View Full Version : shortest distance a boundingbox to current camera
08-19-2002, 11:29 PM
Hello, In a 3D scene, I want calculate the Near/Far planes of "gluPerspective" function in order to obtain a optimal ratio.
Then I want calculate the shortest distance of the every boundingbox's entities of the scene to the current positon/direction camera.
How I do?
thanks in avance.
08-20-2002, 10:16 PM
hey ahuarte, what's goin on man?
what i would do is form a ray with the camera location as the origin of the ray, and the camera view direction as the direction of the ray. then i'd perform a ray/OBB intersection test.
i suggest you pick up a book like real time rendering if you have a need to do lots of intersection testing. in the meantime check out this page: http://www.realtimerendering.com/int/
from what i understand you're going to recalculate the near and far planes each frame based on the distance to the nearest/farthest object. i imagine that would be very slow, and probably not a good idea.
08-21-2002, 01:18 AM
thanks your reply, but if I want calculate an optimal ratio far/near in order to get a nicest scene, how I do it ?
what do you suggest ?
thank you very much
08-21-2002, 02:33 AM
"thanks your reply, but if I want calculate an optimal ratio far/near in order to get a nicest scene, how I do it ?"
there are two main things to consider when coming up with a good near/far plane ratio. first, you want to include in the scene as much of the geometry that should be visible as possible. second, you want to keep z-fighting to a minimum.
unfortunately, these two goals oppose each other. pushing the far plane back increases the likelihood of having z-buffer problems.
here's all the advise i can offer:
1) push the near plane back as far as is reasonably possible. this is more plausible for a flight sim than, say, a first person shooter.
2) use fogging or alpha-LODing to reduce the "popping" effect of having geometry suddenly appear/disappear as it enters/exits the view frustrum.
3) use a 32 bit z-buffer.
another technique i used in a terrain viewing program was to calculate the distance to the location of the terrain that the view was centered on. as the distance to this point decreased (or increased), it eventually crossed a threshold value, and i changed the near and far clip planes accordingly. this technique isn't plausible for general applications though, since the view isn't always "centered" on a particular point.
what you are talking about, computing an "optimal" near/far ratio based on the geometry in the scene, isn't a very good idea since the location of both the camera and the drawable geometry is changing (i assume). thus, the optimal ratio could change from one frame to the next.
all i can recommend is that you do some testing and try to come up with some reasonable values for your app. forget about determining "optimal" values based on the geometry in the scene.
08-21-2002, 10:40 AM
Well, in my terrain I use quadtree and use frustum culling... I pass a point to my frutum culling function and it returns the distance form the camera position to the tested point... I control my LOD that way...
If that is sounds like soemthing you might use you can get it from http://cheo.resnet.wayne.edu/terrain.zip
That one has some of what I mentioned...
08-21-2002, 10:41 PM
My 3D application is a very large terrain viewer. I have readed that there is a technique called multi-pass.
You draw the scene twice.
1) Set near/far values 500/5.000
2) draw only features which crosses this extent
3) Set near/far values 1/550
4) draw only features which crosses last extent
I will try use Fog and a simple multi-pass algorithm.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.