# Change rotation origin point

hi all i have a spatial and i can apply a rotation on x,y axis.

now i want to translate that spatial of 2 unit on x axis and changing origin rotation point of 2 unit on x axis.How to move rotation origin point?

I donâ€™t get it. According to what you describe, you just have to set the local translation of the spatial, then set itâ€™s local rotation then it will rotate around itâ€™s center of mass. Quaternions describe a relative rotation.

If you want your object to continue to rotate around the origin, you have to apply the rotation to the translation by doing

``` Quaternion quat=â€¦whatever rotation you wantâ€¦; Vector3f translation= new vector3f(2,0,0); spatial.setLocalTranslation(quat.mult(translation)); spatial.setLocalRotation(quat); ```

1 Like

Well simple way, attach it to a node with translatioa nd rotate the node

i read it but i cannot understand how to do that

i want to change the origin.

The rotation origin has to move with spatial

I was going to ask the same question he is asking. Basically, the origin he is speaking of is a point. For example, if you have a 1 X 1 square, there can be 5 different origin points - the four vertices and the middle. This origin point is the point around which an object rotates.

@dilembo, correct me if I am wrong.

dilembo said:
i want to change the origin.
The rotation origin has to move with spatial

that's the default behavior...
what happen if you just translate then rotate the spatial?

@memonick, the center of rotation will be the center in your example if you want to rotate around a corner you'll have to use the math i described above.

@nehon, many thanks I also found another method using 3DS Max. You can align the pivot point to the center or somewhere else to define the pivot point.

the way to do it is to attach it to another node and then offset it relative to that node.

@kidneytrader could u give me more details?

@memonick it is exactly what i mean

@dilembo, is the model made in 3DS Max? We will continue from here

no itâ€™s just a box in the center .Itâ€™s made with jme3

Then I guess you will have to try the code nehon wrote above.

[java]Quaternion quat=â€¦whatever rotation you wantâ€¦;

Vector3f translation= new vector3f(2,0,0);

spatial.setLocalTranslation(quat.mult(translation));

spatial.setLocalRotation(quat);[/java]

or kidneytraderâ€™s way itâ€™s fine too and involve less math, at least on your side.

attach the box to a node, set the local translation of the box, then rotate the node.

For lazy ones:

``````//Get the center of the mesh (no matter the original pivot)
Vector3f center = ((Geometry)model).getMesh().getBound().getCenter();

//Create the node to use as pivot
Node newPivot = new Node();
newPivot.setLocalTranslation(center);
newPivot.attachChild(model);

//Reverse the pivot to match the center of the mesh
model.setLocalTranslation(center.negate());

//Apply the desire angle and axis rotation
Quaternion quat = new Quaternion();
quat.fromAngleAxis(angle, Vector3f.UNIT_Y);

//Enjoy
newPivot.rotate(quat);``````