Skip to main content
gamedev.net
🔒 Locked

bounding sphere

Started by Mursel 2 replies 250+ views
Original Post
Mursel
Mursel
when i make initialization for every mesh i make bounding sphere for them. But there is radius in function. how to figure out radius for meshes? tnx
Pseudo
Pseudo
If you are using D3DX meshes, there is a function to compute the radius built in. otherwise, first you need to calculate the center, and then you can calculate the farthest vertex from the center.

I''m not positive, but I think if you sum up all the vertex positions and then divide by the number of verts, you will get a measure of center. you can then loop through all verts again, and calculate the distance from that point, and the biggest distance is your radius. depending on the model you might want to throw out outliers, or just shrink the radious at the end a bit. either way works pretty well.
Mursel
Mursel
I am using D3DXMeshes so radius is really built-in!
Anyway, when i am using scaled object my radius is wrong. I figured out that radius of that object is initialization radius.

So, how to figure out radius from scaled object?

tnx again...
Lazy303
Lazy303
You''ll have to scale the radius with the same value you
scaled your mesh...

radius=radius*scalefactor;

Use the largest scalefactor if you scale your mesh
in several axis.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.