Hi Bruno,
You can choose many different ways. OSG is not a collision detection library
but it has some functionality you can play with. Also you can use bullet
physics which is a free physics library. Also this is a pretty easy detection
implementation and you can just do it on your own.
1. osg:
look at:
osg::PolytopyIntersector:
Code:
osgUtil::PolytopeIntersector * picker = new
osgUtil::PolytopeIntersector(osgUtil::Intersector::CoordinateFrame::PROJECTION,
rectangle_min_x, rectangle_min_y, rectangle_max_x, rectangle_maxy);
// setup picker ...
osgUtil::IntersectionVisitor intersecvisitor(picker);
// setup iv
viewer->getCamera()->accept(iv);
I'm not shure if it's possible to select a SINGLE Point from a geometry with
this.
2. bullet physics
ask at bullet physics for this
3. own implementation:
an easy point in rectangle implementation:
Code:
bool point3DinsideRectangle2D(Position p, Rectangle r) {
if(p.x < r.minPos.x || p.y < r.minPos.y)
return false;
if(p.x > r.maxPos.x || p.y > r.maxPos.y)
return false;
}
If you would check every point like this it would take hours. So make this test
above for each point after you checked the boundingbox of a geometry or
drawable:
Code:
bool boundingBox3DinsideRectangle2D(BoundingBox bb, Rectangle r) {
if(bb.xMin() < r.minPos.x || bb.yMin() < r.minPos.y)
return false;
if(bb.xMax() > r.maxPos.x || bb.yMax() > r.maxPos.y)
return false;
}
You can implement this with a simple NodeVisitor. For the Rectangle make shure
to transform the choosen min and max right.
Code:
Rectangle r;
// minP, maxP from selection
// transform them
minP = this->mViewer->getCamera()->getProjectionMatrix() *
this->mViewer->getCamera()->getViewMatrix() * minP;
maxP = this->mViewer->getCamera()->getProjectionMatrix() *
this->mViewer->getCamera()->getViewMatrix() * maxP;
// compute new min max
r.min.x = min(minP.x, maxP.x);
r.min.y = min(minP.y, maxP.y);
r.max.x = max(minP.x, maxP.x);
r.max.y = max(minP.y, maxP.y);
Something like this should work. But using a Rectangle isn't actually right. A
rectangle drawn on display will actually create a frustum with the view. (If
look at a cuboid in 3D, you will see a frustum that you'r brain will interpret
as cuboid)
If you like to use frustum google for:
"Point in Frustum"
And
"Intersection BoundingBox and Frustum"
I guess you will find plenty of stuff.
Cheers,
NoxxKn
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66722#66722
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org