|
楼主 |
发表于 2010-1-23 11:02:35
|
显示全部楼层
把代码贴出来,请大家看看,多提宝贵意见:
bool WorkerManipulator::calcMovement()
{
......
if (buttonMask==osgGA::GUIEventAdapter:EFT_MOUSE_BUTTON)
{
// rotate camera.
osg::Vec3 axis;
float angle;
float px0 = _ga_t0->getXnormalized();
float py0 = _ga_t0->getYnormalized();
float px1 = _ga_t1->getXnormalized();
float py1 = _ga_t1->getYnormalized();
//限制旋转角度不使其到模型下部
osg::Vec3d eyeNow;
osg::Vec3d centerNow;
osg::Vec3d upNow;
mainView->getCamera()->getViewMatrixAsLookAt(eyeNow, centerNow, upNow);
if(eyeNow[2] > lowZ)
{
//只有弹回正确的Z值范围后即可解除第一下反射标志
//firstReject标志主要为了解决到达边缘时的震动问题
firstReject = false;
}
if((eyeNow[2] < lowZ) || reject)
{
//如果属于拖拽,则不允许继续向下,同时也不反射
if (!_thrown)
{
//将视点向上移动,并计算出新的位置并返回
eyeNow += osg::Vec3d(0.0f, 0.0f, 1.0f);
computePosition(eyeNow, _center, upNow);
reject = false;
return true;
}
if(eyeNow[2] < lowZ)
{
if(!firstReject)
{
//如果不是第一下反射,则允许反射
reject = !reject;
firstReject = true;
}
}
}
//如果是反射,则交换坐标
if(reject)
{
py1 = _ga_t0->getYnormalized();
py0 = _ga_t1->getYnormalized();
px1 = _ga_t0->getXnormalized();
px0 = _ga_t1->getXnormalized();
}
//抛掷衰减
if(!_thrown)
{
//如果不是抛掷则衰减数值恢复
attenuation = 1.0f;
}
else
{
//如果是抛掷则进行衰减
attenuation *= attenuationFactor;
throwScale *= attenuation;
}
trackball(axis,angle,px1,py1,px0,py0);
osg:uat new_rotate;
new_rotate.makeRotate(angle * throwScale,axis);
_rotation = _rotation*new_rotate;
return true;
} |
|