Problems with gluLookAt();
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
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
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.
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.
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.
If you're using OpenGL lighting or fog, it's important that gluLookAt is used in the MODELVIEW matrix.
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.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL gluLookAt() not doing anything? | ene777 | 1 | 3,016 |
May 1, 2008 08:50 AM Last Post: ThemsAllTook |
|
| gluLookAt problem | vobla | 0 | 2,406 |
Sep 1, 2007 12:44 PM Last Post: vobla |
|
| gluLookAt vs. glRotatef/glTranslatef...etc | hangt5 | 9 | 7,201 |
Mar 15, 2005 12:54 PM Last Post: OneSadCookie |
|

