Center rotation

I have a rotation problem. This is using the jME3 nightly build.



I need to rotate a box around it’s center. I first center it, rotate it, then put it back to its original place. In theory, it should work, but it does not here.

All it does is orbit around the center.

[java]

Box b = new Box(min,new Vector3f(x,y,z));

blockBox = new Geometry(“blockBox”,b);

Vector3f oldTranslation = blockBox.getLocalTranslation();

blockBox.center();

blockBox.rotate(0, rotation, 0);

blockBox.setLocalTranslation(oldTranslation);

rootNode.attachChild(blockBox);

[/java]

Use a quaternion and don’t use the rotate method for this use the setLocalRotation();



blackBox.setLocalRotation(new Quaternion.fromAngles(0,rotation,0);



then wherever the box is it will rotate around it’s center.

rotation must be in radians.

I have done the following:



Box b = new Box(min,new Vector3f(x,y,z));

blockBox = new Geometry(“blockBox”,b);

Quaternion quat = new Quaternion();

quat.fromAngles(0,blockRotation,0);

blockBox.setLocalRotation(quat);

rootNode.attachChild(blockBox);



My problem persists and the box still orbits around (0,0,0).

And min and x,y,z are not zero centered? If so, you cannot get there from here. :slight_smile:



Rotation of the geometry will always be about the local origin of the geometry. You could center the box and move the geometry as one solution.

Yeah, I was a bit boggled by this thread. But, I usually make boxes using extents, so I guess the center is defined as the center in that case. I’m guessing using the corner constructor of Box places the center at one of the points? I dunno. But, I do know that if you make a node, and put it at the center of your box (or wherever), attach the box to this new node, and attach the node to the rootNode you should be good. Just make sure to rotate the newly created node you attached the box to. Anything you attach to a node will rotate about the node if the rotation is applied to the node itself.



Weeee

~FlaH

Thank you very much, that worked perfectly!