|
请教各位大牛,我在做animationPath的时候实时调整模型姿态时,遇到一些问题,我的飞机的机翼在飞行时要如何调到与地面平行(图片) 部分代码如下(可能有误)- for( ;iter != m_AniMap.end(); iter++ )
- {
- pSec = iter->second.m_Point;
-
- //假设称其为飞行坐标系(Look,Up, Right)
- //飞行方向..look
- osg::Vec3d Look = pSec - pFir;
- double lengh = Look.length();
- Look.normalize();
- //测试运算 地理空间坐标?
- osg::Vec3d U = pFir;
- U.normalize();
- osg::Vec3d Up = Look ^ U;
- Up.normalize();
- //对应于Look,这个大概就是机翼伸出来的方向
- osg::Vec3d Right = Look ^ Up;
- Right.normalize();
- int t = lengh/m_FlyTime;
- for( int index=0; index<m_FlyTime; ++index )
- {
- osg::Vec3d advVec = pFir + Look * t * index;
- advVec.y() += 300.0;
- osg::Quat quat2 ;
- quat2.makeRotate(osg::Vec3d(0.0, -1.0, 0.0), Look);
- //???计算飞行坐标 机翼方向与地平面的夹角
- double angle = asin(Right.y()/Right.length());//acos(osg::Vec3d(1,0,0) * Right);
- OE_WARN<< " angle is " << angle <<std::endl;
- //机头对齐 and 旋转机翼??
- osg::Quat ratote (quat2 * osg::Quat(angle, Look));
-
- m_AniPath->insert(time, osg::AnimationPath::ControlPoint(advVec, ratote));
复制代码 我的思路飞行时,使机头与路径方向一致,然后计算Right与地平面的夹角angle,然后绕Look旋转angle..测试结果是错的,希望各位给点意见. 多谢了。 |
-
-
|