Continuous rotation around Y-axis with user input conditioned Z-axis rotation

hi!



I am trying to rotate an imported model object around it’s own Y axis as well as around it’s own Z axis. The Y rotation is just for a cool continuous rotating motion, while the rotation around the Z axis is for the direction of the “spaceship”. However what i end up getting is a cumulative rotation around Y and Z simultaneously .This is essentially a birds-eye-view game with 3D objects. The player moves around the X-Y plane while the Z remains 0 for all objects.



What i really want is to rotate the object around it’s Y axis, and THEN rotate it around the Z axis. I think this used to do this with OpenGL simply by first rotating the object around Y axis and then around Z axis and then drawing it. Now i am trying to do it with object.rotate(x, y, z) but it starts spinning around the X axis as well as the Y and Z. I guess i understand that rotate(x,y,z) will spin the object in all directions - but how do you spin it one by one? I was looking into updateGeometry() thing, not sure if that’s it or…

So this seems to be quite peculiar. I guess when you first do a “.rotate” on an object, you end up rotating it’s local coordinates as well. Meaning that while i am doing my cool looking Y-axis rotation around itself, the coordinate space is rotating as well, so the rotation against the Z are now not what i am expecting.





http://stackoverflow.com/questions/7724840/is-it-possible-to-rotate-an-object-around-its-own-axis-and-not-around-the-base-c similar problem…



“Then, once finding out the location of the camera, you could either do the math and get the correct parameters to call glRotatef and glTranslatef or, use gluLookAt.”



Some options i am thinking of: either rotate the object around itself (first axis rotation easy, second axis rotation super difficult since now the coordinate system is rotated) or you rotate the object around the Y axis and then you rotate the camera itself (OpenGL gluLookAt). In jMonkey i tried going up one parent and rotating that but that rotates the whole world. I am gonna look into pivot points next.



Quaternion yaw90 = new Quaternion();

Quaternion roll90 = new Quaternion();

Quaternion pitch90 = new Quaternion();

yaw90.fromAngles(1, 0, 0);

roll90.fromAngles(0, 1, 0);

pitch90.fromAngles(0, 0, 1);

mymodel.rotate(yaw90, roll90, pitch90);





Have a try ;). Also, read these:



https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

@glaucomardano said:

yaw90.fromAngles(1, 0, 0);
roll90.fromAngles(0, 1, 0);
pitch90.fromAngles(0, 0, 1);



Ops :roll:

[java]
yaw90.fromAngles(FastMath.HALF_PI , 0, 0);
roll90.fromAngles(0, FastMath.HALF_PI, 0);
pitch90.fromAngles(0, 0, FastMath.HALF_PI);
[/java]

Maybe this helps?

http://hub.jmonkeyengine.org/groups/graphics/forum/topic/trackball-samples/

@glaucomardano said:
Ops :roll:

[java]
yaw90.fromAngles(FastMath.HALF_PI , 0, 0);
roll90.fromAngles(0, FastMath.HALF_PI, 0);
pitch90.fromAngles(0, 0, FastMath.HALF_PI);
[/java]


hi glaucomardano!

Thanks for your help - however i have tried the above which will rotate the object around all axis at the same time. So lets say you have a "stick looking model" pointing up and down. What i want is to have it continually rotate around the Y axis(it's own) while at the same time rotate around the Z axis (hopefully it's own, but i think i'll need to pivot around a new point). This would give you the effect of looking at the stick that's rotating like a clock hand (only extended through both halves of the clock) while the hand itself was rotating just for cool-effect. In other words a diameter of a circle that's rotating on the flat x-y plane, plus the diameter also rotating around it's own Y axis. So it's always visually for the user rotating around the Z axis, but as it also spins - however to the user it's always flat in front of him. the .rotate(x, y, z) or .rotate(0,0,z) rotate(0,1,0) etc logic seems to rotate it cumulatively but non the less the way it should, but not what i need.

If you want it to behave like a trackball or these balls that are lifted by water and turn, look again at that link…

@normen said:
Maybe this helps?
http://hub.jmonkeyengine.org/groups/graphics/forum/topic/trackball-samples/


I think this is it. To be honest i was hoping it was simpler than this, but looking back to openGL i think this is exactly how you would do it there as well. I guess it boils down to two paths one could take?

1. Do bad-ass math matrix calculations to take into calculation that after you have rotated the object once, it's coordinate system is rotated as well and you need to "pretend(do crazy math)" to be able to say that Z is still where it was and then rotate it against Z and get what you wanted.
2. Use a pivot point + the lookAt (rotate the camera for the second rotation instead of the object (which is the first method and it's too complex))

Thanks guys!

The problem is that rotation doesn’t work like you imagine it: http://en.wikipedia.org/wiki/Gimbal_lock Using direction vectors is much easier and more straightforward the way we think about rotation.

Thanks normen - i’ll be honest here, that Gimbal lock is totally confusing to me (the name on it’s own is confusing). I look at that gif and i’m like…it’s spinning too fast :slight_smile: anyways i’m sure i’d understand it better if i knew what Gimbal was and what the purpose of it was, however at this point i’m just too distracted by other stuff to focus on it. I should take some time and study it further because it could mean that i am not understanding the basics of rotation.



In any case i was able to solve my problem by attaching the spatial to a pivot node, and then i rotate the spatial for Y axis rotation and i rotate the pivot node for Z rotation.



Thanks for the help guys - hope this helps some other dude as well.



Vedran