Sign in to follow this  

default 3d view

This topic is 4546 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

I would like to make a program to view 3ds files. However, many of the files do not contain a camera definition. Thus, it seems necessary to create a default view. Does anyone know what the standard procedure for doing so is? My current idea for a default view is to compute the centroid by averaging all the points. Then, I will translate by the opposite of the centroid (to essentially move the centroid to 0). Then I will scale everything by the maximum distance from the centroid to make the maximum distance 1. Then I will push everything back along the z axis by -2. Here's some pseudocode: centroidx = (sum of all x values) / (number of points); centroidy = (sum of all y values) / (number of points); centroidz = (sum of all z values) / (number of points); maxdist = maximumdist(centroidx, centroidy, centroidz, points); glTranslatef(0, 0, -2); glScale(1/maxdist); glTranslatef(-centroidx, -centroidy, -centroidz); drawpoints(); Does this seem reasonable? Mike C. http://www.coolgroups.com/zoomer/

Share this post


Link to post
Share on other sites
There is no need to scale. Just place the model at the position where its bounding sphere fits in the window. The distance is computed like this:

z = radius / sin( fov/2 )

So, you code will look something like this:
    glTranslatef( -centroidx, -centroidy, -centroidz );
glTranslatef( 0.0f, 0.0f, -maxdist / sinf( fov * 0.5f ) );

Share this post


Link to post
Share on other sites
I thought of this, but what if it's outside the viewing frustum? That's why I opted to scale instead.

Mike C.
http://www.coolgroups.com/zoomer/

Quote:
Original post by JohnBolton
There is no need to scale. Just place the model at the position where its bounding sphere fits in the window. The distance is computed like this:

z = radius / sin( fov/2 )

So, you code will look something like this:
    glTranslatef( -centroidx, -centroidy, -centroidz );
glTranslatef( 0.0f, 0.0f, -maxdist / sinf( fov * 0.5f ) );


Share this post


Link to post
Share on other sites

This topic is 4546 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this