0
votes

I want to rotate a 3d object in a roll pitch yaw fashion. I store the pose of the object in a matrix, and perform roll, pitch and yaw rotations multiplying the pose matrix by one of the standard rotation matrices about x, y, or z axis.

Then I display it using these lines of code.

void display()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  gluLookAt(-5, 5, 2, 0, 0, 0, 0, 1, 0);
  glPushMatrix();
    ship.Draw();
  glPopMatrix();
  glutSwapBuffers(); 
}
void Spacecraft::Draw(){
  glMultMatrixf(pose);
  model.Draw();
  return;
}

It works, but the object, instead to rotate around their own axis it rotates around the world axis... Where am I wrong?

1

1 Answers

0
votes

Rotations are always about the origin of the local coordinate system. So you first have to translate the coordinate system so that the center of the desired rotation happens to be at the local coordinate system origin. It's hard to tell where and which transformations to apply without seeing the rest of your code.

The rest of the drawing code, which is not shown, also includes the contents of the model. Draw function. Most likely you've got a translations somewhere in there. This translation moves the object away from the coordinate system center. I think what you're missing (not about OpenGL but linear algebra in general) is, that matrix multiplication is non-commutative, i.e. order of operations matter and that for column major matrices the order of operations is last to first (or right to left if written in normal notation). So the rotation must be the last thing you multiply on the matrix, not the first.