• Advertisement
Sign in to follow this  

Fit to Screen - How To?

This topic is 4683 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... I have done a prog that opens a file with the coordinates of several triangles and displays them in the screen. The user can Rotate, Pan, and Zoom the 3D object. I would like to give the user the ability to fit the object on the screen, no matter what the user have already rotated, but I have no idea on how to do this in DirectX 8. I think this should be something like centering the projection of the object on the screen and adjust the Zoom scale... But how can I know where the projection is? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You can use orthogonal projections to make something (like a quad) fill the entire screen. Then just make the objects the size that you want them displayed as. With orthogonal projections you get 1:1 projections.

Share this post


Link to post
Share on other sites
Thanks for your response...

I'm already using orthogonal projections because I don't like perspective efect.

However, the objects that my prog opens are unknown to me and can have any shape...

How can I identify the square on the screen that the object is being projected to?

I've started DirectX only 2 weeks ago... so... what's that about a quad?

Thanks

Share this post


Link to post
Share on other sites
Instead of altering the projection, you'll need to alter the vertices of the mesh. Say you use an ortho projection with width and height set to 1.0f. You'll have vertices between 0.0f and 1.0f on the screen. For your mesh to fit within that range, you'll have to find the vertex that is farthest out in each direction, then scale it (and all other vertices in that axis) down. This is really a rather simple process, and if you use D3DXMesh, I believe there are some functions with finding the extents of a mesh.

Loop through all vertices;
{
if (XVertex > FarthestXVertex)
FarthestXVertex = XVertex;
if (YVertex > FarthestYVertex)
FarthestYVertex = YVertex;
if (ZVertex > FarthestZVertex)
FarthestZVertex = ZVertex;
}

Now you know the vertices that are the farthest in the X, Y, and Z directions.

ScaleX = 1.0f/FarthestXVertex;
ScaleY = 1.0f/FarthestYVertex;
ScaleZ = 1.0f/FarthestZVertex;

Here, 1.0f is the value for width, height, and depth. You may want to use an ortho projection with 640x480 instead, but I would encourage you to use 1.0f instead. It allows you to represent in percentages instead of pixels. This helps alleviate changing stuff when they resize the screen.

Share this post


Link to post
Share on other sites
How about using D3DXComputeBoundingSphere() and then adjust the view position or scaling to include the whole sphere?

Shawn

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Create bounding boxes around the objects and check if they are inside/outside the frustum view (see Cull sample from SDK).
If the bounding boxes are completely inside the frustum, increase the zoom until the maximum limit (one 'step' before a bounding box intercepts the frustum planes).
If the bounding boxes are outside the frustum (or intercepting the frustum planes), decrease the zoom until they are completely inside the frustum.

Share this post


Link to post
Share on other sites
Ok...

Thanks to everyone.

I've managed to solve my problem by looping all the vertices and aplying to them the rotations of the matWorld...

This way I can check where each vertex is on my screen coordinates and so I can adjust the position and zoom...

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement