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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:09:19+00:00 2026-05-23T05:09:19+00:00

I’m just starting to work with Quaternions, but I’m having some annoying difficulties getting

  • 0

I’m just starting to work with Quaternions, but I’m having some annoying difficulties getting a simple FPS camera to work properly using Quaternions.

Basically, whenever I try to move the mouse, a triangle I draw on the screen goes crazy and moves off and on the screen faster than I can see. The movement keys (wsad) are working as expected, UNTIL I move the mouse, and then it gets all messed up. I think the problem is with the rotation, but I’ve been pouring over this issue for the past couple of days to no avail.

Here’s a video of what’s going on: Quaternion Test Video

  • To see mouse input, watch from the beginning.
  • To see keyboard input (go forward, backward, etc) skip to 0:51 seconds.

Just for reference, here are the 3 main classes I’m using:
Quaternion.h
CameraSceneNode.h
CameraSceneNode.cpp

The most relevant sections are tick() (where I update the rotation Quaternion), and render() (where I render the ‘camera’, which consists of rotating and translating the scene).

Here is the tick() method:

void CameraSceneNode::tick(float32 time) {
    // movement direction
    if (movement_[MOVE_DIR_FORWARD] == 1)
        pos_ += rotation_ * vmath::Vector3f(0, 0, -moveSpeed_ * time);

    if (movement_[MOVE_DIR_BACKWARD] == 1)
        pos_ += rotation_ * vmath::Vector3f(0, 0, moveSpeed_ * time);

    if (movement_[MOVE_DIR_LEFT] == 1)
        pos_ += rotation_ * vmath::Vector3f(-moveSpeed_ * time, 0, 0);

    if (movement_[MOVE_DIR_RIGHT] == 1)
        pos_ += rotation_ * vmath::Vector3f(moveSpeed_ * time, 0, 0);

    // rotation
    if (xRot_ != 0) {
        Quaternion quatRotation = Quaternion();
        quatRotation.buildFromAxisAngle(1, 0, 0, (xRot_ * time * rotSpeed_) *         math::DEGTORAD);
        //quatRotation.normalize();
        rotation_ = rotation_ * quatRotation;
        xRot_ = 0;
        rotation_.normalize();
    }
    if (yRot_ != 0) {
        Quaternion quatRotation = Quaternion();
        quatRotation.buildFromAxisAngle(0, 1, 0, (yRot_ * time * rotSpeed_) *         math::DEGTORAD);
        //quatRotation.normalize();
        rotation_ = quatRotation * rotation_;
        yRot_ = 0;
        rotation_.normalize();
    }
}

and here is the render() method:

void CameraSceneNode::render() {
    if (isActive()) {
        float32 matrix[16];
        rotation_.fillMatrix(matrix);

        glMultMatrixf(&matrix[0]);

        //glRotatef(rotYTest, 0, 1, 0);
        //glRotatef(rotXTest, 1, 0, 0);

        glTranslatef(-pos_.x, -pos_.y, -pos_.z);
    }
}

Also, before I call render() on the camera, I run this bit of code:

glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

Both tick(..) and render() are called every frame from my main game loop. There are functions in the CameraSceneNode class that accept changes in movement direction and camera rotation (i.e. that change the movement_ buffer or xRot_ and yRot_) .

I’m sorry if this isn’t enough information. Some of the functions (like fillMatrix(..)) are defined in those 3 .h/.cpp files I referenced above. I’ve checked over the Quaternion class several times, and it looks to me like it’s correct. But then again, all the code I’m using looks correct to me, so who knows :S

I’m totally at my wits end with this. If anyone can shed some light on why this is not working, I would greatly appreciate it!!

Cheers

Jarrett

  • 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-23T05:09:20+00:00Added an answer on May 23, 2026 at 5:09 am

    From the looks of it, you’re progressively accumulating your rotation every tick (rotation_ = quatRotation * rotation_;), which makes sense at first because all you’re doing is adjusting the rotation slightly and so it should be safe to tack on another degree or two of rotation to what’s already there, right?

    However, each time you rotate (by what you’re doing), you’re actually slightly changing the axis of rotation each time, which is why you see this erratic behaviour.

    What I would suggest is to keep track of the overall X/Y rotations, incrementing or decrementing as the mouse moves, and then computing the rotation directly each time instead of accumulating rotations. So if you rotated in X by 1 degree 15 times, your current code essentially says “rotate 1 degree in X, add a rotate 1 degree in X, etc, etc”. What I’m suggesting is to keep track of a single rotation factor X, and as it changes set the rotation directly “rotate 13 degrees, rotate 14 degrees, rotate 15 degrees, etc”.

    From your video it also looks like the rotations are too large, so you may wish to scale the final rotations used by a factor of 10 or 50 (or whatever).

    I could be way off, but I’ve run into similar things in my 3D coding adventures and this is my best suggestion. If that’s not the issue, since you’re dealing with a camera rotation, you may need to use the matrix inverse. Worse comes to worse, look at the modelview matrix for certain rotations and see if it matches what you expect (a pain, but also a valuable debugging exercise).

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.