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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:38:59+00:00 2026-05-13T08:38:59+00:00

I’m implementing a simple camera system in OpenGL. I set up gluPerspective under the

  • 0

I’m implementing a simple camera system in OpenGL. I set up gluPerspective under the projection matrix and then use gluLookAt on the ModelView matrix. After this I have my main render loop which checks for keyboard events and, if any of the arrow keys are pressed, modifies angular and forward speeds (I only rotate through the y axis and move through the z (forwards)). Then I move the view using the following code (deltaTime is the amount of time since the last frame was rendered in seconds, in order to decouple movement from framerate):

//place our camera  
newTime = RunTime(); //get the time since app start  
deltaTime = newTime - time; //get the time since the last frame was rendered  
time = newTime;  
glRotatef(view.angularSpeed*deltaTime,0,1,0); //rotate  
glTranslatef(0,0,view.forwardSpeed*deltaTime); //move forwards  
//draw our vertices  
draw();  
//swap buffers  
Swap_Buffers();  

Then the code loops around again. My draw algorithm begins with a glPushMatrix() and ends in a glPopMatrix().

Each call to glRotatef() and glTranslatef() pushes the view forwards by the forwards speed in the direction of view.

However when I run the code, my object is drawn in the correct place, but when I move the movement is done with the orientation of the world origin (0,0,0 – facing along the Z axis) as opposed to the local orientation (where I’m pointing) and when I rotate, the rotation is done about (0,0,0) and not the position of the camera.

I end up with this strange effect of my camera orbiting (0,0,0) as opposed to rotating on the spot.

I do not call glLoadIdentity() at all anywhere inside the loop, and I am sure that the Matrix Mode is set to GL_MODELVIEW for the entire loop.

Another odd effect is if I put a glLoadIdentity() call inside the draw() function (between the PushMatrix and PopMatrix calls, the screen just goes black and no matter where I look I can’t find the object I draw.

Does anybody know what I’ve messed up in order to make this orbit (0,0,0) instead of rotate on the spot?

  • 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-13T08:38:59+00:00Added an answer on May 13, 2026 at 8:38 am

    glRotate() rotates the ModelView Matrix around the World Origin, so to rotate around some arbitrary point, you need to translate your matrix to have that point at the origin, rotate and then translate back to where you started.

    I think what you need is this

    float x, y, z;//point you want to rotate around
    
    glTranslatef(0,0,view.forwardSpeed*deltaTime); //move forwards
    
    glTranslatef(x,y,z); //translate to origin
    glRotatef(view.angularSpeed*deltaTime,0,1,0); //rotate
    glTranslatef(-x,-y,-z); //translate back
    //draw our vertices
    draw();
    //swap buffers
    Swap_Buffers();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 296k
  • Answers 296k
  • 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 vim can do this. In your vimrc resource file: :au… May 13, 2026 at 7:02 pm
  • Editorial Team
    Editorial Team added an answer Cast it to text, remove with regexp, and cast back… May 13, 2026 at 7:02 pm
  • Editorial Team
    Editorial Team added an answer Check out the scrollTo jQuery plugin. You can simply do… May 13, 2026 at 7:02 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

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.