Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Rotating around a Scene problem

This topic is 5391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there i'm a newbie to graphics programming with opengl. Basically my problem is that i want to setup an camera such that i'm constantly rotating around my scene and all the objects within the scene. That is i'm doing a complete 360 degrees rotation on the y-axis. Below is my current code that draws the scene and all the objects within: Where will i put the gluLookAt function within this code and what are the possible values? So far i know how to do the up vector for gluLookAt but nothing more than than. Please help. void Display(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); DrawGround(); glPushMatrix(); glLoadIdentity(); glTranslatef(0.0f, 0.0f, zDistance); glBegin(GL_LINES); glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(-nRight, 0.0f, zDistance); glVertex3f(nRight, 0.0f, zDistance); glVertex3f(0.0f, -nBottom, zDistance); glVertex3f(0.0f, nBottom, zDistance); glEnd(); DrawVerticalTicks(); DrawHorizontalTicks(); glLoadIdentity(); glTranslatef(-1.0f, 0.0f, -6.0f); glRotatef(xRot, 0.0f, 1.0f, 0.0f); DrawHouse(); glLoadIdentity(); glTranslatef(2.0f, 0.0f, -6.0f); glRotatef(-xRot, 0.0f, 1.0f, 0.0f); DrawHouse(); glLoadIdentity(); glTranslatef(2.0f, 1.0f, -10.0f); glRotatef(xRot, 0.0f, 1.0f, 0.0f); CreatePyramid(0.0f, 0.0f, 0.0f, 1.0f, 1.0f); glLoadIdentity(); glColor3f(1.0f, 1.0f, 1.0f); glTranslatef(0.0f, 0.0f, -15.0f); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glutSolidCube(1.0f); xRot += 0.2f; yRot += 0.2f; zRot += 0.2f; glPopMatrix(); glutSwapBuffers(); }

Share this post

Link to post
Share on other sites
void gluLookAt(
GLdouble eyex,
GLdouble eyey,
GLdouble eyez,
GLdouble centerx,
GLdouble centery,
GLdouble centerz,
GLdouble upx,
GLdouble upy,
GLdouble upz

the eye ones are the position of the eye. center is what it's looking at. Just set the center to some point in the middle of the scene and use something like

eyex = sin(angle)*radius;
eyez = cos(angle)*radius;
eyey = SomeHeight;

hope that helps. You could also do it by using calls to glRotate and glTranslate so you don't have to use GLU.

Call it after glClear(). But you might want to put
glPushMatrix() before DrawGround(). then do this after each

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!