I don't quite get how the 3D rotation transformations work. In my program I first rotate an object and then move it.(you can rotate it by the arrow keys and space and m.) I would think that the object would just rotate where it is but no; in a full rotation it first is where it should be, then it rotates in a circle to 0,0,0 and then it rotates back to where it should be. Why doesn't it just rotate where the object is? Why does it move to a different place when rotated?
translation code:
whole code:
That's not how you use al_rotate_transform_3d. Or at least, I don't think you're doing it right. In your case, x,y, and z would be the angle you rotate around the axis. What you do is rotate around a single axis. That will make it spin. If you rotate around two axes, you can get roll, yaw, and pitch. But you need to rotate around the forward, up, and right vectors to do that.
I don't quite get what you mean. Could you post some example code?
XYZ defines the vector (axis) you wish to rotate around. Theta is by how much.
If you rotate around the z (forward) vector, you get roll.
If you rotate around the x (right) vector, you get pitch.
If you rotate around the y (up) vector, you get yaw.
I thought that that is exactly what im doing. First I rotate by x amount around axis x, then by y amount around axis y etc. and at the end I move it a bit back
You're missing an al_identity_transform before you construct your perspective transformation (thanks for providing the code, it took me a few minutes to figure out what was going on).
yes thank you! I forgot the identity transform...
The thing you have to realize is that you're applying yaw, roll, and pitch improperly.
Time for a quick tut.
Take your left hand and open it and spread out your fingers. Now close the pinky and ring fingers into your palm while keeping your other fingers in place as best you can. Now form the 3 remaining fingers into the shape of a 3D corner. Now point your middle finger directly towards you. They now form the basis of a Left Handed Coordinate system. Your middle finger points towards positive z, towards the screen, or you. Your pointer finger points towards the positive x axis, and your thumb points towards positive y axis.
Now try to rotate your hand around one of your open fingers. You can't do it without affecting the other two axes. This means if you want to apply yaw, pitch, and roll, then you need to modify the other two vectors when you rotate around an axis. So anytime you rotate around one of the three axis vectors (forward, right, up), you change the other two.
This means you need to account for that in your code, if you truly want local roll, pitch, and yaw.
This is mostly psuedocode. Initialization of fw,rt,and up are up to you. They should be normalized to length 1, and they can simply be your xyz axes.