Hi guys,
Rotations on JMonkey are really giving me a headache.
I’m modeling a fiber optic and the behaviour of light in a fiber optic. It seemed like an easy task but it’s proving harder then I originally thought possible.
The blue cylinder is the fiber optic. The grey object is the direction of the light and the white line is the actual light.
The first thing I find very odd is that the rotation angle of the grey object is a positive number. As far as I know angles go counterclockwise which would make it a negative number. Why is that?
I am using the rotate method to rotate the object but I would prefer to use absolute rotation. How can I do that?
Lets say that I have a vector3f that stores a spatials x,yz rotation. How can I apply it to the spatial?
Thanks
AtomR
I had a very bad headache with rotations as well, Quaternions were tought to understand. I think u maybe wanna use degrees for calc the next light angle, so i hope this helps you:
[java]public static void turnTo(Node n, float angle, Vector3f witchAxis) { // (0,1,0) will rotate Y axis
Quaternion quat = new Quaternion();
quat.fromAngleAxis((FastMath.PI * angle / 180),witchAxis);
n.setLocalRotation(quat);
}
public static float getNodeAngle(Node n) {
float headAngle = (float) Math.toDegrees(n.getLocalRotation().toAngles(null)[0]); // 0 = x, 1=y, 2 = Z
if (headAngle < 0) {
headAngle += 360;
}
headAngle = 360 - headAngle;
return headAngle;
}
[/java]
Then u can make the node turns to the right angle i guess
I think you want to use direction vectors instead of rotation, rotations will give you much more headaches. Really, check the tutorial I linked.
So I can create a Quaternion from an array of the angles I need. And then setting the spatial Local Rotation it will substitute the old local rotation with a this new one.
That is very helpfull. Thank you.
I actually have the lines behaving exactly like I wanted using the rotate command. The problem I was having was actually more related with the Math.Ray and Bullet Collisions affecting the behaviour of the line then with my rotation math.
But I don’t understand why the angles range from 0 to -180 in the first and second quadrants, and 0 to 180 in the 3rd 4th quadrants. Makes no sence to me.
You may have your quadrants backwards, I guess.
In the x,z plane, if you are standing upright looking into the screen then x+ is left and z+ is towards you. So a positive angle around the Y axis is counter clockwise when looking down from above… but it’s still in the first and second quadrants.
-.- … just use direction vectors, trust me.
he knows loads more then me, ill be tryng to use direction vectors as well = ~~
i’m in a hurry to get this project finished (its for school) so I’ll stick with the rotations as I seem to have gotten a handle on them But will look into direction vectors more closelly for my future (much more interesting) game dev projects
Thank you all for your help.
:brainsout: