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 6759757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:59:16+00:00 2026-05-26T13:59:16+00:00

I have an object which I want to rotate via keys. The object should

  • 0

I have an object which I want to rotate via keys. The object should yaw, pitch and roll. After trying a lot, I figured out that glRotate has its limitations and it won’t be possible to implement something like that with that function.

I’ve researched a bit and found out about quaternion-based rotation. It would be also possible to rotate via a rotation matrix, but almost everyone describes the quaternions as the best ever.

I have read about the quaternions and understood them fairly well, but how to implement them in my OpenGL program is still a mystery. Does anyone know a small example? Not how to implement the quaternion class but how to use it. I don’t get how to put the things together.

  • 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-26T13:59:17+00:00Added an answer on May 26, 2026 at 1:59 pm

    The most important is to implement method that will build rotation matrices from quaternion. Then, as you’ll do with normal rotation matrix, just multiply it with your modelview matrix.

    This is simple example that was used to rotate cube with mouse movement. As you see I’ve needed to implement three methods: toMatrix, quaternionFromAxis, multiplyWith. Assuming that you understand quaternions, this should be clear what they do.

    void display() {
    
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glPushMatrix();
    
        // Multiply quaternion with current modelview matrix    
        glMultMatrixf(cameraQuaternion.toMatrix());
    
        // Some other transformations
        glTranslatef(-0.5f, -0.5f, -0.5f);
    
        // Draw something, i.e. cube
        glDrawArrays(GL_TRIANGLES, 0, 36);
        glDrawArrays(GL_TRIANGLES, 0, 36);
    
        glPopMatrix();
    }
    
    void mouseMoved(float dx, float dy) {
        float axisY[] = { 0, 1, 0 },
              axisX[] = { 1, 0, 0 };
    
        float sensitivity = 0.005f;
        Quaternion *q1 = Quaternion.quaternionFromAxis(axisY, dx * sensitivity];
        Quaternion *q2 = Quaternion.quaternionFromAxis(axisX, dy * sensitivity];
    
        // Multiply two quaternions with camera
        cameraQuaternion = (q1.multiplyWith(q2)).multiplyWith(cameraQuaternion);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object which I first want to rotate (about its own center)
I have an object which I want to rotate between -45 and 45 degrees,
I have an object for which I want to generate a unique hash (override
I have this object which is an instance of a superclass. I want to
I have a productVariant object which has child product object. I want to show
Lets say I have a single object of type Car which I want to
I have a page in which I want to maintain the value of object
I have an object, and I want to list all the selectors to which
I have an object x which I want to marshal into a file. xml
I have a object which contains unicode data and I want to use that

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.