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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:23:25+00:00 2026-05-11T18:23:25+00:00

I’ve created this basic 3D Demo using OpenGL/SDL. I handled the keyboard callback so

  • 0

I’ve created this basic 3D Demo using OpenGL/SDL. I handled the keyboard callback so I can "strafe" left and right using ‘a’ and ‘s’ and move forward and backward using ‘s’ and ‘w’.

However, I would like to now make it so I can control the direction my camera is "looking" based off my mouse movements. Just like in a FPS shooter when you move the mouse around it makes the camera look around in various directions.

Does anyone have any idea how I could utilize the mouse callbacks to "points" the camera class correctly when I move the mouse?

#include "SDL.h"
#include "Camera.h"

Camera cam;
Scene scn;

//<<<<<<<<<<<<<<<<<myKeyboard>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void myKeyboard(unsigned char key, int x, int y)
{
  switch(key)
    {
    case 's': cam.slide(0.0, 0.0, 0.2); break;
    case 'w': cam.slide(0.0, 0.0, -0.2); break;
    case 'a': cam.yaw(-1.0); break;
    case 'd': cam.yaw(1.0); break;


    case 27: exit(0);
    }
  glClear(GL_COLOR_BUFFER_BIT);
  glutPostRedisplay();
}

void displaySDL( void )
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    scn.drawSceneOpenGL();
    glFlush();
    glutSwapBuffers();
}

int main( int argc, char* argv[] )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("SDL Sence With Camera");
    glutKeyboardFunc(myKeyboard);
    glutDisplayFunc(displaySDL);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glViewport(0, 0, 640, 480);
    scn.read("fig5_63.dat");
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    scn.makeLightsOpenGL();

    cam.set(2.3, 1.3, 2.0, 0, 0.25, 0, 0, 1, 0);
    cam.setShape(30.0f, 64.0f/48.0f, 0.5f, 50.0f);

    glutMainLoop();
    return 0;
}

This is a tar with my SDL file, and the file I pasted above and my Camera class.
http://www.filedropper.com/fpsdemotar

If someone can give me some tips for what algorithm I should use when processing mouse callbacks in terms of pointing the camera I would appreciate it.

Thanks!

  • 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-11T18:23:25+00:00Added an answer on May 11, 2026 at 6:23 pm

    Mouse moving up/down -> pitch, Mouse moving right/left -> yaw.

    I do not believe having your ‘a’ and ‘d’ keys be yaw is accurate.

    Actually, your whole setup is a bit odd to me, since from a geometric standpoint, I view the coordinate as (x, y, z). You set s and w to go “up” and “down” (z), instead of “forward” and “back” (y). I see it as a xy graph that has been set flat on a table and you are looking at it from above. Moving close to it decreases z, which is coming out of the plane.

    Here is how I would have it setup:

    w -> slide(0, 0.2, 0); // y
    s -> slide(0, -0.2, 0);
    a -> slide(-0.2, 0, 0); // x
    d -> slide(0.2, 0, 0);
    
    //The following goes in your mouse event handler or something:
    pitch(newMouseLocation.y - oldMouseLocation.y); // mouse y is related to pitch
    yaw(newMouseLocaiton.x - oldMouseLocation.x); // mouse x is related to yaw
    

    I realize that you do not need to follow this coordinate convention, but it just seems more intuitive for me.

    I hope this helps.

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

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Data Property as associated with shapes and path geometry dont… May 12, 2026 at 3:04 pm
  • Editorial Team
    Editorial Team added an answer You could try Canam Wiki 1.5. Here is a features… May 12, 2026 at 3:04 pm
  • Editorial Team
    Editorial Team added an answer So, after a great deal of agony I have finally… May 12, 2026 at 3:04 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I am currently running into a problem where an element is coming back from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.