diff --git a/examples/osgdem/osgdem.cpp b/examples/osgdem/osgdem.cpp index fd9f45385..9aa012fd7 100644 --- a/examples/osgdem/osgdem.cpp +++ b/examples/osgdem/osgdem.cpp @@ -715,8 +715,8 @@ bool createWorld(const std::string& inputFile, const std::string& baseName, cons bool doBumpMapping = true; - int bumpMapSizeWidth = 4097; - int bumpMapSizeHeight = 4097; + int bumpMapSizeWidth = 1024; + int bumpMapSizeHeight = 1024; // int bumpMapSizeWidth = 512; // int bumpMapSizeHeight = 512; diff --git a/examples/slideshow3D/ReaderWriterXML.cpp b/examples/slideshow3D/ReaderWriterXML.cpp index ff0c95fde..619e3034c 100644 --- a/examples/slideshow3D/ReaderWriterXML.cpp +++ b/examples/slideshow3D/ReaderWriterXML.cpp @@ -488,12 +488,12 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSS3D::readNode(const std::string& fi else constructor.setPresentationName(""); xmlFree(key); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"ratio"))) + /*else if ((!xmlStrcmp(cur->name, (const xmlChar *)"ratio"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (key) constructor.setPresentationAspectRatio((const char*)key); xmlFree(key); - } + }*/ else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bgcolor"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); diff --git a/examples/slideshow3D/SlideShowConstructor.cpp b/examples/slideshow3D/SlideShowConstructor.cpp index de16d4f0f..ea9c625a5 100644 --- a/examples/slideshow3D/SlideShowConstructor.cpp +++ b/examples/slideshow3D/SlideShowConstructor.cpp @@ -18,10 +18,7 @@ SlideShowConstructor::SlideShowConstructor() { _slideDistance = osg::DisplaySettings::instance()->getScreenDistance(); _slideHeight = osg::DisplaySettings::instance()->getScreenHeight(); - _slideWidth = _slideHeight*1280.0f/1024.f; - - _slideOrigin.set(-_slideWidth*0.5f,_slideDistance,-_slideHeight*0.5f); - + _slideWidth = osg::DisplaySettings::instance()->getScreenWidth(); _backgroundColor.set(0.0f,0.0f,0.0f,1.0f); _textColor.set(1.0f,1.0f,1.0f,1.0f); @@ -60,6 +57,8 @@ void SlideShowConstructor::setPresentationAspectRatio(const std::string& str) void SlideShowConstructor::createPresentation() { + _slideOrigin.set(-_slideWidth*0.5f,_slideDistance,-_slideHeight*0.5f); + _titleHeight = _slideHeight*0.06f; _titleWidth = _slideWidth*0.8f; _titleOrigin = _slideOrigin + osg::Vec3(_titlePositionRatios.x()*_slideWidth,_titlePositionRatios.y()*1.0f,_titlePositionRatios.z()*_slideHeight); @@ -85,6 +84,8 @@ void SlideShowConstructor::createPresentation() hp->center = slideCenter; hp->up.set(0.0f,0.0f,1.0f); + std::cout<<" slideCenter "<setUserData(new Duration(_presentationDuration)); diff --git a/examples/slideshow3D/slideshow3D.cpp b/examples/slideshow3D/slideshow3D.cpp index 9560d4692..be2e631f5 100644 --- a/examples/slideshow3D/slideshow3D.cpp +++ b/examples/slideshow3D/slideshow3D.cpp @@ -87,7 +87,8 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("-a","Turn auto stepping on by default"); - arguments.getApplicationUsage()->addCommandLineOption("-d ","Time delay in seconds between layers/slides"); + arguments.getApplicationUsage()->addCommandLineOption("-d ","Time duration in seconds between layers/slides"); + arguments.getApplicationUsage()->addCommandLineOption("-s ","width, height, distance and of the screen away from the viewer"); // construct the viewer. @@ -112,6 +113,9 @@ int main( int argc, char **argv ) bool autoSteppingActive = false; while (arguments.read("-a")) autoSteppingActive = true; + + + // register the slide event handler - which moves the presentation from slide to slide, layer to layer. SlideEventHandler* seh = new SlideEventHandler; @@ -124,6 +128,17 @@ int main( int argc, char **argv ) PointsEventHandler* peh = new PointsEventHandler; viewer.getEventHandlerList().push_front(peh); + float width, height, distance; + bool sizesSpecified = false; + while (arguments.read("-s", width, height, distance)) + { + sizesSpecified = true; + + osg::DisplaySettings::instance()->setScreenDistance(distance); + osg::DisplaySettings::instance()->setScreenHeight(height); + osg::DisplaySettings::instance()->setScreenWidth(width); + } + // get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(*arguments.getApplicationUsage()); @@ -135,7 +150,7 @@ int main( int argc, char **argv ) } // any option left unread are converted into errors to write out later. - arguments.reportRemainingOptionsAsUnrecognized(); + //arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occured when parsing the program aguments. if (arguments.errors()) @@ -179,6 +194,14 @@ int main( int argc, char **argv ) // create the windows and run the threads. viewer.realize(); + if (sizesSpecified) + { + double vfov = osg::RadiansToDegrees(atan2(height/2.0,distance)*2.0); + double hfov = osg::RadiansToDegrees(atan2(width/2.0,distance)*2.0); + + viewer.setLensPerspective( hfov, vfov, 0.1, 1000.0); + } + // set all the sceneview's up so that their left and right add cull masks are set up. for(osgProducer::OsgCameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin(); itr!=viewer.getSceneHandlerList().end(); diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 348a486a2..92f4a8a6c 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -97,9 +97,6 @@ class SG_EXPORT DisplaySettings : public osg::Referenced void setEyeSeparation(float eyeSeparation) { _eyeSeparation = eyeSeparation; } float getEyeSeparation() const { return _eyeSeparation; } - void setScreenDistance(float distance) { _screenDistance = distance; } - float getScreenDistance() const { return _screenDistance; } - enum SplitStereoHorizontalEyeMapping { LEFT_EYE_LEFT_VIEWPORT, @@ -128,9 +125,16 @@ class SG_EXPORT DisplaySettings : public osg::Referenced bool getSplitStereoAutoAjustAspectRatio() const { return _splitStereoAutoAdjustAspectRatio; } + 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 setDoubleBuffer(bool flag) { _doubleBuffer = flag; } bool getDoubleBuffer() const { return _doubleBuffer; } @@ -168,8 +172,9 @@ class SG_EXPORT DisplaySettings : public osg::Referenced bool _stereo; StereoMode _stereoMode; float _eyeSeparation; - float _screenDistance; + float _screenWidth; float _screenHeight; + float _screenDistance; SplitStereoHorizontalEyeMapping _splitStereoHorizontalEyeMapping; int _splitStereoHorizontalSeparation; diff --git a/include/osgProducer/Viewer b/include/osgProducer/Viewer index 5bf7eafd0..53278813f 100644 --- a/include/osgProducer/Viewer +++ b/include/osgProducer/Viewer @@ -150,8 +150,14 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction const osg::AnimationPath* getAnimationPath() const { return _animationPath.get(); } + const double* getPosition() const { return _position; } + double getSpeed() const { return _speed; } + osg::Quat getOrientation() const { return _orientation; } + + /** Get the keyboard and mouse usage of this viewer.*/ virtual void getUsage(osg::ApplicationUsage& usage) const; + protected : @@ -166,11 +172,15 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction EventHandlerList _eventHandlerList; osg::ref_ptr _keyswitchManipulator; - osg::ref_ptr _updateVisitor; + osg::ref_ptr _updateVisitor; bool _recordingAnimationPath; osg::ref_ptr _animationPath; + // record the current position and orientation of the view. + double _position[3]; + osg::Quat _orientation; + double _speed; }; } diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 4c993c1c0..3108707e4 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -48,8 +48,9 @@ void DisplaySettings::copy(const DisplaySettings& vs) _displayType = vs._displayType; _stereoMode = vs._stereoMode; _eyeSeparation = vs._eyeSeparation; - _screenDistance = vs._screenDistance; + _screenWidth = vs._screenWidth; _screenHeight = vs._screenHeight; + _screenDistance = vs._screenDistance; _splitStereoHorizontalEyeMapping = vs._splitStereoHorizontalEyeMapping; _splitStereoHorizontalSeparation = vs._splitStereoHorizontalSeparation; @@ -89,8 +90,9 @@ void DisplaySettings::setDefaults() _stereo = false; _stereoMode = ANAGLYPHIC; _eyeSeparation = 0.05f; - _screenDistance = 0.5f; + _screenWidth = 0.325f; _screenHeight = 0.26f; + _screenDistance = 0.5f; _splitStereoHorizontalEyeMapping = LEFT_EYE_LEFT_VIEWPORT; _splitStereoHorizontalSeparation = 0; @@ -200,9 +202,9 @@ void DisplaySettings::readEnvironmentalVariables() _eyeSeparation = atof(ptr); } - if( (ptr = getenv("OSG_SCREEN_DISTANCE")) != 0) + if( (ptr = getenv("OSG_SCREEN_WIDTH")) != 0) { - _screenDistance = atof(ptr); + _screenWidth = atof(ptr); } if( (ptr = getenv("OSG_SCREEN_HEIGHT")) != 0) @@ -210,6 +212,11 @@ void DisplaySettings::readEnvironmentalVariables() _screenHeight = atof(ptr); } + if( (ptr = getenv("OSG_SCREEN_DISTANCE")) != 0) + { + _screenDistance = atof(ptr); + } + if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING")) != 0) { if (strcmp(ptr,"LEFT_EYE_LEFT_VIEWPORT")==0) diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 32938ea3b..00080561d 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -136,6 +136,10 @@ Viewer::Viewer(): _done(false), _recordingAnimationPath(false) { + _position[0] = 0.0; + _position[1] = 0.0; + _position[2] = 0.0; + _speed = 0.0; } Viewer::Viewer(Producer::CameraConfig *cfg): @@ -143,6 +147,10 @@ Viewer::Viewer(Producer::CameraConfig *cfg): _done(false), _recordingAnimationPath(false) { + _position[0] = 0.0; + _position[1] = 0.0; + _position[2] = 0.0; + _speed = 0.0; } Viewer::Viewer(const std::string& configFile): @@ -150,6 +158,10 @@ Viewer::Viewer(const std::string& configFile): _done(false), _recordingAnimationPath(false) { + _position[0] = 0.0; + _position[1] = 0.0; + _position[2] = 0.0; + _speed = 0.0; } Viewer::Viewer(osg::ArgumentParser& arguments): @@ -157,6 +169,11 @@ Viewer::Viewer(osg::ArgumentParser& arguments): _done(false), _recordingAnimationPath(false) { + _position[0] = 0.0; + _position[1] = 0.0; + _position[2] = 0.0; + _speed = 0.0; + // report the usage options. if (arguments.getApplicationUsage()) { @@ -477,14 +494,38 @@ void Viewer::update() void Viewer::frame() { + // record the position of the view point. + osg::Matrixd matrix; + matrix.invert(getViewMatrix()); + matrix.get(_orientation); + double newPosition[3]; + newPosition[0] = matrix(3,0); + newPosition[1] = matrix(3,1); + newPosition[2] = matrix(3,2); + + _speed = sqrtf(osg::square(newPosition[0]-_position[0])+osg::square(newPosition[1]-_position[1])+osg::square(newPosition[2]-_position[2])); + _position[0] = newPosition[0]; + _position[1] = newPosition[1]; + _position[2] = newPosition[2]; + +#if 0 + osg::Quat::value_type angle; + osg::Vec3 axis; + + osg::Quat roll; + roll.makeRotate(-osg::PI/2.0f,1,0,0); + + _orientation = roll*_orientation; + + _orientation.getRotate(angle,axis); + + std::cout<<"_position "<<_position[0]<<", "<<_position[1]<<", "<<_position[2]<<" speed "<<_speed<<" angle "<insert(_frameStamp->getReferenceTime(),osg::AnimationPath::ControlPoint(matrix.getTrans(),quat)); + getAnimationPath()->insert(_frameStamp->getReferenceTime(),osg::AnimationPath::ControlPoint(osg::Vec3(_position[0],_position[1],_position[2]),_orientation)); } OsgCameraGroup::frame(); diff --git a/src/osgProducer/ViewerEventHandler.cpp b/src/osgProducer/ViewerEventHandler.cpp index cbdbdf433..5a9a132bb 100644 --- a/src/osgProducer/ViewerEventHandler.cpp +++ b/src/osgProducer/ViewerEventHandler.cpp @@ -58,7 +58,8 @@ public: _veh(veh), _cameraNumber(cameraNumber), _helpInitialized(false), - _statsInitialized(false) + _statsInitialized(false), + _infoInitialized(false) { _fs.resize(10); _index = 0; @@ -120,7 +121,7 @@ protected: typedef std::vector CameraTimes; - bool _statsInitialized; + bool _statsInitialized; osg::ref_ptr _frameRateLabelText; osg::ref_ptr _frameRateCounterText; TextList _statsLabelList; @@ -130,6 +131,15 @@ protected: CameraTimes _drawTimes; TextList _drawTimeText; + // info related methods and data. + void displayInfo(); + void createInfoText(); + + bool _infoInitialized; + TextList _infoLabelList; + osg::ref_ptr _positionText; + osg::ref_ptr _orientationText; + osg::ref_ptr _speedText; std::vector _fs; unsigned int _index; @@ -168,6 +178,11 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::operator()( const Producer::C displayHelp(); } + if (_veh->getDisplayHelp()) + { + displayInfo(); + } + state.popStateSet(); //state.apply(); @@ -677,6 +692,14 @@ void ViewerEventHandler::StatsAndHelpDrawCallback::createStatsText() } +void ViewerEventHandler::StatsAndHelpDrawCallback::displayInfo() +{ +} + +void ViewerEventHandler::StatsAndHelpDrawCallback::createInfoText() +{ +} + ViewerEventHandler::ViewerEventHandler(OsgCameraGroup* cg): @@ -824,7 +847,7 @@ bool ViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio // have already been recording so switch of recording. viewer->setRecordingAnimationPath(false); - osg::notify(osg::NOTICE) << "To finished recording camera animation, press 'Z' to reply."<< std::endl; + osg::notify(osg::NOTICE) << "finished recording camera animation, press 'Z' to replay."<< std::endl; if (viewer->getAnimationPath()) {