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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:57:27+00:00 2026-05-29T05:57:27+00:00

My camera rotates around a point when I try to change the orientation. If

  • 0

My camera rotates around a point when I try to change the orientation. If I rotate my camera, say, 30 degrees in the Y axis, instead of the camera looking 30 degrees to the right, the camera rotates around the point it was looking at.

o is the camera, A and B are 3D models. The lines show line-of-sight.
This is what I expect:
     A    B
     | > /
     |  /
     | /
     |/
     o

This is what actually happens:
     A    B
     |\
     | \
     |  \
     | > \
          o

Now, from my understanding, in order to move the camera I have to move the world by the inverse of that amount. So if I want to move +1 in the Z axis I translate the world -1 in the Z axis. Since I am using quaternions to represent orientations, I use the camera quaternion’s inverse (since the orientations are always unit quaternions, I optimize by using the conjugate instead of calculating the inverse) to rotate the world by the right amount.

Here is how I convert a quaternion to a matrix, where q is the inverted quaternion:

[1 - 2 * (q.y * q.y + q.z * q.z)   2 * (q.x * q.y - q.w * q.z)       2 * (q.x * q.z + q.w * q.y)         0]
|2 * (q.x * q.y + q.w * q.z)       1 - 2 * (q.x * q.x + q.z * q.z)   2 * (q.y * q.z - q.w * q.x)         0|
|2 * (q.x * q.z - q.w * q.y)       2 * (q.y * q.z + q.w * q.z)       1 - 2 * (q.x * q.x + q.y * q.y)     0|
[0                                 0                                 0                                   1]

After that, I set the translation component of the matrix:

[...   ...   ...  -x]
|...   ...   ...  -y|
|...   ...   ...  -z|
[0     0     0     1]

And finally I multiply that onto the model-view matrix stack, then render all my objects.
I am pretty sure this math is correct, but it doesn’t produce the results that I was expecting. Clearly the forward and right vectors are the problem, so my only question is why are they wrong and how should they be set if I want to get the results I am expecting. Thanks.

EDIT:
I have found the solution from this guy’s quaternion camera class. First i construct a rotation matrix like i was doing before, but then I take the column vectors of the matrix from the first, second and third columns (xa, ya, and za respectively). Then I set the translational component of the matrix like this:

[...  ...  ...  -xa.dotProduct(cameraPos)]
|...  ...  ...  -ya.dotProduct(cameraPos)|
|...  ...  ...  -za.dotProduct(cameraPos)|
[...  ...  ...  ...                      ]

Then the resulting matrix can be multiplied onto the modelview matrix stack, and it works perfectly.

  • 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-29T05:57:28+00:00Added an answer on May 29, 2026 at 5:57 am

    EDIT: I have found the solution from this guy’s quaternion camera class. First i construct a
    rotation matrix like i was doing before, but then I take the column
    vectors of the matrix from the first, second and third columns (xa,
    ya, and za respectively). Then I set the translational component of
    the matrix like this:

    [...  ...  ...  -xa.dotProduct(cameraPos)]
    |...  ...  ...  -ya.dotProduct(cameraPos)|
    |...  ...  ...  -za.dotProduct(cameraPos)|
    [...  ...  ...  ...                      ]
    

    Then the resulting matrix can be multiplied onto the modelview matrix
    stack, and it works perfectly.

    Yes, this is exactly what I would have suggested, only a bit different. You must understand, that OpenGL does not have a camera, but instead you just move the world in the opposite direction, so you need to find the inverse transformation matrix.

    A camera just rotates about and moves. This makes things very simple. The tnverse of translation is just the same vector with opposite sign, and the inverse of a rotation matrix is it’s transpose (column and rows exchanged). Now look at a homogenous transformation matrix like OpenGL uses them:

    R t
    0 1
    

    The upper left 3×3 is the rotational part, the rightmost column is the translation vector. I think the rest you already figured yourself.

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

Sidebar

Related Questions

In OpenGL I'm trying to rotate a camera around a point, with camera being
Right now my application rotates on camera.rotationX, Y Z and does a -translation of
Follow up from: Directdraw: Rotate video stream I managed to preview the camera's video
How would I rotate a view in degrees? I've got the following code setting
Is there any way to rotate the buttons on a UIToolBar as the camera
I'm attempting to get an object to rotate about the origin point (0,0,0) I'm
I'm writing an Android application that uses the camera. I'm setting camera display orientation
Given two consecutive 3D point clouds 1 and 2 (not the whole cloud, say
I have a camera that returns raw images that can easily be converted to
I added Orthographic Camera to my project. I want to show my chart on

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.