0
votes

I need to check intersection between two moving nodes before they hit.

I have this code, which works, but it only is true when they already hit.

Is there a simple way to give an offset to the bounding box, so it gives true before they hit?

osg::ComputeBoundsVisitor cbv;
MatrixTransform* transform = new osg::MatrixTransform;
transform->addChild(node);
transform->accept(cbv);
osg::BoundingBox bb = cbv.getBoundingBox();

osg::ComputeBoundsVisitor cbv2;
MatrixTransform* transform2 = new osg::MatrixTransform;
transform2->addChild(node2);
transform2->accept(cbv2);
osg::BoundingBox bb2 = cbv2.getBoundingBox();

bool intersects=bb.intersects(bb2);
1

1 Answers

0
votes

You could manually use expandBy ( https://codedocs.xyz/openscenegraph/OpenSceneGraph/a01950.html#a4d779d1d6346bce5b3ae469c886a777f ) to increase the size of the bounding box. Take the existing XYZ min point, add your offset, and call expandBy. Repeat with the XYZ max point.