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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:04:42+00:00 2026-05-31T08:04:42+00:00

I was setting up a camera following this tutorial . My problem is that

  • 0

I was setting up a camera following this tutorial. My problem is that when I move it isn’t fluid, it kinda jumps. I’m calculating the MVP whenever the mouse moves using this code:

void motion(int x, int y) {
    static bool wrap = false;

    if(!wrap) {
        int ww = glutGet(GLUT_WINDOW_WIDTH);
        int wh = glutGet(GLUT_WINDOW_HEIGHT);

        int dx = x - ww / 2;
        int dy = y - wh / 2;

        const float mousespeed = 0.001;

        angles.x += dx * mousespeed;
        angles.y += dy * mousespeed;


        if(angles.x < -M_PI)
            angles.x += M_PI * 2;
        else if(angles.x > M_PI)
            angles.x -= M_PI * 2;

        if(angles.y < -M_PI / 2)
            angles.y = -M_PI / 2;
        if(angles.y > M_PI / 2)
            angles.y = M_PI / 2;

        lookat.x = sinf(angles.x) * cosf(angles.y);
        lookat.y = sinf(angles.y);
        lookat.z = cosf(angles.x) * cosf(angles.y);
        view = glm::lookAt(position, position + lookat, glm::vec3(0, 1, 0));

        // move mouse pointer back to the center of the window
        wrap = true;
        glutWarpPointer(ww / 2, wh / 2);
    } else {
        wrap = false;
    }
}

And then I’m updating the attribute on my ‘OnIdele()’ function:

void onIdle() {
    glUseProgram(program);

    glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
    glm::mat4 Model = glm::mat4(1.0f);
    glm::mat4 MVP = Projection * view * Model;

    glUniformMatrix4fv(uniform_mvp, 1, GL_FALSE, glm::value_ptr(MVP));

    glutPostRedisplay();
}

My question is, is this the right way to implement this? Is there any way to avoid the laggyness?

Also if you don’t mind me asking, how exactly does this code work? I know it limits where you can look but I can’t seem to make sense of it:

 if(angles.x < -M_PI)
            angles.x += M_PI * 2;
        else if(angles.x > M_PI)
            angles.x -= M_PI * 2;

        if(angles.y < -M_PI / 2)
            angles.y = -M_PI / 2;
        if(angles.y > M_PI / 2)
            angles.y = M_PI / 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-31T08:04:43+00:00Added an answer on May 31, 2026 at 8:04 am

    See if increasing mousespeed makes a difference. After you find the distance the mouse has moved, stored in dx and dy, you scale the distance by mousespeed before adding it to the camera’s angles. The lower the value of mousespeed the less your mouse movement will affect the angles of your camera, and vice versa.

    Also the code you asked about is limiting your camera angles to between 0 and PI * 2, or 0 and 360 degrees.

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

Sidebar

Related Questions

I followed the tutorial on http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/ to achieve a camera that follows my player
I'm writing an Android application that uses the camera. I'm setting camera display orientation
Setting onchange event for CheckBoxList using the following code doesn't work. chkListUserGroup.Attributes.Add(onchange, document.forms[0].isRecordModified.value='true';); How
In a MonoDroid app, the following code is used to start the native camera
How would I rotate a view in degrees? I've got the following code setting
I encountered the problem when working with IP Camera Panasonic (BL-C111CE). I want to
this is basic question. im having touble setting the camra not how to set
this question probably wont be explained very well and that's because I don't really
I am having a problem with correctly detecting a user's camera settings. If the
In my app, I have an Activity that acts as a camera preview. I

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.