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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:55:13+00:00 2026-06-01T01:55:13+00:00

I have a 3D camera with its current rotation stored as a quaternion, and

  • 0

I have a 3D camera with its current rotation stored as a quaternion, and I’m having trouble rotating it correctly. I want the camera to rotate incrementally around its local axes based on mouse movement each frame (first-person-shooter-style), but the rotation is wrong. It kind of works, but the camera seems to “roll” around its forward axis when it shouldn’t.

I update the rotation each frame with this function:

void Camera::rotate(const Quat& q)
{
    // m_rot is the current rotation
    m_rot = m_rot * q;
}

Here’s my quaternion multiplication function:

Quat Quat::operator*(const Quat &rhs) const
{
    // quaternion elements in w,x,y,z order
    Vector4d res;

    res[0] = m_q[0]*rhs.m_q[0] - m_q[1]*rhs.m_q[1] -
             m_q[2]*rhs.m_q[2] - m_q[3]*rhs.m_q[3];
    res[1] = m_q[0]*rhs.m_q[1] + m_q[1]*rhs.m_q[0] +
             m_q[2]*rhs.m_q[3] - m_q[3]*rhs.m_q[2];
    res[2] = m_q[0]*rhs.m_q[2] - m_q[1]*rhs.m_q[3] +
             m_q[2]*rhs.m_q[0] + m_q[3]*rhs.m_q[1];
    res[3] = m_q[0]*rhs.m_q[3] + m_q[1]*rhs.m_q[2] -
             m_q[2]*rhs.m_q[1] + m_q[3]*rhs.m_q[0];

    return Quat(res);
}

Am I doing something wrong, or is this some kind of floating-point error thing?

  • 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-06-01T01:55:14+00:00Added an answer on June 1, 2026 at 1:55 am

    Figured out the problem. For a mouse-controled first-person camera like the one I’m going for, I want to rotate around the local x-axis to look up and down, but the global y-axis for looking side to side.

    So this is correct for the x-axis:

    m_rot = m_rot * q;
    

    But I need to do this for the y-axis:

    m_rot = d * m_rot;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have written a Quaternion based 3D Camera oriented toward new programmers so
I have an abstract class called camera which PointCamera uses as its super class.
Assume I have a camera defined by its position and direction, and a box
I have an IP camera and I would like to share its feed. It
In my camera function i have an custom overlayview, its is a square in
I have a camera that returns raw images that can easily be converted to
I have a camera and I am trying to connect to it vis suds.
I have a camera on my network which I am trying to connect to
Task: I have a camera mounted on the end of our assembly line, which
I have an app that uses the iPhone camera and puts an overlay over

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.