Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
Rick York 24-May-21 21:33pm    
I don't have an answer for you but when I run into problems like this I try first try to determine if there is an issue with the model or with the drawing. To do that I first try drawing a simple model like a cube, tetrahedron, or sphere. Usually it is one I define myself and I try to make it the same size as the one of interest. Once I see it displayed correctly then I try it with the other one.
peanutpig 25-May-21 20:29pm    
thank you very mush

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900