c++ - how to rotate all objects by their own centers and then translate them to the real position (it isn't working) -
what way make objects not aligned origin center (vector3(0.0f,0.0f,0.0f)) , rotate own central axis?
the problem in pseudo code:
vector3 vector3 objectcenter = (10,5,0); // current object center vector3 vector3 objectposition = (40,5,0); // place translate object vector3 objectrotation; = 45.0f; matrix.loadidentity (); matrix.translate (objectcenter); //apply transformations matrix.rotatex (objectrotation); matrix.translate (-objectcenter); //itÅ› work correctly until here //when try translate object real position, rotation incorrect. matrix.translate (objectposition);
i use c++, glm (to matrix manage) , opengl.
if want rotate object locally own coordinate system this:
m=inverse(inverse(m)*rotation_matrix);
- m object transform matrix
- rotation_matrix rotation (glrotate())
- inverse function computes inverse matrix
- you can use mine inverse matrix computation
- or rotation around lcs x (lrotx) implementation in c++ (at bottom of answer)
[edit1] more relation between m , object coordinate system represents
- look here: transform matrix anatomy
- m origin middle of object (or point center of rotation movements)
- axises of m aligned object
- for example in airplanes x axis fly direction
- i more used +z axis forward direction movement
- +x right, -x left
- +y , -y down
- pith,yaw,roll object local rotations around x,y,z
Comments
Post a Comment