Hi,
I want to rotate a ball around another and I do not really understand the system how it is done in jME.
If i rotate from 0 to 180 to 360 it turns counter clockwise.
If I now want to turn further I have to turn to 540 and then to 0 and so on to do multiple turns ???
Why do if have to stay under one periodes length in rotation.
jME does not use degrees, it uses radians. (in case you didn't know yet).
I know that it uses rad but this does not change that you have to use more than one period before it resets.
Maybe I am mistaken but is it not easier to calculate and use with only one period ( one way around the circle) ?
This is no offense it's only a question which cames to my mind because I am starting to use jME.
Which method are you using to do your rotation? Also, I'm not really sure I understand your question… If it goes all the way around by 360 degrees, what odd behavior are you seeing from 360-540… or above?
If i rotate 360 degree i must rotate 180 and then 360 and if I want to rotate in the same direction another 360 I must rotate to 540 and then i can rotate to zero before the period restarts.
Would'nt it be easier to work only within one period and change the direction by the vector you give setRotation?
Again, what are you doing exactly (the code)? Generally I use fromAngleAxis to do rotations. Is this what you are doing? If there is an issue you'd like corrected, a simple test showing the bug is the best way to illustrate it.
Ok here is some code:
//controller for rotation
SpatialTransformer st=new SpatialTransformer(1);
Quaternion rot0=new Quaternion();
Quaternion rot180=new Quaternion();
Quaternion rot360=new Quaternion();
Quaternion rot540=new Quaternion();
rot0.fromAngleAxis(0,new Vector3f(0,1,0));
rot180.fromAngleAxis(FastMath.DEG_TO_RAD180,new Vector3f(0,1,0));
rot360.fromAngleAxis(FastMath.DEG_TO_RAD(360),new Vector3f(0,1,0));
rot540.fromAngleAxis(FastMath.DEG_TO_RAD540,new Vector3f(0,1,0));
Node ns=new Node("Sun Node");
Sphere sun=new Sphere("Sun",20,20,1);
ns.attachChild(sun);
Node pive=new Node("Pivot Earth");
Node ne=new Node("Earth Node");
Sphere earth=new Sphere("Earth",20,20,0.3f);
ne.attachChild(earth);
ne.setLocalTranslation(new Vector3f(10,0,0));
pive.attachChild(ne);
st.setObject(pive,0,-1);
for (int i=0;i<11;i++){
st.setRotation(0,11.2fi+0f,rot0);
st.setRotation(0,11.2fi+2.8f,rot180);
st.setRotation(0,11.2fi+5.6f,rot360);
st.setRotation(0,11.2f*i+8.4f,rot540);
}
st.interpolateMissing();
pive.addController(st);
rootNode.attachChild(pive);
rootNode.attachChild(ns);
the problem is it is not possible to leave out the 180 and 540 for a continous rotation, but shouldn't it be better like this or am I mistaken.
It can also be a missunderstanding from myself but it should be easier to only spin in one direction with a given ancle and change the direction via the vector.
Ah, so SpatialTransformer, glad you finally let that piece of info slip out. ;) Looks like what you are missing is an understanding of repeat types and how interpolation works with Quats. Try this altered code… I think it does what you are looking for.
//controller for rotation
SpatialTransformer st=new SpatialTransformer(1);
Quaternion rot0=new Quaternion();
Quaternion rot180=new Quaternion();
Quaternion rot360=new Quaternion();
rot0.fromAngleAxis(0,new Vector3f(0,1,0));
rot180.fromAngleAxis(FastMath.DEG_TO_RAD*180,new Vector3f(0,1,0));
rot360.fromAngleAxis(FastMath.DEG_TO_RAD*(360),new Vector3f(0,1,0));
// Wrap repeat type tells the transformer to pick back up at the beginning of the loop after passing the end.
st.setRepeatType(Controller.RT_WRAP);
Node ns=new Node("Sun Node");
Sphere sun=new Sphere("Sun",20,20,1);
ns.attachChild(sun);
Node pive=new Node("Pivot Earth");
Node ne=new Node("Earth Node");
Sphere earth=new Sphere("Earth",20,20,0.3f);
ne.attachChild(earth);
ne.setLocalTranslation(new Vector3f(10,0,0));
pive.attachChild(ne);
st.setObject(pive,0,-1);
// we need all three for interpolation to work properly.
st.setRotation(0,0f,rot0);
st.setRotation(0,2.8f,rot180);
st.setRotation(0,5.6f,rot360);
st.interpolateMissing();
pive.addController(st);
rootNode.attachChild(pive);
rootNode.attachChild(ns);
Now i got it, but if I want to make 7 complete rotations and then drop to another behavior.
Do I have to create this many Quaternionsor or is the idea to set the SpatialTransformer to a final state and then pass the new movement to it?
I am new to jME so my questions sometimes sound maybe quite easy or stupid.
regards for so much help
Sue
Yeah, if you want to get SpatialTransformer to do something like that, you'd have to spell it out for it. If I were doing it though, i'd probably write my own controller once I started getting more complex like that.