Problems with gluLookAt();

ghettotek
Unregistered
 
Post: #1
im trying to write a simple game engine in Cocoa and everything was going good until it came time to implement a camera system.

from what i understand, gluLookAt() provides an efficient way to simulate camera's and camera movement.

they way i have this setup is that models are loaded, "objects" are created from the models, and at each frame, each object is drawn.

this is the basic way i draw each object:

void drawObjects()
{
goes through all the objects and calls each objects drawObject method
}

note: each object draws itself separately
void drawObject()
{
glLoadIdentity();
translation to object's corresponding position vector
rotation based on object's corresponding orientation
drawing of object's corresponding model using glDrawElements()
}

now everything works fine when i dont try to implement a camera; the objects rotate and move fine, just the way i want them too.

however, i cant get gluLookAt() to "transform the scene" to match the camera's position and orientation.

this is the basic way i update the camera:

void updateCamera()
{
glLoadIdentity();
gluLookAt(...);
}

and when i draw each frame, this is how i do it:

void updateFrame()
{
...unrelated crap
glMatrixMode(GL_MODELVIEW);
updateCamera();
drawObjects();
...some more crap
}

the only problem i have is that its not working. i cant seem to get the concept right. someone please help me ive been up for at least 2 days messing with this. thanks in advance
Quote this message in a reply
ghettotek
Unregistered
 
Post: #2
nevermind i finally got it. good sh*t. i was so frustrated with this that i started chopping up my code at random and i guess it worked out in my favor. lol. god im glad i got over that.
Quote this message in a reply
kainsin
Unregistered
 
Post: #3
Isn't gluLookAt supposed to be used when in the Projection matrix?
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #4
The two matrices are interchangable, the fact that there are 2 of them is just a convenience.

Also, are you using glPushMatrix() and glPopMatrix()? If you call glLoadIdentity() the matrix is completely cleared, which effectively moves the camera back to the origin.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
If you're using OpenGL lighting or fog, it's important that gluLookAt is used in the MODELVIEW matrix.
Quote this message in a reply
henryj
Unregistered
 
Post: #6
gluLookat is supposed to be applied to the ModelView matrix. It is effectively a bunch of translations and rotations. While applying it to the projection matrix may work it isn't recommended because it can lead to weird stuff happening especially with lighting.
Quote this message in a reply
ghettotek
Unregistered
 
Post: #7
i still havent actually gotten gluLookAt to work. i replaced it with the reverse-translation technique. it seems to work pretty good. does gluLookAt offer any advantages over this technique? or is it all the same?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL gluLookAt() not doing anything? ene777 1 3,777 May 1, 2008 08:50 AM
Last Post: ThemsAllTook
  gluLookAt problem vobla 0 2,734 Sep 1, 2007 12:44 PM
Last Post: vobla
  gluLookAt vs. glRotatef/glTranslatef...etc hangt5 9 8,398 Mar 15, 2005 12:54 PM
Last Post: OneSadCookie