|
我想把汽车的位置与地形上碰撞点的法线垂直,放置结果不对,如图所示,不知道该改哪里,希望大家能帮帮我。
其中lv是小车前进方向,m_rotation是小车要旋转的角度,
osg::Vec3d ip = heightTestResults.getWorldIntersectPoint();
osg::Vec3d np = heightTestResults.getWorldIntersectNormal();
osg::Vec3d lv =delta;
osg::Vec3d uv;
if(np*osg::Vec3(0.0,0.0,1.0)>0.0)
uv=np;
else
uv=-np;
lv.normalize();
osg::Vec3d s(lv^uv);
s.normalize();
osg::Vec3d u(s^uv);
u.normalize();
osg::Matrixd rotation_matrix(s[0], -u[0], -lv[0], 0.0,
s[1], -u[1], -lv[1], 0.0,
s[2], -u[2], -lv[2], 0.0,
0.0, 0.0, 0.0, 1.0);
m_rotation=rotation_matrix.getRotate().inverse();
osg:ositionAttitudeTransform* trans;
trans->setAttitude(m_rotation);
|
|