Simple renderer in .net with SharpGL (openGL)


Re: Simple renderer in .net with direct3d
#22
I can't directly answer your question, since I don't know Direct3D. However, I can give an overview of what LDView does.

IIRC, LDView first calculates the bounding box for the whole model. Next, using the center of that box, it calculates the bounding sphere for the whole model. It then moves the camera to the center of the sphere, then backs it up by an amount calculated based on the FOV and the sphere radius. I believe that the distance to move back is:

radius / sin(fov/2)

Note that I believe fov in the above is either the horizontal FOV (if the window is taller than it is wide) or the vertical FOV (if the window is wider than it is tall). OpenGL expects you to always give it the vertical FOV, so LDView calculates that based on the horizontal FOV when the window is taller than it is wide. I suspect that Direct3D also wants the vertical FOV. If you always use the same FOV value, no matter what the window shape, I believe you'll get a cropped image if you use that in the above calculation when the window is taller than it is wide.

If have have the horizontal FOV, the vertical FOV can be calculated like so:

VFOV = 2*atan(tan(hfov/2)/(width/height))

Note also that LDView's default zoom level (calculated as per above) is set up so that no matter how you rotate the model, it will always be fully visible (which is why it uses the bounding sphere).

LDView's "zoom to fit" functionality uses an algorithm I got from Lars C. Hassing that solves numerous equations for numerous unknowns to move the view pyramid around until at least two points on the model are exactly at the edge of the view. (Those two points are either at the top and bottom of the view, or at the left and right.) The pyramid is moved in such a way that the view direction remains constant, but the camera position moves in all three dimensions, so the look-at point also moves.
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Re: Simple renderer in .net with direct3d - by Travis Cobbs - 2013-11-26, 7:45

Forum Jump:


Users browsing this thread: 1 Guest(s)