tags:

views:

116

answers:

2

How does a 3D model handled unit wise ?
When i have a random model that i want to fit in my view port i dunno if it is too big or not, if i need to translate it to be in the middle...
I think a 3d object might have it's own origine.

A: 

Sorry, your question is very unclear. I suppose you want to center a 3D model to a viewport. You can achieve this by calculating the model's bounding box. To do this, traverse all polygons and get the minimum/maximum X/Y/Z coordinates. The bounding box given by the points (min_x,min_y,min_z) and (max_x,max_y,max_z) will contain the whole model. Now you can center the model by looking at the center of this box. With some further calculations (depending on your FOV) you can also get the left/right/upper/lower borders inside your viewport.

schnaader
i grabed a random model on the internet and i wanted to show it in opengl for learning, but i can't see anything, but by tweaking a little i can see some movement, so i tried to scale it down, it's a bit better, so i wanted to know how i could get the model bounds like you said to fit the model in my view
CiNN
+1  A: 

You need to find a bounding volume, a shape that encloses all the object's vertices, for your object that is easier to work with than the object itself. Spheres are often used for this. Either the artist can define the sphere as part of the model information or you can work it out at run time. Calculating the optimal sphere is very hard, but you can get a good approximation using the following:

determine the min and max value of each point's x, y and z
  for each vertex
    min_x = min (min_x, vertex.x)
    max_x = max (max_x, vertex.x)
    min_y = min (min_y, vertex.y)
    max_y = max (max_y, vertex.y)
    min_z = min (min_z, vertex.z)
    max_z = max (max_z, vertex.z)

sphere centre = (max_x + min_x) / 2, (max_y + min_y) / 2, (max_z + min_z) / 2
sphere radius = distance from centre to (max_x, max_y, max_z)

Using this sphere, determine the a world position that allows the sphere to be viewed in full - simple geometry will determine this.

Skizz

Skizz