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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:37:52+00:00 2026-06-14T10:37:52+00:00

I have been looking into this problem for a while now but I can’t

  • 0

I have been looking into this problem for a while now but I can’t find a solution.
Right now my camera follows the players position correctly but the rotation of the camera goes wrong. If I only use one rotation it goes correctly, say of I rotate only along the x axis then it works fine. But the second I add another rotation say the ‘y’ things go wrong and the camera starts looking into the wrong direction.

Right now my camera only has a position and a rotation.

Here is some code.

glm::vec4 cameraPosition;

//This gives the camera the distance it keaps from the player.
cameraPosition.x = 0.0;
cameraPosition.y = 0.0;
cameraPosition.z = 20.0;
cameraPosition.w = 0.0;

// mStartingModel is the rotation matrix of the player.
glm::vec4 result = mStartingModel * cameraPosition;

//here I set the camera's position and rotation. The z rotation is given a extra 180 degrees so the camera is behind the player.
CameraHandler::getSingleton().getDefaultCamera()->setPosition(Vector3f(-player->mPosition.x + result.x, -player->mPosition.y + result.y, -player->mPosition.z + result.z), Vector3f(-(player->mRotation.x + 180), -player->mRotation.y, -player->mRotation.z) );

Also know I am using opengl, c++ and glm.

  • 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-14T10:37:53+00:00Added an answer on June 14, 2026 at 10:37 am

    If you want a simple behavior, using gluLookAt is probably the simplest option! More infos here.

    Seeing that you use glm, consider something like

    glm::mat4 CameraMatrix = glm::LookAt(
        cameraPosition, // the position of your camera, in world space
        cameraTarget,   // where you want to look at, in world space
        upVector        // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too
    );
    

    As taken from this site on opengl tutorials.

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

Sidebar

Related Questions

I have been looking for a while now but I can not find an
I have been looking for a solution to this problem for a while now
I've been looking into this issue for 2 days, but no luck. I have
I have been looking around for an answer to this, but couldn't really find
I have been looking into backbone.js and I can't seem to figure out how
I have been looking into HTML5 manifest but I am unclear as to whether
I've been using RhinoMocks for a good while, but just started looking into Moq.
so my studies have led me to this little problem. (ive been into php
Ok well I have been fighting with this for a while now and have
I have been browsing the web for a while now and looking at different

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.