|
本帖最后由 voronoi 于 2013-11-16 15:27 编辑
下图是在projected空间下的建筑模型,各个模型之间的相对关系是正确的。
现在,我想把这些建筑模型放到osgearth的球上,代码如下:
m_Node = osgDB::readNodeFile(m_strFileName);
osg::ref_ptr<osg:ositionAttitudeTransform> nodePAT = new ::PositionAttitudeTransform;
std::string name = string_make_lower(name_);
if ( _attribute_map.find(name_) != _attribute_map.end() ) {
db::_attribute* a = _attribute_map[name];
double _X_insertion_point = atof(a->_X_insertion_point.c_str());
double _Y_insertion_point = atof(a->_Y_insertion_point.c_str());
double _Z_insertion_point = atof(a->_Z_insertion_point.c_str());
double _Z_insertion_point_ = _Z_insertion_point;
double _X_scale = atof(a->_X_scale.c_str());
double _Y_scale = atof(a->_Y_scale.c_str());
double _Z_scale = atof(a->_Z_scale.c_str());
double _Rotation = atof(a->_Rotation.c_str());
double _Rotation_Direction_X = atof(a->_Rotation_Direction_X.c_str());
double _Rotation_Direction_Y = atof(a->_Rotation_Direction_Y.c_str());
double _Rotation_Direction_Z = atof(a->_Rotation_Direction_Z.c_str());
double _UTrans_angle = atof(a->_UTrans_angle.c_str());
double _UTrans_Direction_X = atof(a->_UTrans_Direction_X.c_str());
double _UTrans_Direction_Y = atof(a->_UTrans_Direction_Y.c_str());
double _UTrans_Direction_Z = atof(a->_UTrans_Direction_Z.c_str());
// 将模型与地形进行配准,这里只是一个估计值,真实的值,暂时无法获取。
// 下面的偏移值 是根据中央电视大楼的新址的位置 算出来的一个相对值。
_X_insertion_point -= 2689354.084687071;
_Y_insertion_point += 4110818.296879871;
_Z_insertion_point += 4039083.203658373;
osg::Vec3f vTrans = osg::Vec3f(_UTrans_Direction_X, _UTrans_Direction_Y, _UTrans_Direction_Z) * _UTrans_angle;
nodePAT->setScale( osg::Vec3f( _X_scale, _Y_scale, _Z_scale ) );
osg:uat quat(_Rotation, osg::Vec3f(_Rotation_Direction_X, _Rotation_Direction_Y, _Rotation_Direction_Z));
nodePAT->setAttitude(quat);
osg::BoundingSphere bound = m_Node->getBound();
osg::Vec3f v = nodePAT->getPosition();
nodePAT->addChild(m_Node.get());
AddToSceneGraph* pAddToSceneGraph = AddToSceneGraph::Instance();
const SpatialReference* geoSRS = pAddToSceneGraph->_mapNode->getMapSRS()->getGeographicSRS();
osgEarth::Style style;
style.getOrCreate<ModelSymbol>()->setModel( nodePAT );
ModelNode* model = new ModelNode( pAddToSceneGraph->_mapNode, style );
double X, Y, Z;
double latitude, longitude, height;
pAddToSceneGraph->_mapNode->getMapSRS()->getEllipsoid()->convertXYZToLatLongHeight( _X_insertion_point, _Y_insertion_point, _Z_insertion_point, latitude, longitude, height);
model->setPosition( GeoPoint(geoSRS, osg::RadiansToDegrees(longitude), osg::RadiansToDegrees(latitude), _Z_insertion_point_, ALTMODE_ABSOLUTE) );
pAddToSceneGraph->AddNode(model);
将模型加入到球上后,位置关系明显有问题,不知道问题出在哪?请大牛帮忙看看。
|
|