Multiply this matrix by the matrix with the supplied elements and store the result in dest. Transformation of the right matrix will be applied first! Parameters: r00 - the m00 element of the right matrix r01 - the m01 element of the right matrix r02 - the m02 element of the right matrix r03 - the m03 element of the right matrix r10 - the m10 element of the right matrix r11 - the m11 element of the right matrix r12 - the m12 element of the right matrix r13 - the m13 element of the right matrix r20 - the m20 element of the right matrix r21 - the m21 element of the right matrix r22 - the m22 element of the right matrix r23 - the m23 element of the right matrix r30 - the m30 element of the right matrix r31 - the m31 element of the right matrix r32 - the m32 element of the right matrix r33 - the m33 element of the right matrix Returns: this So when transforming a vector v with the new matrix by using M * R * v, the If M is this matrix and R the right matrix whoseĮlements are supplied via the parameters, then the new matrix will be M * R.
GluPerspective(60.0,(GLfloat) w/(GLfloat) h, 1.0, 20.Multiply this matrix by the matrix with the supplied elements. GlViewport (0, 0, (GLsizei) w, (GLsizei) h) GlClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) nexusone, you need to swap these two lines. I put together a simple program, for an example: You are correct I did need to swap the two lines. There is an example just like this in the red book Chapter 3, “Building a Solar System” Rotate for the moon’s revolution around the earth Nexusone - You are definitely confused about how translate and rotate work together in OpenGL. Allow only one angle (typically yaw) to go up to (and beyond) +/- 90 degrees.Use a rotation matrix or quaternions to keep track of orientation.You are now looking to the left of your original direction with your head straight (as if p=0,y=90,r=0), but according to your Euler angles (p=0, y=0, r=90), you should be looking in your original direction with your head tilted over to the right. You are still looking straight up but now you have turned to the left. Here is a example of the problem of gimble lock: Jrbcast - His problem is not necessarily gimbal lock and the source of gimbal lock is not because “OpenGL modifies the coordinate system”. Maybe then it will work the way you expect.Īlso, a common mistake is that the angle parameter in glRotate is degrees, not radians.Ĭoconut - there is no reason to call glTranslate( -x,-y,-z) after rotating if he wants to rotate the model around its local origin.
Try doing your rotation in the order yaw-pitch-roll (Y-X-Z) instead of pitch-yaw-roll (X-Y-Z).
So, after the first glRotate, the coordinate system is rotated and the next glRotate will rotate around the new axes. Remember that in OpenGL, transformations are done “locally” and are cumulative.
First of all, the first three replies all have errors.