|
发表于 2009-10-21 13:26:37
|
显示全部楼层
bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (buttonMask==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();
trackball(axis,angle,px1,py1,px0,py0);
osg:uat new_rotate;
new_rotate.makeRotate(angle,axis);
_rotation = _rotation*new_rotate;
return true;
}
else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON))
{
// pan model.
float scale = -0.3f*_distance;
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3 dv(dx*scale,dy*scale,0.0f);
_center += dv*rotation_matrix;
return true;
}
else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON)
{
// zoom model.
float fd = _distance;
float scale = 1.0f+dy;
if (fd*scale>_modelScale*_minimumZoomScale)
{
_distance *= scale;
}
else
{
// notify(DEBUG_INFO) << "ushing forward"<<std::endl;
// push the camera forward.
float scale = -fd;
osg::Matrix rotation_matrix(_rotation);
osg::Vec3 dv = (osg::Vec3(0.0f,0.0f,-1.0f)*rotation_matrix)*(dy*scale);
_center += dv;
}
return true;
} |
|