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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:39:58+00:00 2026-05-23T20:39:58+00:00

I have written a 3D environment in OpenGL where you can move forward/backwards and

  • 0

I have written a 3D environment in OpenGL where you can move forward/backwards and look around (up/down left/right) However I cant work out how you can side step to the left of right.

I am using gluLookAt and my moving forward code is

GLfloat v[] = {[self centerAtIndex:0] - [self eyeAtIndex:0],[self centerAtIndex:1] - [self eyeAtIndex:1], [self centerAtIndex:2] - [self eyeAtIndex:2]}; 

[self setEye:[self eyeAtIndex:0] + v[0] * SPEED_MOVE atIndex:0];
[self setEye:[self eyeAtIndex:2] + v[2] * SPEED_MOVE atIndex:2];
[self setCenter: [self centerAtIndex:0] + v[0] * SPEED_MOVE atIndex:0];
[self setCenter: [self centerAtIndex:2] + v[2] * SPEED_MOVE atIndex:2];

and

gluLookAt(eye[0], eye[1], eye[2],center[0],  center[1], center[2], 0.0, 1, 0.0);

Anyone got any idea how to side step or seen an example?

Solution

float up[3] = {0, 1, 0};
        float forward[3] = { center[0] - eye[0],center[1] - eye[1],center[2] - eye[2] };

        float left[3];
        left[0] = forward[1] * up[2] - forward[2] * up[1];
        left[1] = forward[2] * up[0] - forward[0] * up[2];
        left[2] = forward[0] * up[1] - forward[1] * up[0];

        // now translate your eye position
        [self setEye:[self eyeAtIndex:0] - left[0] * SPEED_MOVE atIndex:0];
        [self setEye:[self eyeAtIndex:2] - left[2] * SPEED_MOVE atIndex:2];
        [self setCenter: [self centerAtIndex:0] - left[0] * SPEED_MOVE atIndex:0];
        [self setCenter: [self centerAtIndex:2] - left[2] * SPEED_MOVE atIndex:2];  


        if (([self eyeAtIndex:2] >= MapSizeZ || [self eyeAtIndex:0] >= MapSizeX  || [self eyeAtIndex:2] <= 1 || [self eyeAtIndex:0] <= 1) || [self checkCollisionWithPoint:CGPointMake([self eyeAtIndex:0] ,[self eyeAtIndex:2])] ){

            [self setEye:[self eyeAtIndex:0] + left[0] * SPEED_MOVE atIndex:0];
            [self setEye:[self eyeAtIndex:2] + left[2] * SPEED_MOVE atIndex:2];
            [self setCenter: [self centerAtIndex:0] + left[0] * SPEED_MOVE atIndex:0];
            [self setCenter: [self centerAtIndex:2] + left[2] * SPEED_MOVE atIndex:2];  
        }
  • 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-23T20:39:59+00:00Added an answer on May 23, 2026 at 8:39 pm

    To move sideways you simply have to translate the eye position along the camera’s right vector.

    To find the right vector, remember that the cross product of two vectors gives a perpendicular vector. So, the cross product of your forward vector and your up vector will give the right vector.

    Your forward vector is v[3], but I will use ‘forward’ here for clarity.

    // find the Right vector. (forward cross product up)
    float right[3];
    right[0] = forward[1] * up[2] - forward[2] * up[1];
    right[1] = forward[2] * up[0] - forward[0] * up[2];
    right[2] = forward[0] * up[1] - forward[1] * up[0];
    
    // now translate your eye position
    [self setEye:[self eyeAtIndex:0] + right[0] * SPEED_MOVE atIndex:0];
    [self setEye:[self eyeAtIndex:2] + right[2] * SPEED_MOVE atIndex:2];
    

    You should also note that the glu library is not available for OpenGL ES, so you will have to reimplement the lookat function, which is straightforward, but also another question.

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

Sidebar

Related Questions

We have a Visual Studio Wizard written using the DTE environment to automatically generate
I have a c++ source code that was written in linux/unix environment by some
I have written a bash script which installs a number of packages, however for
I have written a small application which will be used in my work environment
I have written an application in C# that generates all the words that can
Environment - C#, .net 4.0, VS 2010 Hello, I have written a simple shell
I have written a VB script (.vbs) to add a Windows System Environment variable,
I have written a program that uses 2 million arrays of integer values. However,
I have project written in Zend Framework and it works fine most of environments.
have written this little class, which generates a UUID every time an object of

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.