The bounding sphere of a node is actually generated from a a bounding
box surrounding the Drawable (geometry) leaf. This makes the bounding
sphere a crude approximation of the real size of your sphere.
Therefore I would recommend a parallel structure for doing collision detection.
Depending on the number of collisions, and what information you need
(boolean query/ penetration, normal) there are quite a few different
ways to go around this.
If you only need boolean query (intersection yes/no) and you have lots
of spheres of similar sizes, then a spatial hash is a good
alternative. Its very fast for this thing, you can have 100.000:s of
thousands and still get good performance unless you have them
occupying the same space.
Other efficient datastructures/algorithms are octrees, KD-trees,
sphere-trees, Separating Axis test, ...
It all depends on what scalability you require from your app.
There are quite a few libs that does very efficient collision detection.
Osg is mostly for rendering, and ray/scene intersection tests,
anything beyond that you have to add yourself...
There are quite a few approaches to add ODE for collision
detection/dynamics Look at the osgwiki for Don Burns osg/ode
example.
/Anders
On 5/11/07, Rémi Chaignon <[EMAIL PROTECTED]> wrote:
Hi all again, (sorry I pressed the wrong button)
In my program, I am creating 2 spheres in the same way:
// Create a sphere centered at the origin, unit radius:
osg::Sphere* sphere = new osg::Sphere(osg::Vec3f( 0.f, 0.f, 0.f),
1.f);
osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere);
sphereDrawable->setColor(osg::Vec4f(0.4f, 0.2f,
0.8f, 1.f));
osg::Geode* sphereGeode = new osg::Geode();
sphereGeode->addDrawable(sphereDrawable);
osg::MatrixTransform* sphereTransform = new osg::MatrixTransform();
sphereTransform->addChild(sphereGeode);
return sphereTransform;
Then I want to know if the spheres collide, to do this, I've tried different
ways:
- Get the bounding sphere of the node (getBound())
Result: A collision is detected even when the spheres are far from
each other.
- Get the bounding sphere of the geode (getBound())
- Get the bounding box of the geode (getBoundingBox())
- Get the bounding box of the drawable (getBound())
Result: A collision is always detected.
Debugging, I've found that the bounding box never moves and always remains
the same (eg [-1, 1] on each axis). So I've tried to apply the different
transformations to the bounding box but it didn't work either.
I am new at OpenSceneGraph, so I'm definitely doing something wrong there
but I don't know what.
Can someone help me, please.
Thank you,
Rémi.
___
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
--
Anders Backman Email:[EMAIL PROTECTED]
HPC2N/VRlab Phone:+46 (0)90-786 9936
Umea university Cellular: +46 (0)70-392 64 67
S-901 87 UMEA SWEDEN Fax: +46 90-786 6126
http://www.cs.umu.se/~andersb
___
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/