Public Group

# 3D Rotations

This topic is 4290 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am working on a small 3D app. I am using OpenGL and C++. I am trying to rotate a block. I would like it to spin in a diagonal direction. I know that I want it to rotate .2 of a degree around its local coordinates x-axis and .2 of a degree around its local coordinates y-axis between every frame. I am trying something like the following:
/* .. some code .. */

// this is called between frames
void Cube::update(){
// for now update this cubes rotation
rotX += .2;
rotZ += .2;
}

/* .. more code .. */

void Cube::draw( Fl_Gl_Window *gl ){
// preform the needed rotate
glRotated( rotX, 1, 0, 0 );
glRotated( rotY, 0, 1, 0 );

/* .. code here to draw the cube as a group of quads .. */
}


When I preform the above code the cube seems to rotate in the correct direction and then change directions. I understand why this is, when I do the xRotation I am moving where the y-axis points and thus rotating around it will not give the desired result. I am curious if there is a way to compute one matrix to preform the rotation? If there is could somone please enlighten me, I am really drawing a blank on this one. Thanks in advance :) -sevans :EOF

##### Share on other sites
I don't really have the matrix perspective on this, but if you want to see some manual rotations here's my SDL code for a rotating toroid:

Donuts, the tastiest of nuts.

Read the text help file for controls, and there's code in QB if you want (though I don't know why you would)

Not that this is particularly helpful if you want to use opengl to do so (which is advisable)

[Edited by - M2tM on October 20, 2006 2:54:46 AM]

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002086
×