Public Group

# default 3d view

This topic is 4882 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 JohnBoltonThere 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 ) );

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633300
• Total Posts
3011266
• ### Who's Online (See full list)

There are no registered users currently online

×