Archived

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

djwarder

Another Dumb Problem That's Bugging Me!!

Recommended Posts

Hi again I''m trying to code an .OBJ file loader that not only loads the geometry into standard 3d data structures, but also does automatic bounding box generation and positions the camera to look at the mesh that''s been loaded. BUT ... the last bit doesn''t seem to work. I''ve using OpenGl''s "GluLookAt" function to point to the centre of the bounding box, but can''t figure out how to use this info to make sure the camera is zoomed out enough to fit all the mesh on the screen at one time!! Any ideas? Please!!! Dan

Share this post


Link to post
Share on other sites
You may already know that in addition to a target, gluLookAt() also requires a camera position and an up vector. What are you using for your camera position? You should be able to set it pretty much anywhere, such as along the z axis, by some amount that will allow you to see your model.

Are you getting the dreaded ''blank screen''? If so, there may be some other problem, such as not having your perspective or modelview matrix set up right.

Here''s an idea off the top of my head which might help. Maintain the following variables:

float distance;
float rotation;

Then bind some keys that allow you rotate back and forth and increase and decrease distance. Then, every frame, calculate your camera position as:

cam.pos.x = cos(rotation) * distance;
cam.pos.z = sin(rotation) * distance;
cam.pos.y = whatever you want;

Then:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(cam.pos.x, cam.pos.y, cam.pos.z, 0, cam.pos.y, 0, 0, 1, 0); // I can''t remember which comes first, the target or the camera position...

If you get all this working, you should be able to use the aforementioned keys to rotate around your model, and also to increase or decrease your distance to it. In this way you can interactively ''zoom out'' to a distance where you can see the whole model.

That''s just off the top of my head, so I may have missed something. But maybe it''ll get you started...

Share this post


Link to post
Share on other sites