Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 970205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:46:06+00:00 2026-05-16T02:46:06+00:00

Im trying to do a simple rotation of a cube about the x and

  • 0

Im trying to do a simple rotation of a cube about the x and y axis:

I want to always rotate the cube over the x axis by an amount x
and rotate the cube over the yaxis by an amount y independent of the x axis rotation

first i naively did :

glRotatef(x,1,0,0);
glRotatef(y,0,1,0);

then

but that first rotates over x then rotates over y
i want to rotate over the y independently of the x access.

I started looking into quaternions, so i tried :

Quaternion Rotation1;
Rotation1.createFromAxisAngle(0,1, 0, globalRotateY);
Rotation1.normalize();

Quaternion Rotation2;
Rotation2.createFromAxisAngle(1,0, 0, globalRotateX);
Rotation2.normalize();

GLfloat Matrix[16];

Quaternion q=Rotation2 * Rotation1;

q.createMatrix(Matrix);
glMultMatrixf(Matrix);

that just does almost exactly what was accomplished doing 2 consecutive glRotates …so i think im missing a step or 2.

is quaternions the way to go or should i be using something different? AND if quaternions are the way to go what steps can i add to make the cube rotate independently of each axis.
i think someone else has the same issue:
Rotating OpenGL scene in 2 axes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:46:07+00:00Added an answer on May 16, 2026 at 2:46 am

    I got this to work correctly using quaternions: Im sure there are other ways, but afeter some reseatch , this worked perfectly for me. I posted a similar version on another forum. http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=280859&#Post280859

    first create the quaternion representation of the angles of change x/y
    then each frame multiply the changing angles quaternions to an accumulating quaternion , then finally convert that quaternion to matrix form to multiply the current matrix. Here is the main code of the loop:

    Quaternion3D Rotation1=Quaternion3DMakeWithAxisAndAngle(Vector3DMake(-1.0f,0,0), DEGREES_TO_RADIANS(globalRotateX));
    Quaternion3DNormalize(&Rotation1);
    
    Quaternion3D Rotation2=Quaternion3DMakeWithAxisAndAngle(Vector3DMake(0.0f,-1.0f,0), DEGREES_TO_RADIANS(globalRotateY));
    Quaternion3DNormalize(&Rotation2);
    
    
    Matrix3D Mat;
    Matrix3DSetIdentity(Mat);
    Quaternion3DMultiply(&QAccum, &Rotation1);
    
    Quaternion3DMultiply(&QAccum, &Rotation2);
    
    Matrix3DSetUsingQuaternion3D(Mat, QAccum);
    globalRotateX=0;
    globalRotateY=0;
    
    glMultMatrixf(Mat);
    

    then draw cube

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do a simple rotation in OpenGL but must be missing the
I am trying to learn some more about vectors and rotation in Java by
i'm trying to develop my first and simple videogame. I'm using SDL.NET (wrapper .NET
I am trying to make a simple image rotator that will rotate through a
I am trying to honor the android rotation lock setting - I want my
I'm trying to do a simple extension of jQuery to allow image rotation via
I'm trying to draw a simple crystal that rotates on its axis. I can
I am learning and trying simple example using node.js and mongoskin. here is my
After trying this simple console input with 5, the result is shown as 53
I am trying a simple Extension Method example and am unable to increment or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.