Added initial CameraNode and CameraView stups for the .ive loader

This commit is contained in:
Robert Osfield
2005-11-03 10:16:38 +00:00
parent eb28f9f587
commit 6562aa4f5f
10 changed files with 296 additions and 110 deletions

View File

@@ -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

View File

@@ -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 <filename>","Load an image and render it on a quad");
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","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<osg::Node> 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 = "<<osg::Timer::instance()->delta_s(start_tick,end_tick)<<std::endl;
// optimize the scene graph, remove rendundent nodes and state etc.
osgUtil::Optimizer optimizer;
optimizer.optimize(loadedModel.get());
// pass the loaded scene graph to the viewer.
viewer.setSceneData(loadedModel.get());
// copied from osgtessealte.cpp
// add event handler for keyboard 'n' to retriangulate
viewer.getEventHandlerList().push_front(new KeyboardEventHandler(loadedModel.get(), viewer));
// create the windows and run the threads.
viewer.realize();
while( !viewer.done() )
{
// wait for all cull and draw threads to complete.
viewer.sync();
// update the scene by traversing it with the the update visitor which will
// call all node update callbacks and animations.
viewer.update();
// fire off the cull and draw traversals of the scene.
viewer.frame();
}
// wait for all cull and draw threads to complete before exit.
viewer.sync();
return 0;
}
osg::Vec3Array * WallConstraint::getWall(const float height) const
{ // return array of points for a wall height high around the constraint
@@ -1379,3 +1269,113 @@ osg::Geometry * LinearConstraint::makeGeometry(const osg::Vec3Array *points)
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 <filename>","Load an image and render it on a quad");
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","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<osg::Node> 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 = "<<osg::Timer::instance()->delta_s(start_tick,end_tick)<<std::endl;
// optimize the scene graph, remove rendundent nodes and state etc.
osgUtil::Optimizer optimizer;
optimizer.optimize(loadedModel.get());
// pass the loaded scene graph to the viewer.
viewer.setSceneData(loadedModel.get());
// copied from osgtessealte.cpp
// add event handler for keyboard 'n' to retriangulate
viewer.getEventHandlerList().push_front(new KeyboardEventHandler(loadedModel.get(), viewer));
// create the windows and run the threads.
viewer.realize();
while( !viewer.done() )
{
// wait for all cull and draw threads to complete.
viewer.sync();
// update the scene by traversing it with the the update visitor which will
// call all node update callbacks and animations.
viewer.update();
// fire off the cull and draw traversals of the scene.
viewer.frame();
}
// wait for all cull and draw threads to complete before exit.
viewer.sync();
return 0;
}

View File

@@ -0,0 +1,60 @@
/**********************************************************************
*
* FILE: CameraNode.cpp
*
* DESCRIPTION: Read/Write osg::CameraNode in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 17.3.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "CameraNode.h"
#include "Group.h"
using namespace ive;
void CameraNode::write(DataOutputStream* out){
// Write CameraNode's identification.
out->writeInt(IVECAMERANODE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(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<osg::Group*>(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");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_CAMERANODE
#define IVE_CAMERANODE 1
#include <osg/CameraNode>
#include "ReadWrite.h"
namespace ive{
class CameraNode : public osg::CameraNode, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -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<osg::Transform*>(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<osg::Transform*>(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.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_CAMERAVIEW
#define IVE_CAMERAVIEW 1
#include <osg/CameraView>
#include "ReadWrite.h"
namespace ive{
class CameraView : public osg::CameraView, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -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);

View File

@@ -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<const osg::MatrixTransform*>(node)){
((ive::MatrixTransform*)(node))->write(this);
}
else if(dynamic_cast<const osg::CameraNode*>(node)){
((ive::CameraNode*)(node))->write(this);
}
else if(dynamic_cast<const osg::CameraView*>(node)){
((ive::CameraView*)(node))->write(this);
}
else if(dynamic_cast<const osg::PositionAttitudeTransform*>(node)){
((ive::PositionAttitudeTransform*)(node))->write(this);
}

View File

@@ -13,6 +13,8 @@ CXXFILES =\
ClipNode.cpp\
ClipPlane.cpp\
ClusterCullingCallback.cpp\
CameraNode.cpp\
CameraView.cpp\
ConeSector.cpp\
ConvexPlanarOccluder.cpp\
ConvexPlanarPolygon.cpp\

View File

@@ -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