0
votes

I have created 2 circles, where one rotates around the other, like the moon rotating around the sun.

I translated down the z axis then applied a rotation around the y axis for the object to orbit. I need to work out the matrix multiplications of yRotation * ZTranslation * (0,0,0,1)

i.e.

(cos(angle)   0  sin(angle)  0  ) ( 1  0  0   0   ) ( 0 )
(    0        1      0       0  ) ( 0  1  0   0   ) ( 0 )
(-sin(angle)  0  cos(angle)  0  ) ( 0  0  1 zTran ) ( 0 ) 
(    0        0      0       1  ) ( 0  0  0   1   ) ( 1 )

How can I do this?

1

1 Answers

0
votes

Since you are talking about circles, I am assuming you are making a 2D application.

In OpenGL, you have the following coordinates:

   Y
   |
   |
   |
   O---- X
  /
 /
Z

This means that your 2D application is in X-Y space, with Z being perpendecular to the monitor (and towards the outside).

So, if you have a circle going around the other, you probably meant to first translate the circle in the X-Y plane (for example on the Y axis), and then apply a rotation on the Z axis.

So your matrix multiplication should be:

(cos(angle)   sin(angle)  0  0 ) ( 1  0  0   0   ) ( circle_center_x )
(-sin(angle)  cos(angle)  0  0 ) ( 0  1  0 yTran ) ( circle_center_y ) 
(    0            0       1  0 ) ( 0  0  1   0   ) (        0        )
(    0            0       0  1 ) ( 0  0  0   1   ) (        1        )

Or just in 2D:

(cos(angle)   sin(angle) 0 ) ( 1  0   0   ) ( circle_center_x )
(-sin(angle)  cos(angle) 0 ) ( 0  1 yTran ) ( circle_center_y ) 
(    0            0      1 ) ( 0  0   1   ) (        1        )

Using OpenGL functions:

glRotatef(angle, 0, 0, 1);
glTranslatef(0, yTran, 0);
glBegin(GL_LINE_LOOP);
for (...)
    /* points of circle around circle_center_x/y */
glEnd();

Note that in OpenGL, the matrices are multiplied on the right. So if you write glRotatef before glTranslatef, the rotation will be applied after the translation.