From Roland Smeenk, "Attached you will find an improved Collada plugin to properly support camera's.

A Collada camera will be added to the scenegraph as osg::CameraView. This allows the user to create a set of predefined camera viewpoints. I also added a new MatrixManipulator to osgGA called CameraViewSwitchManipulator and added usage of this to the osgviewer example. This manipulator allows switching between the predefined camera viewpoints. The current design limition I ran into is that a MatrixManipulator only manipulates the ViewMatrix, but for this particular  manipulator I also want to update the projectionMatrix of the camera when switching to a new viewpoint. This is not implemented because I don't know what would be the best way to design it. Any ideas?
 
Furthermore Collada also supports orthographic camera's, where an osg::CameraView only supports a perspective camera. Would it be useful to create a CameraView with customizable optics for this?"
This commit is contained in:
Robert Osfield
2009-01-05 16:53:29 +00:00
parent 1a600c1178
commit 85fffc2e76
6 changed files with 330 additions and 16 deletions

View File

@@ -0,0 +1,111 @@
#include <osgGA/CameraViewSwitchManipulator>
#include <osg/Quat>
#include <osg/Notify>
#include <osg/BoundsChecking>
using namespace osg;
using namespace osgGA;
class CollectCameraViewsNodeVisitor : public osg::NodeVisitor
{
public:
CollectCameraViewsNodeVisitor(CameraViewSwitchManipulator::CameraViewList* cameraViews):
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_cameraViews(cameraViews)
{}
virtual void apply(CameraView& node)
{
_cameraViews->push_back(&node);
}
CameraViewSwitchManipulator::CameraViewList* _cameraViews;
};
void CameraViewSwitchManipulator::setNode(osg::Node* node)
{
_node = node;
_cameraViews.clear();
CollectCameraViewsNodeVisitor visitor(&_cameraViews);
_node->accept(visitor);
}
void CameraViewSwitchManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("CameraViewSwitcher: [","Decrease current camera number");
usage.addKeyboardMouseBinding("CameraViewSwitcher: ]","Increase current camera number");
}
bool CameraViewSwitchManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if (ea.getHandled()) return false;
switch(ea.getEventType())
{
case(GUIEventAdapter::KEYDOWN):
if (ea.getKey()=='[')
{
if (_currentView == 0)
_currentView = _cameraViews.size()-1;
else
_currentView--;
return true;
}
else if (ea.getKey()==']')
{
_currentView++;
if (_currentView >= _cameraViews.size())
_currentView = 0;
return true;
}
return false;
default:
return false;
}
return false;
}
osg::Matrixd CameraViewSwitchManipulator::getMatrix() const
{
osg::Matrix mat;
if (_currentView < _cameraViews.size())
{
NodePathList parentNodePaths = _cameraViews[_currentView]->getParentalNodePaths();
if (!parentNodePaths.empty())
{
mat = osg::computeLocalToWorld(parentNodePaths[0]);
// TODO take into account the position and attitude of the CameraView
}
else
{
osg::notify(osg::NOTICE)<<"CameraViewSwitchManipulator::getMatrix(): Unable to calculate matrix due to empty parental path."<<std::endl;
}
}
return mat;
}
osg::Matrixd CameraViewSwitchManipulator::getInverseMatrix() const
{
osg::Matrix mat;
if (_currentView < _cameraViews.size())
{
NodePathList parentNodePaths = _cameraViews[_currentView]->getParentalNodePaths();
if (!parentNodePaths.empty())
{
mat = osg::computeWorldToLocal(parentNodePaths[0]);
// TODO take into account the position and attitude of the CameraView
}
else
{
osg::notify(osg::NOTICE)<<"CameraViewSwitchManipulator::getInverseMatrix(): Unable to calculate matrix due to empty parental path."<<std::endl;
}
}
return mat;
}