How are the min and max values calculated for an arbitrary mesh? (for setting bounding volumes)
I know it has something to do with adding up the total verticies, and then dividing or subtracting something else..or not. I don't really know.
Thanks.
How are the min and max values calculated for an arbitrary mesh? (for setting bounding volumes)
I know it has something to do with adding up the total verticies, and then dividing or subtracting something else..or not. I don't really know.
Thanks.
M.Eng Computer Engineering CandidateB.Sc Computer Science
Robotics and graphics enthusiast.
Just iterate through all the vertices keeping track of min/max x, y, and z?
That works too.
I was almost positive that there was some formula (or more complicated way) of doing it though. Maybe I confused it with something else?
M.Eng Computer Engineering CandidateB.Sc Computer Science
Robotics and graphics enthusiast.
None that I know of except using averaging and/or tracking min/max.
Just add it to your loading process..
When you're loading the model you're iterating through all the vertices anyways, just check each one to find out if it is higher or lower then the one before...
Then store the minimum and maximum...
To me this sounds very costly though.
Sometimes I forget what I am doing when I enter a room, actually, quite often.
>To me this sounds very costly though.
why is that? you iterate through every vertex while you read it in anyway. And a couple of lt/gt's isn't going to hurt anything. The only alternative would be to store the bounds.
The way to setup bounding volumes is to use meshes. In the 3D modeler you will create your mesh and then also create a bounding mesh for it as well. The bounding mesh can double as your physics collision hull. In order to do accurate collision detection you must simplify your mesh which is done by creating a totally new one based on the actual mesh.
The bounding volume can either be included as a very simple cube mesh or you can iterate the vertices of the collision mesh/hull to find out the min/maxes.
Shrug, maybe you're right...
But those greater and less than signs might cause a problem with a couple if's in a loop of 5000++ vertices.
Course I could be underestimating the processing abilities of modern processors.
Sometimes I forget what I am doing when I enter a room, actually, quite often.
Once you have the min/max as perspective said, you can define the middle as:
Vector3 middle = (maxs + mins) * .5f;
If you want the mesh exactly centered around this 'middle,' while in object space, you simply do:
for(each_vertex)
vertices[current_vertex] -= middle;
And if you want a radius:
Vector3 radius_vector;
if(-mins.x > maxs.x)
radius_vector.x = -mins.x;
else
radius_vector.x = maxs.x;
..etc...
float radius_magnitude = radius_vector.length();
Last edited by BobMcGee123; 04-20-2006 at 03:34 PM.
I'm not immature, I'm refined in the opposite direction.
I think you would get a greater bottle neck from disk I/O.Originally Posted by Shamino
It's not like you need to do this every frame.
Anything you would need to do in computer graphics is never considered expensive just as long as you only need to do it once.
Last edited by BobMcGee123; 04-20-2006 at 05:02 PM.
I'm not immature, I'm refined in the opposite direction.
For my skeletal animation I'm looping through all vertices, normals and tangents once per frame for every model and recalculating them for the new skeleton. This process takes about 0.5 milliseconds for a model I've imported from Doom3 and with all optimisations on. And that is on a 4 years old computer, 1.6 GHz. Since I'm used to Flash I always underestimate the power nowadays myself I simulated a simulation (ehm, yes ^^) of half a million particles and that would run at about 25 fps, and that simulation involved a square root calculation for each particle along with ~40 lines of other calculations.
So I think that you can take the ~0.5 milliseconds at startup to calculate the bounding box for the mesh Thats at least what I'm going to do after I've figured out how to write a good scene manager.
EDIT: Small spelling mistake.
Last edited by The Wazaa; 04-21-2006 at 02:30 AM.
Got it working. The loading time didn't seem to increase at all, and if it did, it was by a very, very small amount.
M.Eng Computer Engineering CandidateB.Sc Computer Science
Robotics and graphics enthusiast.