From ce0f928f6f17d2ea5b0869a40e2fce26c0b1976c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 5 Dec 2012 11:41:27 +0000 Subject: [PATCH] Added --screen-distance , --screen-height and --screen-width command line support and associated settings to the configuration file. --- examples/osgframerenderer/CaptureSettings.cpp | 11 +++++ examples/osgframerenderer/CaptureSettings.h | 16 +++++- .../osgframerenderer/osgframerenderer.cpp | 49 ++++++++++++++----- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/examples/osgframerenderer/CaptureSettings.cpp b/examples/osgframerenderer/CaptureSettings.cpp index daa9241db..b214d15de 100644 --- a/examples/osgframerenderer/CaptureSettings.cpp +++ b/examples/osgframerenderer/CaptureSettings.cpp @@ -7,6 +7,9 @@ CaptureSettings::CaptureSettings(): _offscreen(false), _width(1024), _height(512), + _screenWidth(0.0), + _screenHeight(0.0), + _screenDistance(0.0), _samples(0), _sampleBuffers(0), _frameRate(60.0), @@ -25,6 +28,9 @@ CaptureSettings::CaptureSettings(const CaptureSettings& cs, const osg::CopyOp& c _offscreen(cs._offscreen), _width(cs._width), _height(cs._height), + _screenWidth(cs._screenWidth), + _screenHeight(cs._screenHeight), + _screenDistance(cs._screenDistance), _samples(cs._samples), _sampleBuffers(cs._sampleBuffers), _frameRate(cs._frameRate), @@ -155,6 +161,11 @@ REGISTER_OBJECT_WRAPPER( gsc_CaptureSettings, ADD_UINT_SERIALIZER( Width, 1024 ); ADD_UINT_SERIALIZER( Height, 512 ); + + ADD_FLOAT_SERIALIZER( ScreenWidth, 0.0 ); + ADD_FLOAT_SERIALIZER( ScreenHeight, 0.0 ); + ADD_FLOAT_SERIALIZER( ScreenDistance, 0.0 ); + ADD_UINT_SERIALIZER( Samples, 0 ); ADD_UINT_SERIALIZER( SampleBuffers, 0 ); diff --git a/examples/osgframerenderer/CaptureSettings.h b/examples/osgframerenderer/CaptureSettings.h index 1ba3ca8a5..9ed3398b3 100644 --- a/examples/osgframerenderer/CaptureSettings.h +++ b/examples/osgframerenderer/CaptureSettings.h @@ -47,7 +47,16 @@ public: void setHeight(unsigned int height) { _height = height; } unsigned int getHeight() const { return _height; } - + + void setScreenWidth(float width) { _screenWidth = width; } + float getScreenWidth() const { return _screenWidth; } + + void setScreenHeight(float height) { _screenHeight = height; } + float getScreenHeight() const { return _screenHeight; } + + void setScreenDistance(float distance) { _screenDistance = distance; } + float getScreenDistance() const { return _screenDistance; } + void setSamples(unsigned int s) { _samples = s; } unsigned int getSamples() const { return _samples; } @@ -103,6 +112,11 @@ protected: unsigned int _width; unsigned int _height; + + float _screenWidth; + float _screenHeight; + float _screenDistance; + unsigned int _samples; unsigned int _sampleBuffers; diff --git a/examples/osgframerenderer/osgframerenderer.cpp b/examples/osgframerenderer/osgframerenderer.cpp index bfea73216..f710f724c 100644 --- a/examples/osgframerenderer/osgframerenderer.cpp +++ b/examples/osgframerenderer/osgframerenderer.cpp @@ -73,8 +73,11 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("-p ","Use specificied camera path file to control camera position."); arguments.getApplicationUsage()->addCommandLineOption("--offscreen","Use an pbuffer to render the images offscreen."); arguments.getApplicationUsage()->addCommandLineOption("--screen","Use an window to render the images."); - arguments.getApplicationUsage()->addCommandLineOption("--width ","Window/output image width"); - arguments.getApplicationUsage()->addCommandLineOption("--height ","Window/output image height"); + arguments.getApplicationUsage()->addCommandLineOption("--width ","Window/output image width."); + arguments.getApplicationUsage()->addCommandLineOption("--height ","Window/output image height."); + arguments.getApplicationUsage()->addCommandLineOption("--screen-distance ","Set the distance of the viewer from the physical screen."); + arguments.getApplicationUsage()->addCommandLineOption("--screen-width ","Set the width of the physical screen."); + arguments.getApplicationUsage()->addCommandLineOption("--screen-height ","Set the height of the physical screen."); arguments.getApplicationUsage()->addCommandLineOption("--ms ","Number of multi-samples to use when rendering, an enable a single sample buffer."); arguments.getApplicationUsage()->addCommandLineOption("--samples ","Number of multi-samples to use when rendering."); arguments.getApplicationUsage()->addCommandLineOption("--sampleBuffers ","Number of sample buffers to use when rendering."); @@ -157,26 +160,37 @@ int main( int argc, char **argv ) { osg::ref_ptr cp = fc->getPropertyOfType(); + bool newCameraProperty = false; + bool valueSet = false; + if (!cp) { + newCameraProperty = true; cp = new gsc::CameraProperty; osg::ref_ptr node = fc->getInputFileName().empty() ? 0 : osgDB::readNodeFile(fc->getInputFileName()); - if (node.valid()) cp->setToModel(node.get()); + if (node.valid()) + { + cp->setToModel(node.get()); + valueSet = true; + } - fc->addUpdateProperty(cp.get()); } osg::Vec3d vec; - while (arguments.read("--center",vec.x(), vec.y(), vec.z())) { cp->setCenter(vec); } - while (arguments.read("--eye",vec.x(), vec.y(), vec.z())) { cp->setEyePoint(vec); } - while (arguments.read("--up",vec.x(), vec.y(), vec.z())) { cp->setUpVector(vec); } - while (arguments.read("--rotation-center",vec.x(), vec.y(), vec.z())) { cp->setRotationCenter(vec); } - while (arguments.read("--rotation-axis",vec.x(), vec.y(), vec.z())) { cp->setRotationAxis(vec); } + while (arguments.read("--center",vec.x(), vec.y(), vec.z())) { cp->setCenter(vec); valueSet = true; } + while (arguments.read("--eye",vec.x(), vec.y(), vec.z())) { cp->setEyePoint(vec); valueSet = true; } + while (arguments.read("--up",vec.x(), vec.y(), vec.z())) { cp->setUpVector(vec); valueSet = true; } + while (arguments.read("--rotation-center",vec.x(), vec.y(), vec.z())) { cp->setRotationCenter(vec); valueSet = true; } + while (arguments.read("--rotation-axis",vec.x(), vec.y(), vec.z())) { cp->setRotationAxis(vec); valueSet = true; } double speed; - while (arguments.read("--rotation-speed",speed)) { cp->setRotationSpeed(speed); } - + while (arguments.read("--rotation-speed",speed)) { cp->setRotationSpeed(speed); valueSet = true; } + + if (newCameraProperty && valueSet) + { + fc->addUpdateProperty(cp.get()); + } } std::string stereoMode; @@ -196,6 +210,14 @@ int main( int argc, char **argv ) unsigned int height = 512; if (arguments.read("--height",height)) fc->setHeight(height); + + float value; + if (arguments.read("--screen-width",value)) fc->setScreenWidth(value); + if (arguments.read("--screen-height",value)) fc->setScreenHeight(value); + if (arguments.read("--screen-distance",value)) fc->setScreenDistance(value); + + + unsigned int samples = 0; if (arguments.read("--samples",samples)) fc->setSamples(samples); @@ -324,6 +346,11 @@ int main( int argc, char **argv ) ds->setStereoMode(stereoMode); ds->setStereo(fc->getStereoMode()!=gsc::CaptureSettings::OFF); + if (fc->getScreenWidth()!=0.0) ds->setScreenWidth(fc->getScreenWidth()); + if (fc->getScreenHeight()!=0.0) ds->setScreenHeight(fc->getScreenHeight()); + if (fc->getScreenDistance()!=0.0) ds->setScreenDistance(fc->getScreenDistance()); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds.get()); traits->readDISPLAY();