Re: Simple renderer in .net with direct3d
 November 25, 2013 11:45PM Standards Committee Member James Jessiman Memorial Award Recipient LDraw Part Author/Reviewer Registered: 3 years agoPosts: 815
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:

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.
SubjectAuthorViewsPosted
Michael Heidemann726November 23, 2013 04:48AM
Roland Melkert299November 23, 2013 09:47AM
Michael Heidemann258November 23, 2013 10:16AM
Roland Melkert247November 23, 2013 10:36AM
Michael Heidemann210November 23, 2013 10:39AM
Michael Heidemann493November 23, 2013 10:48AM
Roland Melkert171November 23, 2013 11:15AM
Michael Heidemann199November 23, 2013 11:19AM
Roland Melkert216November 23, 2013 11:22AM
Michael Heidemann204November 23, 2013 11:32AM
Roland Melkert185November 23, 2013 11:40AM
Michael Heidemann207November 23, 2013 11:54AM
Michael Heidemann226November 23, 2013 11:59AM
Roland Melkert208November 23, 2013 12:27PM
Michael Heidemann205November 23, 2013 12:16PM
Roland Melkert201November 23, 2013 12:25PM
Michael Heidemann232November 23, 2013 12:30PM
Roland Melkert228November 23, 2013 12:50PM
Michael Heidemann191November 23, 2013 12:58PM
Roland Melkert192November 23, 2013 01:06PM
Michael Heidemann211November 23, 2013 01:13PM
Travis Cobbs394November 25, 2013 11:45PM
Michael Heidemann324November 26, 2013 09:36AM
Michael Heidemann264November 29, 2013 03:18AM
Roland Melkert289November 29, 2013 10:22AM
Michael Heidemann248November 30, 2013 02:55AM
Michael Heidemann199November 30, 2013 07:08AM
Michael Heidemann280November 30, 2013 07:48AM
Roland Melkert246November 30, 2013 10:40AM
Michael Heidemann184November 30, 2013 11:44AM
Roland Melkert457November 30, 2013 12:04PM
Michael Heidemann370December 01, 2013 04:33AM
Michael Heidemann302December 01, 2013 08:34AM
Michael Heidemann298December 01, 2013 08:58AM
Roland Melkert303December 01, 2013 09:51AM
Michael Heidemann498December 01, 2013 09:54AM
Travis Cobbs325December 01, 2013 09:08PM
Michael Heidemann326December 02, 2013 09:58AM
Roland Melkert323December 02, 2013 10:05AM
Steffen328December 02, 2013 11:58PM
Michael Heidemann342December 03, 2013 08:53AM
Steffen458December 07, 2013 01:57AM
Michael Heidemann274December 07, 2013 03:10AM
Roland Melkert361December 02, 2013 09:59AM
Michael Heidemann331December 06, 2013 09:30AM
Roland Melkert233December 06, 2013 10:20AM
Michael Heidemann220December 06, 2013 11:30AM
Roland Melkert284December 06, 2013 12:27PM
Michael Heidemann210December 06, 2013 01:22PM
Travis Cobbs266December 06, 2013 03:25PM
Michael Heidemann456December 06, 2013 11:06PM
Roland Melkert255December 07, 2013 10:11AM
Michael Heidemann482December 08, 2013 02:46AM

Sorry, only registered users may post in this forum.