Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!