View Full Version : fit to the screen
10-30-2011, 10:04 AM
How can I fit my 3d model on the screen... I am using perspective projection. Please give me some idea.
10-30-2011, 11:04 AM
I would project the vertices to window space. Use gluProject. If all the vertices are inside the viewport, move closer to the model. Compute vertices in window space again and check again if all vertices are inside.
10-31-2011, 04:17 AM
I have a bounding box. minX, maxX, minY, maxY, minZ, maxZ...With these values how can I fit the bounding box onto the screen. Please help me. Thanks Sujan
10-31-2011, 05:46 AM
If you want to be exact, V-man's method is probably the best.
If you need only coarse fitting then you can simply treat the extents of the bounding box and treat it as the radius if the enclosing bounding sphere. From the top of my head I figured the following.
Assuming a symmetrical view frustum, the minimum distance to ensure the bounding sphere is tightly enclosed by the frustum can be computed using the field of view, the center and the radius of the bounding sphere.
fov: opening angle of the view frustum
C: center of the sphere
d: min distance of the camera
E: eye of the camera
D: the viewing direction of the camera
r = |(maxX, maxY, maxZ)|
The distance of the camera can then be computed by
d = r / tan(fov / 2)
Assuming a simple shift parallel to the positive z-axis in world coordinates, one possible camera position and direction can be computed by
E = C + d * (0, 0, 1)
D = C - E / |C - E| (normalized)
The near and far clipping planes have to be at least
n = d - r
f = d + r
That should do. Try it and tell if it works for you.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.