From Jan Perciva with changes from Robert Osfield, "I am submitting improved osgGA camera manipulators.
Changes: - new mouse wheel zoom/movement/center functionality - ability to fix vertical axis (important for CAD) - possibility to specify values as absolute values or relative to model size - kind of backward compatibility by flags passed to constructor - and much more - restructuring classes to use kind of hierarchy and standard way of event processing (handle methods). This way, there is much more code reusability and it is more easy to develop new kinds of manipulators. Briefly, the new architecture keeps MatrixManipulator as base abstract class. StandardManipulator is the feature-rich standard manipulator with two main descendant classes: OrbitManipulator and FirstPersonManipulator. OrbitManipulator is base class for all trackball style manipulators, based on center, rotation and distance from center. FirstPersonManipulator is base for walk or fly style manipulators, using position and rotation for camera manipulation. " Changes by Robert: Replaced osg::Vec3 by osg::Vec3d, introduced DEFAULT_SETTINGS enum and usage. Added frame time member variables in prep for improving throw animation when vysync is off.
This commit is contained in:
@@ -8,7 +8,7 @@ void KeySwitchMatrixManipulator::addMatrixManipulator(int key, std::string name,
|
||||
if(!cm) return;
|
||||
|
||||
_manips[key]=std::make_pair(name,osg::ref_ptr<MatrixManipulator>(cm));
|
||||
|
||||
|
||||
if(!_current)
|
||||
{
|
||||
_current=cm;
|
||||
@@ -34,7 +34,7 @@ void KeySwitchMatrixManipulator::selectMatrixManipulator(unsigned int num)
|
||||
++itr,++manipNo)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
if (itr!=_manips.end())
|
||||
{
|
||||
itr->second.second->setHomePosition(_homeEye,_homeCenter,_homeUp,_autoComputeHomePosition);
|
||||
@@ -45,7 +45,7 @@ void KeySwitchMatrixManipulator::selectMatrixManipulator(unsigned int num)
|
||||
{
|
||||
itr->second.second->setCoordinateFrameCallback(_current->getCoordinateFrameCallback());
|
||||
}
|
||||
|
||||
|
||||
if ( !itr->second.second->getNode() )
|
||||
{
|
||||
itr->second.second->setNode(_current->getNode());
|
||||
@@ -56,26 +56,6 @@ void KeySwitchMatrixManipulator::selectMatrixManipulator(unsigned int num)
|
||||
}
|
||||
}
|
||||
|
||||
/** Set the distance parameter (used by TrackballManipulator etc.) */
|
||||
void KeySwitchMatrixManipulator::setDistance(double distance)
|
||||
{
|
||||
for(KeyManipMap::iterator itr=_manips.begin();
|
||||
itr!=_manips.end();
|
||||
++itr)
|
||||
{
|
||||
itr->second.second->setDistance(distance);
|
||||
}
|
||||
}
|
||||
|
||||
double KeySwitchMatrixManipulator::getDistance() const
|
||||
{
|
||||
if(_current)
|
||||
{
|
||||
return _current->getDistance();
|
||||
}
|
||||
else return 1.0;
|
||||
}
|
||||
|
||||
void KeySwitchMatrixManipulator::setNode(osg::Node* node)
|
||||
{
|
||||
for(KeyManipMap::iterator itr=_manips.begin();
|
||||
@@ -108,17 +88,6 @@ void KeySwitchMatrixManipulator::setAutoComputeHomePosition(bool flag)
|
||||
}
|
||||
}
|
||||
|
||||
void KeySwitchMatrixManipulator::setMinimumDistance(float minimumDistance)
|
||||
{
|
||||
_minimumDistance = minimumDistance;
|
||||
for(KeyManipMap::iterator itr=_manips.begin();
|
||||
itr!=_manips.end();
|
||||
++itr)
|
||||
{
|
||||
itr->second.second->setMinimumDistance(minimumDistance);
|
||||
}
|
||||
}
|
||||
|
||||
void KeySwitchMatrixManipulator::computeHomePosition()
|
||||
{
|
||||
for(KeyManipMap::iterator itr=_manips.begin();
|
||||
@@ -129,6 +98,23 @@ void KeySwitchMatrixManipulator::computeHomePosition()
|
||||
}
|
||||
}
|
||||
|
||||
void KeySwitchMatrixManipulator::home(const GUIEventAdapter& ee,GUIActionAdapter& aa)
|
||||
{
|
||||
// call home for all child manipulators
|
||||
// (this can not be done just for current manipulator,
|
||||
// because it is not possible to transfer some manipulator
|
||||
// settings across manipulators using just MatrixManipulator interface
|
||||
// (one problematic variable is for example OrbitManipulator::distance
|
||||
// that can not be passed by setByMatrix method),
|
||||
// thus we have to call home on all of them)
|
||||
for(KeyManipMap::iterator itr=_manips.begin();
|
||||
itr!=_manips.end();
|
||||
++itr)
|
||||
{
|
||||
itr->second.second->home(ee,aa);
|
||||
}
|
||||
}
|
||||
|
||||
void KeySwitchMatrixManipulator::setCoordinateFrameCallback(CoordinateFrameCallback* cb)
|
||||
{
|
||||
_coordinateFrameCallback = cb;
|
||||
@@ -147,7 +133,7 @@ MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulatorWithIndex(uns
|
||||
itr != _manips.end();
|
||||
++itr, ++i)
|
||||
{
|
||||
if (i==index) return itr->second.second.get();
|
||||
if (i==index) return itr->second.second.get();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -159,22 +145,22 @@ const MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulatorWithInd
|
||||
itr != _manips.end();
|
||||
++itr, ++i)
|
||||
{
|
||||
if (i==index) return itr->second.second.get();
|
||||
if (i==index) return itr->second.second.get();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulatorWithKey(unsigned int key)
|
||||
{
|
||||
KeyManipMap::iterator itr = _manips.find(key);
|
||||
if (itr!=_manips.end()) return itr->second.second.get();
|
||||
KeyManipMap::iterator itr = _manips.find(key);
|
||||
if (itr!=_manips.end()) return itr->second.second.get();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
const MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulatorWithKey(unsigned int key) const
|
||||
{
|
||||
KeyManipMap::const_iterator itr = _manips.find(key);
|
||||
if (itr!=_manips.end()) return itr->second.second.get();
|
||||
KeyManipMap::const_iterator itr = _manips.find(key);
|
||||
if (itr!=_manips.end()) return itr->second.second.get();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
@@ -200,7 +186,7 @@ bool KeySwitchMatrixManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapt
|
||||
_current = it->second.second;
|
||||
|
||||
//_cameraManipChangeCallbacks.notify(this);
|
||||
|
||||
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user