diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index 1cca5dfea..d2f700b86 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -128,6 +128,14 @@ SOURCE=..\..\..\src\osgPlugins\ive\BlinkSequence.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\CameraNode.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\ive\CameraView.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\ClipPlane.cpp # End Source File # Begin Source File @@ -464,6 +472,14 @@ SOURCE=..\..\..\src\osgPlugins\ive\BlinkSequence.h # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\CameraNode.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\ive\CameraView.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\ClipPlane.h # End Source File # Begin Source File diff --git a/examples/osgdelaunay/osgdelaunay.cpp b/examples/osgdelaunay/osgdelaunay.cpp index 10b27daba..f39dfab39 100644 --- a/examples/osgdelaunay/osgdelaunay.cpp +++ b/examples/osgdelaunay/osgdelaunay.cpp @@ -743,116 +743,6 @@ public: osgProducer::Viewer &viewer; int iview; }; -int main( int argc, char **argv ) -{ - - // use an ArgumentParser object to manage the program arguments. - osg::ArgumentParser arguments(&argc,argv); - - // set up the usage document, in case we need to print out how to use this program. - arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); - arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); - arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); - arguments.getApplicationUsage()->addCommandLineOption("--image ","Load an image and render it on a quad"); - arguments.getApplicationUsage()->addCommandLineOption("--dem ","Load an image/DEM and render it on a HeightField"); - arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line paramters"); - arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available"); - arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); - arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindigs."); - - - // construct the viewer. - osgProducer::Viewer viewer(arguments); - - // set up the value with sensible default event handlers. - viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); - - // get details on keyboard and mouse bindings used by the viewer. - viewer.getUsage(*arguments.getApplicationUsage()); - - // if user request help write it out to cout. - bool helpAll = arguments.read("--help-all"); - unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) | - ((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) | - ((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 ); - if (helpType) - { - arguments.getApplicationUsage()->write(std::cout, helpType); - return 1; - } - - // report any errors if they have occured when parsing the program aguments. - if (arguments.errors()) - { - arguments.writeErrorMessages(std::cout); - return 1; - } - - if (arguments.argc()<1) - { - arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); - return 1; - } - - osg::Timer_t start_tick = osg::Timer::instance()->tick(); - - // create the scene from internal specified terrain/constraints. - osg::ref_ptr loadedModel = makedelaunay(0); - - // if no model has been successfully loaded report failure. - if (!loadedModel) - { - std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; - return 1; - } - - - // any option left unread are converted into errors to write out later. - arguments.reportRemainingOptionsAsUnrecognized(); - - // report any errors if they have occured when parsing the program aguments. - if (arguments.errors()) - { - arguments.writeErrorMessages(std::cout); - } - - osg::Timer_t end_tick = osg::Timer::instance()->tick(); - - std::cout << "Time to load = "<delta_s(start_tick,end_tick)<setApplicationName(arguments.getApplicationName()); + arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("--image ","Load an image and render it on a quad"); + arguments.getApplicationUsage()->addCommandLineOption("--dem ","Load an image/DEM and render it on a HeightField"); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line paramters"); + arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available"); + arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); + arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindigs."); + + + // construct the viewer. + osgProducer::Viewer viewer(arguments); + + // set up the value with sensible default event handlers. + viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); + + // get details on keyboard and mouse bindings used by the viewer. + viewer.getUsage(*arguments.getApplicationUsage()); + + // if user request help write it out to cout. + bool helpAll = arguments.read("--help-all"); + unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) | + ((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) | + ((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 ); + if (helpType) + { + arguments.getApplicationUsage()->write(std::cout, helpType); + return 1; + } + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } + + if (arguments.argc()<1) + { + arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); + return 1; + } + + osg::Timer_t start_tick = osg::Timer::instance()->tick(); + + // create the scene from internal specified terrain/constraints. + osg::ref_ptr loadedModel = makedelaunay(0); + + // if no model has been successfully loaded report failure. + if (!loadedModel) + { + std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; + return 1; + } + + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + } + + osg::Timer_t end_tick = osg::Timer::instance()->tick(); + + std::cout << "Time to load = "<delta_s(start_tick,end_tick)<writeInt(IVECAMERANODE); + + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("CameraNode::write(): Could not cast this osg::CameraNode to an osg::Group."); + + + // Write CameraNode's properties. + out->writeMatrixd(getProjectionMatrix()); + out->writeMatrixd(getViewMatrix()); +} + +void CameraNode::read(DataInputStream* in){ + // Read CameraNode's identification. + int id = in->peekInt(); + if(id == IVECAMERANODE){ + // Code to read CameraNode's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); + } + else + throw Exception("CameraNode::read(): Could not cast this osg::CameraNode to an osg::Group."); + + // Read matrix + setProjectionMatrix(in->readMatrixd()); + setViewMatrix(in->readMatrixd()); + } + else{ + throw Exception("CameraNode::read(): Expected CameraNode identification"); + } +} diff --git a/src/osgPlugins/ive/CameraNode.h b/src/osgPlugins/ive/CameraNode.h new file mode 100644 index 000000000..8b95c55eb --- /dev/null +++ b/src/osgPlugins/ive/CameraNode.h @@ -0,0 +1,15 @@ +#ifndef IVE_CAMERANODE +#define IVE_CAMERANODE 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class CameraNode : public osg::CameraNode, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/CameraView.cpp b/src/osgPlugins/ive/CameraView.cpp new file mode 100644 index 000000000..a675c11ae --- /dev/null +++ b/src/osgPlugins/ive/CameraView.cpp @@ -0,0 +1,58 @@ +/********************************************************************** + * + * FILE: CameraView.cpp + * + * DESCRIPTION: Read/Write osg::CameraView in binary format to disk. + * + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. + * + * HISTORY: Created 25.3.2003 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "CameraView.h" +#include "Transform.h" + +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::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."); + } +} diff --git a/src/osgPlugins/ive/CameraView.h b/src/osgPlugins/ive/CameraView.h new file mode 100644 index 000000000..3e9710bff --- /dev/null +++ b/src/osgPlugins/ive/CameraView.h @@ -0,0 +1,15 @@ +#ifndef IVE_CAMERAVIEW +#define IVE_CAMERAVIEW 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class CameraView : public osg::CameraView, 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 63037ab5a..c1c9c45aa 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -46,6 +46,8 @@ #include "Group.h" #include "MatrixTransform.h" +#include "CameraNode.h" +#include "CameraView.h" #include "Geode.h" #include "LightSource.h" #include "TexGenNode.h" @@ -1084,6 +1086,14 @@ osg::Node* DataInputStream::readNode() node = new osg::MatrixTransform(); ((ive::MatrixTransform*)(node))->read(this); } + else if(nodeTypeID== IVECAMERANODE){ + node = new osg::CameraNode(); + ((ive::CameraNode*)(node))->read(this); + } + else if(nodeTypeID== IVECAMERAVIEW){ + node = new osg::CameraView(); + ((ive::CameraView*)(node))->read(this); + } else if(nodeTypeID== IVEPOSITIONATTITUDETRANSFORM){ node = new osg::PositionAttitudeTransform(); ((ive::PositionAttitudeTransform*)(node))->read(this); diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 79b818e03..c7661e6f5 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -49,6 +49,8 @@ #include "Group.h" #include "MatrixTransform.h" +#include "CameraNode.h" +#include "CameraView.h" #include "Geode.h" #include "LightSource.h" #include "TexGenNode.h" @@ -899,6 +901,12 @@ void DataOutputStream::writeNode(const osg::Node* node) if(dynamic_cast(node)){ ((ive::MatrixTransform*)(node))->write(this); } + else if(dynamic_cast(node)){ + ((ive::CameraNode*)(node))->write(this); + } + else if(dynamic_cast(node)){ + ((ive::CameraView*)(node))->write(this); + } else if(dynamic_cast(node)){ ((ive::PositionAttitudeTransform*)(node))->write(this); } diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index a9e7195c3..70791e14d 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -13,6 +13,8 @@ CXXFILES =\ ClipNode.cpp\ ClipPlane.cpp\ ClusterCullingCallback.cpp\ + CameraNode.cpp\ + CameraView.cpp\ ConeSector.cpp\ ConvexPlanarOccluder.cpp\ ConvexPlanarPolygon.cpp\ diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 75853c246..d410a5930 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -34,6 +34,8 @@ namespace ive { #define IVETEXGENNODE 0x00000025 #define IVECLIPNODE 0x00000026 #define IVEPROXYNODE 0x00000027 +#define IVECAMERANODE 0x00000028 +#define IVECAMERAVIEW 0x00000029 // Node callbacks #define IVENODECALLBACK 0x00000050