Added support to slideshow3D for -s commandline option allow the size of

the display to be specified.

Also implementaited some code for display position and speed info in
osgProducer::Viewer, not fully implemented yet.
This commit is contained in:
Robert Osfield
2003-11-04 16:38:10 +00:00
parent 8ed0f3ea95
commit 54a8ea33ce
9 changed files with 137 additions and 27 deletions

View File

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

View File

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

View File

@@ -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 "<<slideCenter<<std::endl;
if (_presentationDuration!=0.0)
{
_presentationSwitch->setUserData(new Duration(_presentationDuration));

View File

@@ -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 <float>","Time delay in seconds between layers/slides");
arguments.getApplicationUsage()->addCommandLineOption("-d <float>","Time duration in seconds between layers/slides");
arguments.getApplicationUsage()->addCommandLineOption("-s <float> <float> <float>","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();

View File

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

View File

@@ -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<osgGA::KeySwitchMatrixManipulator> _keyswitchManipulator;
osg::ref_ptr<osg::NodeVisitor> _updateVisitor;
osg::ref_ptr<osg::NodeVisitor> _updateVisitor;
bool _recordingAnimationPath;
osg::ref_ptr<osg::AnimationPath> _animationPath;
// record the current position and orientation of the view.
double _position[3];
osg::Quat _orientation;
double _speed;
};
}

View File

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

View File

@@ -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 "<<osg::RadiansToDegrees(angle)<<" axis "<<axis<<std::endl;
#endif
if (getRecordingAnimationPath() && getAnimationPath())
{
osg::Matrixd matrix;
matrix.invert(getViewMatrix());
osg::Quat quat;
matrix.get(quat);
getAnimationPath()->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();

View File

@@ -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<double> CameraTimes;
bool _statsInitialized;
bool _statsInitialized;
osg::ref_ptr<osgText::Text> _frameRateLabelText;
osg::ref_ptr<osgText::Text> _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<osgText::Text> _positionText;
osg::ref_ptr<osgText::Text> _orientationText;
osg::ref_ptr<osgText::Text> _speedText;
std::vector <Producer::CameraGroup::FrameStats> _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())
{