c++ - Rotate an object on its own axes in OpenGL -


Then I have a cube that I use to make any of its three axes (to rotate the axis of the cube). As there are many other similar questions, my rotation works till I am only moving in one direction, but when I start their mix, I get strange results. In particular, rotation about the Y-axis always spins about the y-axis of the window, even if the cube rotates.

My drawing code is as follows:

  glMatrixMode (GL_MODELVIEW); GlLoadIdentity (); GluLookAt (0.0, 5.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); GlPushMatrix (); GlRotatef (theta_y, 0,1,0); GlRotatef (theta_x, 1,0,0); GlRotatef (theta_z, 0,0,1); Draw_cube (); GlPopMatrix ();   

What I'm trying to describe the question, I say a lot about it, and the accepted answer I think is what I want to do, even though that Link provides it is dead.

Whatever I can gather in the connected question, my z-rotation is done first, which means that about my X-rotation (which will be the next) (1, 0, 0) Instead of rotating, I rotate about (-in theta_j), cos (theta_j), 0). But for the third rotation, he only gives the link, saying that it becomes "very complex". Now the link is dead, I'm not sure how to know about this third rotation.

Edit: Based on the answer, I've added three vectors: cube_x , cube_y , and cube_z To capture the existing keys of my cube. They have been started as follows:

  float cube_x [] = {1.0f, 0.0f, 0.0f, 0.0f}; Float cube_y [] = {0.0f, 1.0f, 0.0f, 0.0f}; Name cube_z [] = {0.0f, 0.0f, 1.0f, 0.0f};   

Back in my drawing function, I changed it so that rotation is done around these axes instead of the global axis as I did earlier. After rotating three, I call glGetFloatv to get the current matrix and a new function, update_vector to fill my solid vectors with its new values I use. All this is included below:

  zero update_vector (float vector [], float matrix []) {vector [0] = matrix [0] * vector [0] + matrix [1] * Vector [1] + matrix [2] * vector [2] + matrix [3] * vector [3]; Vector [1] = matrix [4] * vector [0] + matrix [5] * vector [1] + matrix [6] * vector [2] + matrix [7] * vector [3]; Vector [2] = matrix [8] * vector [0] + matrix [9] * vector [1] + matrix [10] * vector [2] + matrix [11] * vector [3]; Vector [3] = matrix [12] * vector [0] + matrix [13] * vector [1] + matrix [14] * vector [2] + matrix [15] * vector [3]; } Zero my_display (zero) {glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GlamatrixSmod (GLIMDLUF); GlLoadIdentity (); GluLookAt (0.0, 5.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); GlPushMatrix (); GlRotatef (theta_y, cube_y [0], cube_y [1], cube_y [2]); GlRotatef (theta_x, cube_x [0], cube_x [1], cube_x [2]); GlRotatef (theta_z, cube_z [0], cube_z [1], cube_z [2]); // Get current matrix flat my_matrix [16]; Glagfloatev (GLIMDLUUUTIMERIRIIX, MIA_matrix); // Multiply the matrix by each of my vectors update_vector (cube_x, my_matrix); Update_vector (cube_y, my_matrix); Update_vector (cube_z, my_matrix); Make_cube (); GlPopMatrix (); / * Buffer is ready * / glutSwapBuffers (); Return; }   

Now when I try to rotate about the y axis, the cube flips around with some axes before finally walking about the X-axis. The only thing revolving about Z is to work around the X-X only.

Edit: Solution:

In his comment below, Gavin had mentioned that Y-axis rotation is always happening first, this is the whole issue By setting the flag rot> and on which axis I am trying to rotate around, I am able to order rotation so that eventually the axis can be rotated. .

After your look, you have to translate the negative position of the cube, rotation, then cube key Translate back to the status.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -