Click to See Complete Forum and Search --> : Camera manipulation using gluLookAt


UCLA.Blue
December 16th, 2006, 03:32 AM
I've been trying to get some real basic camera functions - like a 360 rotation around the x and y axis and panning to work using the OpenGL gluLookAt function. However I can't seem to get the darned thing to work and all the tutorials and faqs all suggest building a camera class that does everything. Not that I'm opposed to using a camera class I'd rather not have to create one if I can simply manipulate where my camera is positioned and looking.

That's the extent of my code:

glClearColor(0.0f,0.5f,1.0f,1.0f); // set the background colour
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

eye[Z] = 8 ;
gluLookAt (cos(eye[X]*TIME)+TIME, sin(eye[Y]*TIME), eye[Z]*TIME,
ref[X], ref[Y], ref[Z], 0.0,1.0,0.0);
//alter for camera movement

glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity();

HMatrix arcball_rot;
Ball_Value(Arcball,arcball_rot);
glMultMatrixf((float *)arcball_rot);

glScalef(Zoom, Zoom, Zoom) ;
glTranslatef(TIME*0.5,0.0,0.0);
set_colour(0.7, 0.4, 0.0);
drawFish(TIME, 1);

(so my fish it swims and the camera's position -should- rotate around it while moving with the fish... but it doesn't. It doens't move at all o.0;)

JohnyDog
December 16th, 2006, 06:52 AM
It's because the worldspace->cameraspace(or viewspace) transformation is done via MODELVIEW matrix, which you are resetting. It should be:


// begin loop
...
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity(); // clear the modelview matrix
...
gluLookAt... // the gluLookAt function sets the MODELVIEW matrix for camera transformations
...
glscale, gltranslate .. // adds (multiplies) to the MODELVIEW matrix the model transformations
draw your model here
...
// end loop

UCLA.Blue
December 16th, 2006, 11:30 AM
lol, what a stupid mistake. Thanks, works great now!