the center of geometry with bounding sphere

Hi, basically in my pool game i’m using the geometry from a ASE file that someone else made, with the pool balls i need to get the center of the ball to set the center of mass 4 my physics calculations so what i do is i get the bounds of the ball, cast to a bounding sphere and get the center from there but in my game loop when i set the translation transform to that center when it isn’t moving, its gets moved to the incorrect place here is snippet of what i’m doing:



//Some where being initialized
TransformGroup tg = (TransformGroup)namedNodes.get("poolball1")

Shape3D visualBall = (Shape3D)b.getChild(0);

bounds =      visualBall.getBounds();

Vector3 centerOfGravity = new Vector3f(((BoundingSphere)bounds).getCenter());

///////////////////////////////////////////////////////////

//some where later on in the game loop

Transform3D trans = tg.getTransform();
trans.setTranslation(centerOfGravity);

tg.setTransform(trans);


one ball is placed correctly but the rest stay in the wrong position, i guess ill have to do it the hard way and get the geometry and calculate the center myself?

Some one please help me, i printed out the bounds and the position of the center is correct when i checked the coordinates in 3DS Max, if the balls are not moving i wont them to stay in the position so should i not call translate even thou the coordinates doesn’t change?

Hi,

Bounding sphere defines shape bounds in local coordinate system (i.e. the same coordinate system where shape vertices are defined).

If you want to determine center of bounding shpere in Vworld coordinates, you can use Node.getVworldBounds() (you can use this even for groups).

If you want to do something different, you have to check the structure of your scenegraph and apply appropriate transforms either to local bounds, or to vworld bounds (your choice).

Yuri

if u move the view- i take it the shape/model location of the getVworldBounds says the same, and the models location only changes when the model itself is moved?

if this is the case how can i get the center of the model/shape in space when the view is moving? i want to do this so i can make an fmod sound object. at the moment xith3d has sound mediahandlers and soundbuffers- fmod handles all that anyway so i dont need any of that i think. just an fmod type pointsound for fmod- i was going to make it a tookit extra.

also the fmod 3d action can take streams :slight_smile: and thats what i want to use. xith at present just uses samples. and my fmod has loads more effects the openal (no need for hardware for them also).

[quote]if u move the view- i take it the shape/model location of the getVworldBounds says the same, and the models location only changes when the model itself is moved?
[/quote]
Yes.

[quote]if this is the case how can i get the center of the model/shape in space when the view is moving?
[/quote]
So, you need coordinates in Camera (View) coordinate space, not VWorld. You can apply inverse View transform to VWorld coords to get View coords. Use getTransposeTransform() to get inverse View transform, because of exactly this one is used to set up transform during rendering.

Yuri

[quote]Hi,

Bounding sphere defines shape bounds in local coordinate system (i.e. the same coordinate system where shape vertices are defined).

If you want to determine center of bounding shpere in Vworld coordinates, you can use Node.getVworldBounds() (you can use this even for groups).

If you want to do something different, you have to check the structure of your scenegraph and apply appropriate transforms either to local bounds, or to vworld bounds (your choice).

Yuri
[/quote]
Thanks for replying, still wondering about something, once i get the center position from the bounds, when the geometry is suppose to move after the position is updated, where do i apply the translation? after i’ve loaded the data from the ase file, i attach a named node to a BranchGroup and then attach the BranchGroup to a TransformGroup so i can move it around, when i update this TransformGroup to the center position that i obtained from the bounds its not correct, when i print out the value of the Matrix contained in that TransformGroup before applying the transformation, its at identity, so i guess must be the local coordinate system, where should i apply the translation at the most top node?

I printed out the all the transforms (including LocalToWorld) and there all set to identity matrix when i load the objects from an ase file using “getNamedNodesMap()” i can’t seem to find the matrix that has the origional translation of the objects done 3D Studio max, am i missing something here?