From af6af82e56e9c0e0badb403e11fc4ddd875cfeb1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 20 Feb 2006 19:13:11 +0000 Subject: [PATCH] From Nathan Monteleone, addition of AutoTransform support. --- VisualStudio/osgPlugins/ive/ive.dsp | 8 +++ src/osgPlugins/ive/AutoTransform.cpp | 73 +++++++++++++++++++++++++ src/osgPlugins/ive/AutoTransform.h | 15 +++++ src/osgPlugins/ive/DataInputStream.cpp | 5 ++ src/osgPlugins/ive/DataOutputStream.cpp | 4 ++ src/osgPlugins/ive/GNUmakefile | 1 + src/osgPlugins/ive/ReadWrite.h | 1 + 7 files changed, 107 insertions(+) create mode 100644 src/osgPlugins/ive/AutoTransform.cpp create mode 100644 src/osgPlugins/ive/AutoTransform.h diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index a9b17b5c2..54f84fe83 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -108,6 +108,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\AnimationPathCallback.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\AutoTransform.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\AzimElevationSector.cpp # End Source File # Begin Source File @@ -456,6 +460,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\AnimationPathCallback.h # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\AutoTransform.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\AzimElevationSector.h # End Source File # Begin Source File diff --git a/src/osgPlugins/ive/AutoTransform.cpp b/src/osgPlugins/ive/AutoTransform.cpp new file mode 100644 index 000000000..442b9aeec --- /dev/null +++ b/src/osgPlugins/ive/AutoTransform.cpp @@ -0,0 +1,73 @@ +/********************************************************************** + * + * FILE: AutoTransform.cpp + * + * DESCRIPTION: Read/Write osg::AutoTransform in binary format to disk. + * + * CREATED BY: Nathan Monteleone, based on PositionAttitudeTransform.cpp + * + * HISTORY: Created 02.3.2006 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "AutoTransform.h" +#include "Transform.h" + +using namespace ive; + +void AutoTransform::write(DataOutputStream* out){ + // Write AutoTransform's identification. + out->writeInt(IVEAUTOTRANSFORM); + // 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("AutoTransform::write(): Could not cast this osg::AutoTransform to an osg::Transform."); + // Write AutoTransform's properties. + + out->writeVec3(getPosition()); + out->writeVec3(getPivotPoint()); + out->writeFloat(getAutoUpdateEyeMovementTolerance()); + + out->writeInt(getAutoRotateMode()); + + out->writeBool(getAutoScaleToScreen()); + + out->writeQuat(getRotation()); + out->writeVec3(getScale()); +} + +void AutoTransform::read(DataInputStream* in){ + // Peek on AutoTransform's identification. + int id = in->peekInt(); + if(id == IVEAUTOTRANSFORM){ + // Read AutoTransform'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("AutoTransform::read(): Could not cast this osg::AutoTransform to an osg::Transform."); + // Read AutoTransform's properties + + setPosition(in->readVec3()); + setPivotPoint(in->readVec3()); + setAutoUpdateEyeMovementTolerance(in->readFloat()); + + setAutoRotateMode(osg::AutoTransform::AutoRotateMode(in->readInt())); + + setAutoScaleToScreen(in->readBool()); + + setRotation(in->readQuat()); + setScale(in->readVec3()); + } + else{ + throw Exception("AutoTransform::read(): Expected AutoTransform identification."); + } +} diff --git a/src/osgPlugins/ive/AutoTransform.h b/src/osgPlugins/ive/AutoTransform.h new file mode 100644 index 000000000..5fae4df99 --- /dev/null +++ b/src/osgPlugins/ive/AutoTransform.h @@ -0,0 +1,15 @@ +#ifndef IVE_AUTOTRANSFORM +#define IVE_AUTOTRANSFORM 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class AutoTransform : public osg::AutoTransform, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 623afc2e8..a6d2a4e65 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -58,6 +58,7 @@ #include "LOD.h" #include "PagedLOD.h" #include "PositionAttitudeTransform.h" +#include "AutoTransform.h" #include "DOFTransform.h" #include "Transform.h" #include "Switch.h" @@ -1141,6 +1142,10 @@ osg::Node* DataInputStream::readNode() node = new osg::PositionAttitudeTransform(); ((ive::PositionAttitudeTransform*)(node))->read(this); } + else if(nodeTypeID== IVEAUTOTRANSFORM){ + node = new osg::AutoTransform(); + ((ive::AutoTransform*)(node))->read(this); + } else if(nodeTypeID== IVEDOFTRANSFORM){ node = new osgSim::DOFTransform(); ((ive::DOFTransform*)(node))->read(this); diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 22780464d..1f889d057 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -61,6 +61,7 @@ #include "LOD.h" #include "PagedLOD.h" #include "PositionAttitudeTransform.h" +#include "AutoTransform.h" #include "DOFTransform.h" #include "Transform.h" #include "Switch.h" @@ -914,6 +915,9 @@ void DataOutputStream::writeNode(const osg::Node* node) else if(dynamic_cast(node)){ ((ive::PositionAttitudeTransform*)(node))->write(this); } + else if(dynamic_cast(node)){ + ((ive::AutoTransform*)(node))->write(this); + } else if(dynamic_cast(node)){ ((ive::DOFTransform*)(node))->write(this); } diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index 0df118f28..98b8cd7f2 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -7,6 +7,7 @@ CXXFILES =\ AnimationPath.cpp\ AzimElevationSector.cpp\ AzimSector.cpp\ + AutoTransform.cpp\ Billboard.cpp\ BlendFunc.cpp\ BlinkSequence.cpp\ diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index e1d758929..733b08e21 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -36,6 +36,7 @@ namespace ive { #define IVEPROXYNODE 0x00000027 #define IVECAMERANODE 0x00000028 #define IVECAMERAVIEW 0x00000029 +#define IVEAUTOTRANSFORM 0x00000030 // Node callbacks #define IVENODECALLBACK 0x00000050