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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:54:29+00:00 2026-06-15T20:54:29+00:00

So, I’m attempting to create an FPS style camera to explore my scene with,

  • 0

So, I’m attempting to create an FPS style camera to explore my scene with, and it seems to be working fine. There is no way of changing the pitch of the camera at the moment. I am trying to create a function that allows me to set the camera to some predefined viewpoints, however when attempting to rotate the camera after setting it to a new viewpoint using the setPosition() function, I experience a jump not in position but in orientation when first pressing the rotate button.

This is my camera class implementation.

Camera::Camera(void)
{
    angleX = 0.0;
    angleY = 0.0;
    directionX = 0.0;
    directionZ = -5.0;
    directionY = 0.0;
    xPos = 0.0;
    zPos = 1.0;
    yPos = 2.0;
}

void Camera::setPosition(float xDir, float yDir, float zDir, float posX, float posZ, float posY)
{
    directionX = xDir;
    directionZ = zDir;
    directionY = yDir;
    xPos = posX;
    zPos = posZ;
    yPos = posY;
}

Camera::~Camera(void)
{
}

The following is my special keys callback function, with functionality other than camera movement omitted.

void specialKeys(int key, int xx, int yy)
{
    float fraction = 0.3f;

    switch(key)
    {
        // Camera Controls
        case GLUT_KEY_LEFT:
            camera.angleY -= 0.05f;
            camera.directionX = sin(camera.angleY);
            camera.directionZ = -cos(camera.angleY);
            break;
        case GLUT_KEY_RIGHT:
            camera.angleY += 0.05f;
            camera.directionX = sin(camera.angleY);
            camera.directionZ = -cos(camera.angleY);
            break;
        case GLUT_KEY_UP:
            camera.xPos += camera.directionX * fraction;
            camera.zPos += camera.directionZ * fraction;
            camera.yPos += camera.directionY * fraction;
            break;
        case GLUT_KEY_DOWN:
            camera.xPos -= camera.directionX * fraction;
            camera.zPos -= camera.directionZ * fraction;
            camera.yPos -= camera.directionY * fraction;
            break;
       }
}

The display callback function then has the following code using gluLookAt:

glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(camera.xPos, camera.yPos, camera.zPos, camera.xPos+camera.directionX, camera.yPos+camera.directionY, camera.zPos+camera.directionZ, 0, 1, 0);

I cannot see why I am getting this issue. I believe it’s something to do with the interaction between setting the camera and the maths being used to rotate it. Can anyone see how to prevent this jump in orientation?

I am setting the camera position in a keyboard callback function, the code is as follows:

    if(key == '1') // Default View
        camera = Camera();
    if(key == '2') // Ferris Wheel View
        camera.setPosition(-0.8, 0.0, -0.6, 3.6, 3.6, 6.5);
    if(key == '3') // Fountain Water View
        camera.setPosition(0.9, 0.0, -0.4, -0.59, -6.4, 0.6);
  • 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-15T20:54:31+00:00Added an answer on June 15, 2026 at 8:54 pm

    The jump is because how you are initializing your directionZ variable, look at:

       angleX = 0.0;
       angleY = 0.0;
       directionX = 0.0;
       directionZ = -5.0;
       directionY = 0.0;
    

    But later you define directionX and directionZ to be:

    camera.directionX = sin(camera.angleY);
    camera.directionZ = -cos(camera.angleY);
    

    cos is bounded on the intervel [-1, 1] and since angleY is 0.0f, directionZ will be set to -1. If you change your initialization code to set directionZ = -1.0; you should get rid of the jump.

    don’t set direction explicitly. Here is an example of setting an angle and computing direction from that angle:

    void Camera::setPosition(float angle, float posX, float posZ, float posY)
    {
        xPos = posX;
        zPos = posZ;
        yPos = posY;
    
        //compute instead of set based on angle
        angleY = angle;
        camera.directionX = sin(angleY);
        camera.directionZ = -cos(angleY);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.