From 4c13328d98ede6c2bab906f2f891c84ae1ee7b0f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 3 Nov 2005 09:03:46 +0000 Subject: [PATCH] Added CameraNode.cpp and CameraView.cpp --- src/osgPlugins/osg/CameraNode.cpp | 75 +++++++++++++++++++++++++++++++ src/osgPlugins/osg/CameraView.cpp | 71 +++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 src/osgPlugins/osg/CameraNode.cpp create mode 100644 src/osgPlugins/osg/CameraView.cpp diff --git a/src/osgPlugins/osg/CameraNode.cpp b/src/osgPlugins/osg/CameraNode.cpp new file mode 100644 index 000000000..a2873428b --- /dev/null +++ b/src/osgPlugins/osg/CameraNode.cpp @@ -0,0 +1,75 @@ +#include + +#include +#include +#include + +#include "Matrix.h" + +using namespace osg; +using namespace osgDB; + +// forward declare functions to use later. +bool CameraNode_readLocalData(Object& obj, Input& fr); +bool CameraNode_writeLocalData(const Object& obj, Output& fw); + +// register the read and write functions with the osgDB::Registry. +RegisterDotOsgWrapperProxy g_CameraNodeProxy +( + new osg::CameraNode, + "CameraNode", + "Object Node Transform CameraNode Group", + &CameraNode_readLocalData, + &CameraNode_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool CameraNode_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + CameraNode& camera = static_cast(obj); + + if (fr[0].matchWord("Type")) + { + if (fr[1].matchWord("DYNAMIC")) + { + camera.setDataVariance(osg::Object::DYNAMIC); + fr +=2 ; + iteratorAdvanced = true; + } + else if (fr[1].matchWord("STATIC")) + { + camera.setDataVariance(osg::Object::STATIC); + fr +=2 ; + iteratorAdvanced = true; + } + + } + + Matrix matrix; + if (readMatrix(matrix,fr,"ProjectionMatrix")) + { + camera.setProjectionMatrix(matrix); + iteratorAdvanced = true; + } + + if (readMatrix(matrix,fr,"ViewMatrix")) + { + camera.setViewMatrix(matrix); + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + + +bool CameraNode_writeLocalData(const Object& obj, Output& fw) +{ + const CameraNode& camera = static_cast(obj); + + writeMatrix(camera.getProjectionMatrix(),fw,"ProjectionMatrix"); + writeMatrix(camera.getViewMatrix(),fw,"ViewMatrix"); + + return true; +} diff --git a/src/osgPlugins/osg/CameraView.cpp b/src/osgPlugins/osg/CameraView.cpp new file mode 100644 index 000000000..0443abc69 --- /dev/null +++ b/src/osgPlugins/osg/CameraView.cpp @@ -0,0 +1,71 @@ +#include "osg/CameraView" +#include + +#include "osgDB/Registry" +#include "osgDB/Input" +#include "osgDB/Output" + +using namespace osg; +using namespace osgDB; + +// forward declare functions to use later. +bool CameraView_readLocalData(Object& obj, Input& fr); +bool CameraView_writeLocalData(const Object& obj, Output& fw); + +// register the read and write functions with the osgDB::Registry. +RegisterDotOsgWrapperProxy g_CameraViewProxy +( + new osg::CameraView, + "CameraView", + "Object Node Transform CameraView Group", + &CameraView_readLocalData, + &CameraView_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool CameraView_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + CameraView& cameraview = static_cast(obj); + + if (fr.matchSequence("position %f %f %f")) + { + osg::Vec3d pos; + fr[1].getFloat(pos[0]); + fr[2].getFloat(pos[1]); + fr[3].getFloat(pos[2]); + + cameraview.setPosition(pos); + + fr += 4; + iteratorAdvanced = true; + } + + if (fr.matchSequence("attitude %f %f %f %f")) + { + osg::Quat att; + fr[1].getFloat(att[0]); + fr[2].getFloat(att[1]); + fr[3].getFloat(att[2]); + fr[4].getFloat(att[3]); + + cameraview.setAttitude(att); + + fr += 5; + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + + +bool CameraView_writeLocalData(const Object& obj, Output& fw) +{ + const CameraView& cameraview = static_cast(obj); + + fw.indent()<<"position "<