i want draw a
model BoundingBox
in osgearth,but position is not suitable
osg::ComputeBoundsVisitor boundVisitor;
node->accept(boundVisitor);
osg::BoundingBox boundingBox = boundVisitor.getBoundingBox();
osg::Matrixd localToWorld = osg::computeLocalToWorld(paath);
osg::Vec3d pcentter = boundingBox.center() * localToWorld;
float length = boundingBox.xMax() - boundingBox.xMin();
float width = boundingBox.yMax() - boundingBox.yMin();
float height = boundingBox.zMax() - boundingBox.zMin();
osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(
new osg::Box(osg::Vec3d(0,0,0), length, width, height));
drawable->setColor(osg::Vec4(0.0, 1.0, 0.0, 0.6));
geode->addDrawable(drawable);
osg::Vec3d Up=UpInLonLatAltFromXYZ(pcentter.x(),pcentter.y(),pcentter.z());
osg::Vec3d temp(0.0, 0.0, 1.0);
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
mt->addChild(geode);
mt->setMatrix(osg::Matrix::rotate(temp, Up) * osg::Matrix::translate(pcentter)*localToWorld);
What I have tried:
osg::Vec3d UpInLonLatAltFromXYZ(double X, double Y, double Z)
{
osg::EllipsoidModel em;
return osg::Vec3d(em.computeLocalUpVector(X, Y, Z));
}
use
computeLocalUpVector
model can be vertical to the ground, but the direction is wrong