首页 > 解决方案 > osg::BoundingBox 交点偏移检测

问题描述

我需要在两个移动节点碰撞之前检查它们之间的交叉点。

我有这段代码,它有效,但只有当它们已经命中时它才是正确的。

有没有一种简单的方法可以给边界框一个偏移量,所以在它们击中之前它会给出真实的?

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);

标签: c++openscenegraph

解决方案


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.


推荐阅读