Allegro.cc Forums » Programming Questions » 3D rotation using Allegro 5.2.4

Credits go to SiegeLord for helping out!
 3D rotation using Allegro 5.2.4
 DontKnow3D Member #16,883 July 2018 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: #SelectExpand 1al_identity_transform(&transform); 2al_rotate_transform_3d(&transform, 1, 0, 0, x); 3al_rotate_transform_3d(&transform, 0, 1, 0, y); 4al_rotate_transform_3d(&transform, 0, 0, 1, z); 5al_translate_transform_3d(&transform, 0, 0, -4000); 6al_use_transform(&transform); whole code: #SelectExpand 1#include 2#include 3#include 4#include 5 6#define W 1000 7#define H 1000 8#define PPHI 100 9#define PTHETA 100 10#define XYZ_MOVE_AMOUNT 0.01 11#define AMOUNT_OF_INDEXES (PPHI*PTHETA * 2-PPHI) 12#define LOOP(var,max) for(var=0;var
 Edgar Reynaldo Major Reynaldo May 2007 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.
 DontKnow3D Member #16,883 July 2018 I don't quite get what you mean. Could you post some example code?
 Edgar Reynaldo Major Reynaldo May 2007 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.
 DontKnow3D Member #16,883 July 2018 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
 SiegeLord Member #7,827 October 2006 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). "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 DontKnow3D Member #16,883 July 2018 yes thank you! I forgot the identity transform...