How to correctly approximate a sphere ( collisson sphere ) to an object, say cube?

Started by
5 comments, last by GMA965_X3100 13 years, 3 months ago
Simple answers now. As the title asks, how is this done 'correctly' in openGL?
Give a generic answer that applies to any object, to save time. Give a specific exemplification if you can.
http://img440.images...gamedevsig.jpg/

I'm not the typical programmer.
Advertisement
I don't know why you post this in opengl, it's not really relevant.

OpenGL doesn't do these kinds of things for you, it just draws meshes that you give it.

Anyway, what I would do in your case is just pick a point at the center, then iterate over all the mesh vertices and find the length from the center to that vertex. The longest one is your sphere radius. This is obviously going to be larger than your mesh, so you may try to put in some kind of scaling fudge factor. It's obviously going to be dependent on what your object looks like how good of a result you get.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Quote:Original post by karwosts
I don't know why you post this in opengl, it's not really relevant.

OpenGL doesn't do these kinds of things for you, it just draws meshes that you give it.

Anyway, what I would do in your case is just pick a point at the center, then iterate over all the mesh vertices and find the length from the center to that vertex. The longest one is your sphere radius. This is obviously going to be larger than your mesh, so you may try to put in some kind of scaling fudge factor. It's obviously going to be dependent on what your object looks like how good of a result you get.


Since sphere/sphere collision detection is extremely fast its normally used as an early test, its preferable to have it give false positives over false negatives since you normally will follow it up with a more detailed check anyway, thus there is really no need at all to scale the sphere (unless you want to use the sphere as the only test, but in that case you want to set the sphere size manually anyway)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Quote:Original post by karwosts
I don't know why you post this in opengl, it's not really relevant.

OpenGL doesn't do these kinds of things for you, it just draws meshes that you give it.

Anyway, what I would do in your case is just pick a point at the center, then iterate over all the mesh vertices and find the length from the center to that vertex. The longest one is your sphere radius. This is obviously going to be larger than your mesh, so you may try to put in some kind of scaling fudge factor. It's obviously going to be dependent on what your object looks like how good of a result you get.


I'm not entirely getting what your saying:)

What I get the big picture:
Scrap what I just said, what i want is this!!!!


Uploaded with ImageShack.us

THAT ABOVE, MY theory involves getting a sphere on just one face........Don't worry about implementation, just tell me how this may be done, approximate the sphere's point to one face!!!!
http://img440.images...gamedevsig.jpg/

I'm not the typical programmer.
Add all the points together, divide that by the number of points?
------------------------------Great Little War Game
Why do you want to have a collision sphere for single faces?

If you want to get a collision sphere for an arbitrary object, there are several simple ways, one being to caluclate the bounding box and wrap that with a sphere. Thus the sphere should fit even if the object is rotated (provided the object is locally rotated around the sphere's center)

There are more complex approaches to get a tighter fitting bounding sphere, but those might be too complex right now.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
I Figured it out. What I dis was to to take one diagonal of a square face, and used it's those vertices to acquire a midpoint value. Because it's a square, and diagonals are equal in a square, the boudning sphere was correctly approximated to sphere. One step closer to decrypting my theory of special damage, and collision detection and response.
http://img440.images...gamedevsig.jpg/

I'm not the typical programmer.

This topic is closed to new replies.

Advertisement