|
楼主 |
发表于 2012-5-8 12:22:45
|
显示全部楼层
void HeightLightHandler::setViewPointToFeature(osg::Node *pnode)
{
osg::NodePathList nodePaths = pnode->getParentalNodePaths();
//若节点路径不为空
if (!nodePaths.empty())
{
osg::NodePath path = nodePaths[0];
osg::Matrixd localToWorld = osg::computeLocalToWorld( path );
osg::Vec3d center = osg::Vec3d(0,0,0) * localToWorld;
osg::ref_ptr<osg::Geode> pgeode = dynamic_cast<osg::Geode *>(pnode);
osg::ref_ptr<osg:rawable> drawable = pgeode->getDrawable(0);
osg::ref_ptr<osg::Geometry> geomtry = drawable->asGeometry();
osg::ref_ptr<osg::Vec3Array> arry = dynamic_cast<osg::Vec3Array *>(geomtry->getVertexArray());
double x(0);
double y(0);
double z(0);
int s(0);
for (osg::Vec3Array::iterator itor = arry->begin();itor != arry->end();itor++,s++)
{
x += itor->x();
y += itor->y();
z += itor->z();
}
x = x/s;
y = y/s;
z = z/s;
osg::Vec3d myvalue(x,y,z);
//if (drawable)
//{
// const osg::BoundingSphere& bs = drawable->getBound();
//
if ( !dynamic_cast<osg::MatrixTransform*>(pnode) )
center += myvalue;
//}
//else
//{
// qDebug()<<"no drawable in node..";
// return;
//}
osgEarth::GeoPoint output;
_pMap->worldPointToMapPoint(myvalue, output);
osgEarth::Viewpoint viewpoint(output.vec3d(), 0.0, -90.0, drawable->getBound().radius() * 4.0);
osgEarth::Util::EarthManipulator *mapOpeator = dynamic_cast<osgEarth::Util::EarthManipulator*>(_pViewer->getCameraManipulator());
if (mapOpeator)
{
mapOpeator->setViewpoint(viewpoint,0.5f);
_pViewer->requestRedraw();
}
} |
|