This topic is now archived and is closed to further replies.

gluLookAt questions

This topic is 5498 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 folks, Sorry if this is a fairly newb-ish question, but hopefully someone here can help me out ... I''m setting up a typical 3rd-person view camera angle, and I''m using gluLookAt to set up my camera. Ideally, I want to have my 3d model at the "looking at" part of the camera, so that when I rotate the camera about that point, my model turns. I''ve got that implemented and it works well ... when I rotate the camera about the "looking-at" part, the model also rotates appropriately, as I expected. Here''s the issue though... and I can''t think of a good way around it, yet. I want to move the model "closer" to the viewer. I''ve tried adjusting the camera position and view to bring the camera closer, but that doesn''t provide quite the right effect. What I''m really looking for is to move the model "down" the screen a bit, so they are about 1-2 inches above the bottom of the window. What I''m wondering, is if there is a good way to make the focus of "gluLookAt" NOT focus on the center of the window, as it seems to now. Alternatively, does anyone have a smart way of moving the character "lower" on the screen, but keeping it so that they rotate properly when rotating the camera? I hope this is clear, sorry if I''m not using the right terminology here, I''m still new to this stuff Thanks in advance!

Share this post

Link to post
Share on other sites
you could have the camera look at a position above the position of the object. that will have the effect i think you want. so camera.pos = obj.pos + 5; where 5 is an appropriate unit of distance given your current coordinate scaling.


Share this post

Link to post
Share on other sites
Ok, we had thought of that, that would probably work ... the only thing is, is right now our model is placed at camera.view ...

basically it''s like

gluLookAt(x, y, z, viewx, viewy, viewz, 0, 1, 0);
then we
glTranslatef(viewx, viewy, viewz);
and draw our model...

So right now, the model doesn''t exactly have an absolute position, it''s just equal to wherever the camera is "looking at"... is there a practical workaround/solution to doing that? I think we could probably figure out how to absolutely position the character, but I still see problems happening when we "rotate" around the view of the camera ... the character will either get left behind, or rotate in a "circle". What we effectively want to do is rotate the camera around the model.

Thanks for the help so far!

Share this post

Link to post
Share on other sites
usually it's more typical to do something like.

gluLookAt(blah blah blah,
obj.pos.x, obj.pos.y + 5,
obj.pos.z, blah, blah blah);

or even better give your Camera class/struct a member variable of type GameObject * pointedAt. if that var isn't null/0 then your camera is looking at an object and camera.view = obj.pos + offset; so then the gluLookAt(....) is made way easier (see below):

//in your update loop

void update (dT) {
if (camera.pointedAt)
camera.view = camera.pointedAt->pos + offset;

//rest of object update code

void draw() {
//now your gluLookAt is simple and easily understandable
gluLookAt(camera.pos.x, camera.pos.y, camera.pos.z,
camera.view.x, camera.view.y, camera.view.z,
camera.up.x, camera.up.y, camera.up.z);

//it makes way more conceptual sense for all object to have
//absolute positions. then drawing every object is the same

for (int i = 0; i < numObjects; i++) {
glTranslatef(obj.pos.x, obj[i].pos.y, obj[i].pos.z);


[edited by - Palidine on November 21, 2002 4:28:17 PM]

[edited by - Palidine on November 21, 2002 4:30:36 PM]

Share this post

Link to post
Share on other sites