voronoi 发表于 2013-11-16 15:23:59

求助:把模型加载到球上后,模型的位置不对

本帖最后由 voronoi 于 2013-11-16 15:30 编辑

下图是在projected空间下的建筑模型,各个模型之间的相对关系是正确的。


现在,我想把这些建筑模型放到osgearth的球上,代码如下:

                m_Node = osgDB::readNodeFile(m_strFileName);

                osg::ref_ptr<osg::PositionAttitudeTransform> nodePAT = new ::PositionAttitudeTransform;

                std::string name = string_make_lower(name_);
                if ( _attribute_map.find(name_) != _attribute_map.end() ) {
                        db::_attribute* a = _attribute_map;
                        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::Quat 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);

将模型加入到球上后,位置关系明显有问题,不知道问题出在哪?请大牛帮忙看看。

abstract 发表于 2013-12-8 22:25:26

求问楼主
您在编写代码的时候   添加了哪些头文件 , 您的VC++目录包含文件目录有哪些
我也想将模型放在地球上
但是我的配置始终做不成功

仅仅使用OSGVIEWER读取earth文件能成功。

huangzhenyong 发表于 2014-4-7 07:54:45

为何要使用Style呢?

爱德华小遥 发表于 2014-10-20 15:33:46

请问楼主你问题解决了吗   我现在也遇到这个问题
我现在有一片建筑模型,但不知要获取那个坐标点才能准确的把模型加到地球上

maozhumao 发表于 2014-10-21 09:31:51

http://forum.osgearth.org/template/NamlServlet.jtp?macro=search_page&node=2174485&query=model+position&days=0

hprain007 发表于 2015-1-5 16:11:54

爱德华小遥 发表于 2014-10-20 15:33
请问楼主你问题解决了吗   我现在也遇到这个问题
我现在有一片建筑模型,但不知要获取那个坐标点才能准 ...

您的问题解决了吗 怎么获取模型的坐标 怎么对准

爱德华小遥 发表于 2015-1-6 09:15:33

hprain007 发表于 2015-1-5 16:11
您的问题解决了吗 怎么获取模型的坐标 怎么对准

模型的建造过程会有一个基点,通过这个基点的坐标,就可把模型加入到相应的位置

huangzhenyong 发表于 2015-2-1 11:30:01

不要搞太大范围的模型
页: [1]
查看完整版本: 求助:把模型加载到球上后,模型的位置不对