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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:56:02+00:00 2026-05-22T14:56:02+00:00

I know this is a common question (as I have read many threads on

  • 0

I know this is a common question (as I have read many threads on here and other forums about it) but for the life of me I can not get the camera rotation that I desire. I want the camera to be able to ‘look around’ and not for it to ‘orbit’ around a point, this point being the OpenGL origin.

I am aware that ‘there is no camera in OpenGL’, the terrain moves and not the viewpoint, etc. and all of those similar concepts but it has not helped me in solving this.

Unfortunately I am stubborn and want to write my code with no deprecated features and so this eliminates 99% of the similar situations I have read about since most of those solutions were with gluLook and similar functions.

The matrix class I am using is similar to the one that is used by the OpenGL SuperBible 5th Edition ( source, GLFrame.h is the main file of interest) but have adapted it to use the OpenGL Mathematics Library.

The typical response to this question is to translate to the origin, rotate, then translate back, but this does nothing for me.

Some code:

void rotateLocalX( GLfloat p_Angle )
{
    if( ( m_Roll < m_RollLimit ) && ( m_Roll > ( -m_RollLimit ) ) )
    {
        //store away the current location so I can translate back to it
        glm::vec3 tempOrigin = getOrigin( );

        m_Roll += p_Angle;

        // Go to the Origin

        //you can also subtract the current location to get to 0.f

        //also doing glm::translate( m_Matrix, -( tempOrigin ) ); -> rotate -> 
        //glm::translate( m_Matrix, tempOrigin ) has the same result
        m_Matrix[ 3 ][ 0 ] = 0.f;
        m_Matrix[ 3 ][ 1 ] = 0.f;
        m_Matrix[ 3 ][ 2 ] = 0.f;
        m_Matrix[ 3 ][ 3 ] = 1.f;

        // Rotate the matrix
        m_Matrix = glm::rotate( m_Matrix, p_Angle, glm::vec3( 1.f, 0.f, 0.f ) );

        // Go back to the original location
        m_Matrix[ 3 ][ 0 ] = tempOrigin.x;
        m_Matrix[ 3 ][ 1 ] = tempOrigin.y;
        m_Matrix[ 3 ][ 2 ] = tempOrigin.z;
        m_Matrix[ 3 ][ 3 ] = 1.f;

        normalize( );
    }
}

And if it is of any consequence, I am treating the camera matrix as the view matrix (with a separate model matrix [view*model=modelview] and a perspective projection matrix).

Finally a typical frame goes like this: check for input (move/rotate camera as appropriate), render skybox (ignoring the origin/location column of the view/camera matrix), draw everything else (taking into account the entire view matrix).

I apologize for asking such a common question but two days of searching and trying various different solutions has yielded no positive results.

Thank you.

  • 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-22T14:56:03+00:00Added an answer on May 22, 2026 at 2:56 pm

    Moving a ‘camera’ is equivalent to applying the inverse transformation to the model.

    Let’s say you have an object centered at point x in your world, oriented with rotation matrix R. You also have a camera at point y in your world, oriented with rotation matrix S. To get what I believe is your desired result when rendering the object, you need a transformation matrix that looks like this:

    S^-1*T(-y)*T(x)*R

    That is, you orient the object around the origin in object coordinates, you translate it to its location in world coordinates. You then translate it so that the camera is at the origin, and finally rotate the object so that the camera is looking down the -z axis. Fortunately, inverting a rotation matrix is the same thing as taking the transpose.

    If you want to translate the camera by c in camera-centered coordinates then you get x’ = x + Sc. The translations are rotated by the forward camera rotation. If you want to rotate by Q in camera coordinates, then you post-multiply: S’ = S*Q.

    If c and Q are in world coordinates then x’ = x + c and S’ = Q*S.


    By your answer to my comment, it sort of sounds like you might just be manipulating the wrong numbers in the matrix. Is it possible that your rows and columns are swapped; so you’re always getting [0,0,0] as the origin? And then setting those values back to zero (although they’re unchanged).


    Edit 2:

    Perhaps you’re not inverting m_Matrix before applying it to the transformation matrix? I think that would create the effect you’re describing. To create the inverse matrix, you will take the transpose of the rotation component, negate the translation component, and rotate the translation component by the rotation component.

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

Sidebar

Related Questions

I know this might be a common question but I have tried to search
I know this is a common question but I just can't seem to get
I know this isn't strictly a programming question but y'all must have experienced this.
I know this has probably been answered as it seems a common question but
Okay, I know this is a common enough question, but all the solutions I've
I know this is probably a common and easily answered question, but I'm a
I know this question has been asked many times here and elsewhere before as
I know this question is very common but the main point in my question
I know this is a common convention, but what does the k in variable
I know this is a common error, but bear with me. I've pursued the

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.