Advertisement Jump to content


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


Another Dumb Problem That's Bugging Me!!

This topic is 5540 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 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;


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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!