|
本帖最后由 abc-osg 于 2014-8-19 10:13 编辑
osg::ref_ptr<osg::Group> mRoot;//根节点
osg::ref_ptr<osg::MatrixTransform> omt;
mRoot = new osg::Group;
omt = new osg::MatrixTransform() ;
mRoot->addChild(omt);
omt->setDataVariance( osg::Object:: DYNAMIC );
osg::ref_ptr<osg::Node> mModelnew = osgDB::readNodeFile("car.3ds");
omt->addChild(mModelnew);//mModelnew);
osg::Matrix mx;
mx.makeTranslate(osg::Vec3(4568.5312,-8387.43457,20.0f));
omt->setMatrix(mx);
漫游器:
class Manipulator:public osgGA::TrackballManipulator
osg::ref_ptr<osg::AnimationPath> _animationPath;//漫游路径
osg::Matrix _animationMatrix;
osg::Matrixd Manipulator::getInverseMatrix() const
{
if(_beginAnimation&&_animationPath.valid())
{
/* osg::Vec3d _eye,_center,_up;
_animationMatrix.getLookAt(_eye,_center,_up);
_center=this->_center;
osg::Vec3 dir=_eye-_center;
dir.normalize();*/
return _animationMatrix;
}
}
bool Manipulator::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us )
{
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&us);
if(!viewer)
return false;
if(_animationPath.valid())
{
if(_animationPath->getLastTime()-_animationPath->getFirstTime()>=_animationedTime)
//省略时间 漫游没有任何问题
{
_animationPath->getInverse(_animationedTime,_animationMatrix);
//如何让模型居于场景中心
}
}
else
osgGA::TrackballManipulator::handle(ea,us);
return false;
} |
|