Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

c++ - how to rotate all objects by their own centers and then translate them to the real position (it isn't working)

What is the way to make all the objects that are not aligned with the origin center (vector3(0.0f,0.0f,0.0f)) , rotate about its own central axis?

the problem in pseudo code:

vector3 vector3 objectCenter = (10,5,0); // current object center
vector3 vector3 objectPosition = (40,5,0); // Place to translate the object
vector3 objectRotation; = 45.0f;

    matrix.loadIdentity ();
    matrix.translate (objectCenter);

    //apply transformations
    matrix.rotateX (objectRotation);

    matrix.translate (-objectCenter);

    //it? work correctly until here
    //when i try to translate the object to the real position, the rotation is incorrect.

    matrix.translate (objectPosition);

I use C++, glm (to matrix manage) and OpenGL.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

if you want to rotate object locally to its own coordinate system then do this:

M=inverse(inverse(M)*rotation_matrix);

[edit1] more about relation between M and object which coordinate system it represents

look here: transform matrix anatomy

M origin is usually the middle of object (or point which is center of rotation movements). Axises of M are usually aligned with object for example in airplanes the X axis is usually the fly direction. I am more used to:

  • +z axis as forward direction movement
  • +x as right, -x as left
  • +y as up and -y as down

pith,yaw,roll are then object local rotations around x,y,z


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...