10-25-2009, 04:13 AM
Hi am trying to rotate a camera around my scene I have, the camera position is in this function:
void reshape(int width, int height)
glViewport(0, 0, (GLsizei) width, (GLsizei) height);
/*glOrtho(-(float) 2.0*CUBE_SIZE, (float) 2.0*CUBE_SIZE, -(float) 2.0*CUBE_SIZE,
(float) 2.0*CUBE_SIZE, zm, (float)40.0*CUBE_SIZE);*/
glFrustum(-(float) 2.0*CUBE_SIZE, (float) 2.0*CUBE_SIZE, -(float) 2.0*CUBE_SIZE,
(float) 2.0*CUBE_SIZE, zm, (float)40.0*CUBE_SIZE);
How can I rotate the camera but still stay looking at the center of my scene?
10-25-2009, 06:49 AM
You have described the viewing volume and how it is mapped to the pixels of your monitor. Everything you have is correct but it is just not describing the camera position ... To place and orient the camera apply the gluLookAt (http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.opengl/doc/openglrf/gluLookAt.htm) function to the GL_MODELVIEW matrix with center (x,y,z)=(0,0,0) or whatever the center of your scene is in global coordinates.
void gluLookAt( GLdouble eyeX,
GLdouble upZ )
so you would add this add to the _beginning_ of your the render display function a camera as follows:
//for example to spin the camera located in the xy-plane
// around the z-axis
// the camera stays looking at the center 0,0,0 all the time
// and is located a distance .5 from the center
static angle = 0.0;
angle += 360./10.;
// set camera parameters
// start drawing your scene objects after gluLookAt
//... glPushMatrix ... glPopMatrix ..
Note, your reshape(int width, int height) function is fine and should remain unchanged. The camera goes into your display() function since you want to change it from frame to frame for animation effect.
A detailed but well worth reading chapter on openGL camera, transformations, etc is OpenGL Redbook, Chapter 3 (http://glprogramming.com/red/chapter03.html)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.