How to pirorette objects around their own center?

Could someone please explain what I'm doing wrong here? When I use this on one of my 3D avators (a node), I expect the avatar to pirorette in place, turning around its own axis. What I'm seeing is that it rotates around the world axis, like its riding on the edge of a huge carosel.



I'm confused about world/local axes in general, especially how these relate to coordinates hard-coded in the trimesh vertices. In particular, getLocalTranslation seems to be 0,0,0 nomatter where objects are in the scene because their real position is coded in their trimesh somewhere.



Is there an easy way to modify the trimesh coordinates so they're centered on the bounding box center? Or am I just thinking about this the wrong way? 



        void rotateController()

{

  SpatialTransformer transformer=new SpatialTransformer(1);

  transformer.setObject(node, 0, -1);

Vector3f position = node.getLocalTranslation();

Vector3f origin = new Vector3f(0, 0, 0);



  Quaternion x0=new Quaternion();

  x0.fromAngleAxis(0, axis);

  transformer.setPosition(0, 0, origin);

  transformer.setRotation(0, 0, x0);

  transformer.setPosition(0, 0, position);



  Quaternion x180=new Quaternion();

  x180.fromAngleAxis(FastMath.DEG_TO_RAD180, axis);

  transformer.setPosition(0, 2, origin);

  transformer.setRotation(0, 2, x180);

  transformer.setPosition(0, 2, position);



  Quaternion x360=new Quaternion();

  x360.fromAngleAxis(FastMath.DEG_TO_RAD
360, axis);

  transformer.setPosition(0, 4, origin);

  transformer.setRotation(0, 4,x360);

  transformer.setPosition(0, 4, position);



  transformer.setRepeatType(SpatialTransformer.RT_WRAP);

  transformer.interpolateMissing();

  node.addController(transformer);

}

ok, here's what i meant:

i load a model as node A and then use setLocalTranslation()

then i attach A to a node B.

when i now rotate node B the described effect occurs, the model rotates around the center of B, which is 0,0,0 if it wasn't moved.



if i however use setLocalTranslation() on node B instead of A, or rotate A instead of B, the model turns around it's own axis.



i hope, i didn't get anything wrong here…

That's probably the problem then.  So could someone please respond to this part of my original question then?



Is there an easy way to modify the trimesh coordinates so they're centered on the bounding box center (by which I meant 0,0,0 worldCoord).


Not an answer to your question really, but remember you can always attach your model to a Node, and make sure that it's centre is under the Node. Then you can rotate the Node instead.



Eg. if you have an object with coordinates between 10 and 20 on the x axis, you give it a local translation of 15 for x, then you attach it to a Node.

My models are nodes. Nodes are what I'm trying to rotate. And failing, probably because the trimeshes are in world coordinates, not local.



I've tried shifting the world axis under each model in sketchup before exporting them. The resulting .obj files are bit-identical.



Sooo… how would I shift trimesh coordinates in jme to move hardcoded trimesh coordinates into the localTranslation? Surely someone here has done that. In Java? In Blender? In Sketchup? Heck in vim for that matter. Surely this can't be that hard.

So? That's why I said model, not TriMesh. You can attach a Node to a Node just like you can attach a TriMesh to a Node.



You can "try" the right coordinates, or you could look at the bounding box, to find the local translation the model-Node should have.

Yes, you can do this and it's not all that hard really.  What you do is translate the batch verts by the inverse of the vector going from world origin to the bounding volume's center. 



Or to use an example with simpler words, say you have a model whose bounding volume has a center at (-2, 0, 0).  To center that model and the bounding volume on the world origin, what you want to do is shift all of the verts in the model 2 units to the positive x…  so (2, 0, 0)  GeomBatch, the parent class of all batch types, has a nice translatePoints method you can use to do this.  So you right a simple recursive method that starts at the top of your model and looks for Trimeshes, then goes through each batch and translates it.



There's also the methods rotatePoints and rotateNormals in GeomBatch which are handy for converting models from one world up system to another.

it might be possible, that the center of your model is set to a wrong location in your modeling tool. or do you load the model, move it and then attach it to a node? that could also cause the described behaviour.

I'm displaying the boundiing boxes so I'm sure they're set right. All objects are exported as .obj from Sketchup, which assigns all vertices relative to the same world origin. I setLocalTranslation only for replicas, shifting them a few pixels so they don't all overlap.



Pls explain what you mean by "that" could cause the described behavior. I really don't see how it would.

the bounding box is based on your models vertices so it will not tell you anything about where the objects real center is. if your vertices positions are not centered around 0,0,0 the model will carousel…or, as jackoff says, your loaded node has some kind of offset, but that sounds implausible…


  • does your model display itself at 0,0,0 before translating or rotating it?
  • have you tried loading a jme model that we know works?
  • have you checked that the model is centered around the origin before exporting them?