# Rotate // setlocalrotate & transition // ssetlocaltransition is so confusing to me

i can`t understand difference between rotate and setlocalrotate exactly.....<br /> i read https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies...<br /> but i`m so confused. Let me know please…

its like move() and setLocalTranslation() if that helps. rotate() rotates it from its current position, and setLocalRotation() is relative to its parent

Yeah, rotate() is cumulative, setLocalRotation() isn’t. If you know how “setters” works in java, you’ll know their differences.

@wezrule, glaucomardano

Thank you for your help ^^

Then rotate() and setLocalRotation() have just difference in cumulative or not.

But i can understand this.

@wezrule said:
and setLocalRotation() is relative to its parent.

This means, Spatial (is named 'A') rotate on a axis of parent? not a axis of 'A'? right?
In my source code, i can find any difference except cumulativeness.
[java]
public class Hello_Test extends SimpleApplication {
float mtpf = 0.0f;
Node object;
Spatial Parent;
Spatial Cone;
Spatial Cube;
Quaternion backup;
Vector3f Axis = new Vector3f(0, 1, 0);
int i;
public void simpleUpdate(float tpf) {
mtpf += tpf;
if(mtpf > 0.5){
mtpf = 0; ++i;
backup.fromAngleAxis(0.1f*i, Axis);
Cube.setLocalRotation(backup);
Cone.setLocalRotation(backup);
//Cone.rotate(0, 0, 0.3f);
}
}
@Override
public void simpleInitApp() {
backup = new Quaternion();

Parent = (Spatial)object.getChild("Cube");
Cone = (Spatial)object.getChild("Cone");
Cube = (Spatial)object.getChild("Cube.001");
rootNode.attachChild(object);

DirectionalLight sun = new DirectionalLight();
................
}
}
[/java]

public void simpleUpdate(float tpf) {
mtpf += tpf;
if(mtpf > 0.5){
mtpf = 0; ++i;
backup.fromAngleAxis(0.1f*i, Axis);
Cube.setLocalRotation(backup);
Cone.setLocalRotation(backup);
//Cone.rotate(0, 0, 0.3f);
}
}

As you can see, the lines 6 and 7 does the same thing each loop, it simply "set" the location variable "relative" to its parent. If you wanna rotate your model a bit each loop, use the "rotate" method.

@qlaucomardano

Thanks~^^

Hello,

In terms of rotation things are quite clear,rotate() rotates a spatial wrt its own geometrical axis, while setLocalRotation() rotates the spatial wrt its parent node which means its coordinate position also undergoes a change wrt parent node which is not the case with rotate().

But if we come to translation , then some confusion creeps in because I think while you can rotate an oject about its axis but moving an object wrt its own geometrical origin makes no sense.So I really don’t understand the diff between move ans setLocalTranslation() which makes object move wrt parent node.

Manish

You have all of that wrong, I think.

The difference between setLocalRotation and rotate is the if you rotate() 15 degrees four times then you will be rotated 60 degrees. If you setLocalRotation() to 15 degrees four times then you swill be rotated 15 degrees. rotate() is relative to current rotation. setLocalRotation() is absolute…

…but it is all relative to the parent.

Basically, rotate( foo ) is just combining getLocalRotation() with the passed in foo.

move() is the same.

move( 5, 0, 0 ) five times is the same as setLocalTranslation( 25, 0, 0 )… presuming you started at 0,0,0.

And it is ALL relative to the parent’s coordinate system.

hello pspeed,

I made a box, attached it to a node which is at (0,0,0).

Now I call move on box which moved it to (3,0,0).

Now if I call rotate on box with args as (0,0,FastMath.HALF_PI/4) then box gets tilt at 45 degree, its coordinate position remanining same wrt parent node.

But as you said that rotate() also is wrt parent, then shouldn’t box move to new coordinate position.

Following is my code:

Node parent = new Node();//parent node at 0,0,0

Box blue = new Box(Vector3f.ZERO, 1, 1, 1);

player_blue = new Geometry(“blue cube”, blue);

Material mat = new Material(assetManager,

mat.setColor(“Color”, ColorRGBA.Blue);

player_blue.setMaterial(mat);

parent.attachChild(player_blue);

Box green = new Box(Vector3f.ZERO, .1f, .1f, .1f);//a small green box just to track parent node position

player_green = new Geometry(“green cube”, green);

Material mat_green = new Material(assetManager,

mat_green.setColor(“Color”, ColorRGBA.Green);

player_green.setMaterial(mat_green);

parent.attachChild(player_green);

rootNode.attachChild(parent);

player_blue.move(3,0,0);

player_blue.rotate(0,0,FastMath.HALF_PI/4);

No. It rotates the children of Box (the vertexes) but relative to parent’s rotation. So if parent was rotated 45 degrees and you rotate the child then the child’s cumulative rotation will be 90 degrees.

Read the scene graph for dummies link until your eyes bleed or you reach nirvana. Which ever comes first.

Translation moves the coordinate system. Rotation rotates it relative to its own local origin. But that’s all relative to the parent’s coordinate system (which similarly includes translation and rotation).

OK…I got it now.

It brings me to another question.

As rotation rotates a spatial relative to its own local origin, how can I rotate it relative to parent’s origin.

Suppose preant is at (0,0,0), spatial is at (3,0,0) and I want spatial to rotate wrt parent…just like moving on a circle with radius 3 and centre at (0,0,0).

Manish

You can calculate the position yourself pretty easily with a Quaternion.

But I still ask why you want to do such a thing? Why is it not preferable to stick another 0,0,0 located parent node there to rotate?

I can’t get you on ‘Why is it not preferable to stick another 0,0,0 located parent node there to rotate’?

Parent node is there on origin.So if I call rotate on my spatial it would rotate relative to its local origin, isn’t it?So how would it serve my purpose of moving it on a circular path wrt parent.

Or is it that u want me to rotate parent node so that child also gets rotated?If that is the case, then may be parent has other child too and I want to move only a particualar child.

Am I still missing something crucial here?And if yes then may be I need a break.

Manish

.So if I call rotate on my spatial it would rotate relative to its local origin, isn’t it?

yes.

So how would it serve my purpose of moving it on a circular path wrt parent.

attach it to a node, distance it from center, and rotate the node.

Or is it that u want me to rotate parent node so that child also gets rotated?

yes.

If that is the case, then may be parent has other child too and I want to move only a particualar child.

Attach a sub-parent :P.

Yeah, I was talking about attaching a sub-parent. Generally, there is some concept of something that can logically be represented in a scene graph.

For example, if you are trying to represent planets orbiting around a sun (not properly simulated but through scene graph rotation) then you have the sun and you have a planet… and you have the planet’s orbit.

Sun

->Earth Orbit

->Earth

Rotate earth to make a day, rotate “Earth Orbit” to make a year.

ok…thanks a ton.