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

  • Home
  • SEARCH
  • 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 5939751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:52:20+00:00 2026-05-22T15:52:20+00:00

I created a camera class. It is possible to rotate 360 degrees with my

  • 0

I created a camera class. It is possible to rotate 360 degrees with my mouse and move up and down. Just as I intended, just like in all games. It is also possible to move forward and backward just like in all games. But I don’t know how to implement moving to the left and right.

I do the following:

This gets called every frame:

gluLookAt(_posX , _posY , _posZ,
          _viewX, _viewY, _viewZ,
          _upX,   _upY,   _upZ );

My move function
Doesnt Work:

void Camera::moveLeft() 
{

    float rot= (_viewY / 180 * PI);
    _moveX -= float(cos(rot)) * 0.5;
    _moveZ -= float(sin(rot)) * 0.5;
}

Does Work
move forwards in the scene:

void Camera::moveForward() 
{

    float viewX = _viewX - _posX;
    float viewY = _viewY - _posY;
    float viewZ = _viewZ - _posZ;

    _posX += viewX * speed
    _posY += viewY * speed;
    _posZ += viewZ * speed;

    _viewX += viewX * speed;
    _viewY += viewY * speed;
    _viewZ += viewZ * speed;

}

When I move with my mouse only, there is no problem. But if I use this function and rotate with my mouse, I get some strange camera movements

Any ideas of how to solve this?

Thank you

@edit

So I removed the glTranslated statement and I changed my moveLeft function to the following:


void Camera::moveLeft(){

float x = ((_viewY * _upZ) - (_viewZ * _upY));
float y = ((_viewZ * _upX) - (_viewX * _upZ));
float z = ((_viewX * _upY) - (_viewY * _upX));

float magnitude = sqrt( (x * x) + (y * y) + (z * z) );

x /= magnitude;
y /= magnitude;
z /= magnitude;

_posX -= x;
_posY -= y;
_posZ -= z;

}

I am clearly doing something wrong because the movements to left and right are “better”, but still not what you would expect.

  • 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-22T15:52:21+00:00Added an answer on May 22, 2026 at 3:52 pm

    To get a vector which points at 90 degrees to the plane that contains your up and view vectors, you need to do a cross product: http://en.wikipedia.org/wiki/Cross_product. Any decent vector maths library will have a function for this.

    The resulting vector will either be a left vector or a right vector (try it out and find out which) and then add it to your position as appropriate.

    Note that this won’t work if your view vector is in exactly the same direction as your up vector.

    Edit: Based on your edited question I think you need to do this:

    You need to get the view direction vector and use that instead of your view vector in the cross product, and then add to both the position and view vector:

    void Camera::moveLeft() 
    {
    
        float viewX = _viewX - _posX;
        float viewY = _viewY - _posY;
        float viewZ = _viewZ - _posZ;
    
        float x = ((viewY * _upZ) - (viewZ * _upY));
        float y = ((viewZ * _upX) - (viewX * _upZ));
        float z = ((viewX * _upY) - (viewY * _upX));
    
        float magnitude = sqrt( (x * x) + (y * y) + (z * z) );
    
        x /= magnitude;
        y /= magnitude;
        z /= magnitude;
    
        _posX -= x;
        _posY -= y;
        _posZ -= z;
    
        _viewX -= x;
        _viewY -= y;
        _viewZ -= z;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ImageManipulator class that performs some cropping, resizing and rotating of camera
So I created an entire app and it works flawlessly the way I envisioned.
I'm quite new to android, but I have already created several apps and published,
I'm trying to wrap a c library in a high-level python interface with Boost.Python.
I'm working on an app for the ipad 2 that lets the user record
I have an application that I am developing for the iPhone. What it does
So what I need is simple: each time we perform our shader (meaning on
I wanted to use the UiImagePicker to record a video then let the user
I have an application that is using jquery, jquerymobile and spine.js running on phonegap
I'm doing my first steps in OpenGL for Android, for developing Augmented Reality apps

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.