From 9d9d6c5a121e5965cf07fdeb0b71500e01c04e4f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 3 Nov 2005 12:25:25 +0000 Subject: [PATCH] Completed osg::CameraView support in .osg and .ive formats. --- src/osgPlugins/ive/CameraView.cpp | 91 +++++++++++++++++-------------- src/osgPlugins/osg/CameraView.cpp | 46 +++++++++++++++- 2 files changed, 96 insertions(+), 41 deletions(-) diff --git a/src/osgPlugins/ive/CameraView.cpp b/src/osgPlugins/ive/CameraView.cpp index a675c11ae..60eac4958 100644 --- a/src/osgPlugins/ive/CameraView.cpp +++ b/src/osgPlugins/ive/CameraView.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: CameraView.cpp + * FILE: CameraView.cpp * - * DESCRIPTION: Read/Write osg::CameraView in binary format to disk. + * DESCRIPTION: Read/Write osg::CameraView in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 25.3.2003 + * HISTORY: Created 25.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -18,41 +18,52 @@ using namespace ive; -void CameraView::write(DataOutputStream* out){ - // Write CameraView's identification. - out->writeInt(IVECAMERAVIEW); - // If the osg class is inherited by any other class we should also write this to file. - osg::Transform* trans = dynamic_cast(this); - if(trans){ - ((ive::Transform*)(trans))->write(out); - } - else - throw Exception("CameraView::write(): Could not cast this osg::CameraView to an osg::Transform."); - // Write CameraView's properties. - - out->writeVec3(getPosition()); - out->writeQuat(getAttitude()); +void CameraView::write(DataOutputStream* out) +{ + // Write CameraView's identification. + out->writeInt(IVECAMERAVIEW); + // If the osg class is inherited by any other class we should also write this to file. + osg::Transform* trans = dynamic_cast(this); + if(trans) + { + ((ive::Transform*)(trans))->write(out); + } + else + throw Exception("CameraView::write(): Could not cast this osg::CameraView to an osg::Transform."); + + // Write CameraView's properties. + out->writeVec3(getPosition()); + out->writeQuat(getAttitude()); + out->writeDouble(getFieldOfView()); + out->writeInt(getFieldOfViewMode()); + out->writeDouble(getFocalLength()); } void CameraView::read(DataInputStream* in){ - // Peek on CameraView's identification. - int id = in->peekInt(); - if(id == IVECAMERAVIEW){ - // Read CameraView's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Transform* trans = dynamic_cast(this); - if(trans){ - ((ive::Transform*)(trans))->read(in); - } - else - throw Exception("CameraView::read(): Could not cast this osg::CameraView to an osg::Transform."); - // Read CameraView's properties - setPosition(in->readVec3()); - setAttitude(in->readQuat()); - - } - else{ - throw Exception("CameraView::read(): Expected CameraView identification."); - } + // Peek on CameraView's identification. + int id = in->peekInt(); + if(id == IVECAMERAVIEW) + { + // Read CameraView's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Transform* trans = dynamic_cast(this); + if(trans) + { + ((ive::Transform*)(trans))->read(in); + } + else + throw Exception("CameraView::read(): Could not cast this osg::CameraView to an osg::Transform."); + + // Read CameraView's properties + setPosition(in->readVec3()); + setAttitude(in->readQuat()); + setFieldOfView(in->readDouble()); + setFieldOfViewMode((FieldOfViewMode)in->readInt()); + setFocalLength(in->readDouble()); + } + else + { + throw Exception("CameraView::read(): Expected CameraView identification."); + } } diff --git a/src/osgPlugins/osg/CameraView.cpp b/src/osgPlugins/osg/CameraView.cpp index 0443abc69..cf3c1b4e3 100644 --- a/src/osgPlugins/osg/CameraView.cpp +++ b/src/osgPlugins/osg/CameraView.cpp @@ -1,5 +1,6 @@ -#include "osg/CameraView" +#include #include +#include #include "osgDB/Registry" #include "osgDB/Input" @@ -56,6 +57,38 @@ bool CameraView_readLocalData(Object& obj, Input& fr) iteratorAdvanced = true; } + if (fr.matchSequence("fieldOfView %f")) + { + double fov; + fr[1].getFloat(fov); + cameraview.setFieldOfView(fov); + + fr += 2; + iteratorAdvanced = true; + } + + + if (fr.matchSequence("fieldOfViewMode %w")) + { + if (fr[1].matchWord("UNCONSTRAINED")) cameraview.setFieldOfViewMode(osg::CameraView::UNCONSTRAINED); + else if (fr[1].matchWord("HORIZONTAL")) cameraview.setFieldOfViewMode(osg::CameraView::HORIZONTAL); + else if (fr[1].matchWord("VERTICAL")) cameraview.setFieldOfViewMode(osg::CameraView::VERTICAL); + + fr += 2; + iteratorAdvanced = true; + } + + + if (fr.matchSequence("focalLength %f")) + { + double fl; + fr[1].getFloat(fl); + cameraview.setFocalLength(fl); + + fr += 2; + iteratorAdvanced = true; + } + return iteratorAdvanced; } @@ -66,6 +99,17 @@ bool CameraView_writeLocalData(const Object& obj, Output& fw) fw.indent()<<"position "<