Added CameraNode.cpp and CameraView.cpp

This commit is contained in:
Robert Osfield
2005-11-03 09:03:46 +00:00
parent 5dee96c14f
commit 4c13328d98
2 changed files with 146 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
#include <osg/CameraNode>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#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<CameraNode&>(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<const CameraNode&>(obj);
writeMatrix(camera.getProjectionMatrix(),fw,"ProjectionMatrix");
writeMatrix(camera.getViewMatrix(),fw,"ViewMatrix");
return true;
}

View File

@@ -0,0 +1,71 @@
#include "osg/CameraView"
#include <osg/io_utils>
#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<CameraView&>(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<const CameraView&>(obj);
fw.indent()<<"position "<<cameraview.getPosition()<<std::endl;
fw.indent()<<"attitude "<<cameraview.getAttitude()<<std::endl;
return true;
}