From f7ad937020fb25dc8c579740319620c460aec2ca Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 22 Jul 2003 12:39:40 +0000 Subject: [PATCH] Added XML support and slideshow constructor to slideshow3D example, now renamed from the previous osgslideshow. --- Make/makedirdefs | 4 +- VisualStudio/osgDB/osgDB.dsp | 4 +- examples/osgslideshow/GNUmakefile.inst | 16 -- .../DefaultPresentation.cpp | 0 .../{osgslideshow => slideshow3D}/GNUmakefile | 9 +- examples/slideshow3D/GNUmakefile.inst | 19 ++ examples/slideshow3D/ReaderWriterXML.cpp | 256 +++++++++++++++++ .../SlideEventHandler.cpp | 0 .../SlideEventHandler.h | 0 examples/slideshow3D/SlideShowConstructor.cpp | 262 ++++++++++++++++++ examples/slideshow3D/SlideShowConstructor.h | 86 ++++++ .../slideshow3D.cpp} | 0 12 files changed, 633 insertions(+), 23 deletions(-) delete mode 100644 examples/osgslideshow/GNUmakefile.inst rename examples/{osgslideshow => slideshow3D}/DefaultPresentation.cpp (100%) rename examples/{osgslideshow => slideshow3D}/GNUmakefile (54%) create mode 100644 examples/slideshow3D/GNUmakefile.inst create mode 100644 examples/slideshow3D/ReaderWriterXML.cpp rename examples/{osgslideshow => slideshow3D}/SlideEventHandler.cpp (100%) rename examples/{osgslideshow => slideshow3D}/SlideEventHandler.h (100%) create mode 100644 examples/slideshow3D/SlideShowConstructor.cpp create mode 100644 examples/slideshow3D/SlideShowConstructor.h rename examples/{osgslideshow/osgslideshow.cpp => slideshow3D/slideshow3D.cpp} (100%) diff --git a/Make/makedirdefs b/Make/makedirdefs index 0b494411d..8cc3ceff8 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -48,7 +48,7 @@ PLUGIN_DIRS = \ txp\ zip\ 3dc\ - ive + ive\ # comment in if you have Performer installed. @@ -137,7 +137,6 @@ EXAMPLE_DIRS = \ osgshaders\ osgshadowtexture\ osgshape\ - osgslideshow\ osgstereoimage\ osgteapot\ osgtext\ @@ -150,6 +149,7 @@ EXAMPLE_DIRS = \ osgvertexprogram\ osgviewer\ osgwindows\ + slideshow3D\ # osgpagedlod\ # osgsimulation\ diff --git a/VisualStudio/osgDB/osgDB.dsp b/VisualStudio/osgDB/osgDB.dsp index 3b707f198..1c109df7a 100755 --- a/VisualStudio/osgDB/osgDB.dsp +++ b/VisualStudio/osgDB/osgDB.dsp @@ -53,7 +53,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 /nologo /dll /pdb:none /machine:I386 /out:"../../bin/osgDB.dll" /libpath:"../../lib" +# ADD LINK32 OpenThreadsWin32.lib /nologo /dll /pdb:none /machine:I386 /out:"../../bin/osgDB.dll" /libpath:"../../lib" !ELSEIF "$(CFG)" == "Core osgDB - Win32 Debug" @@ -79,7 +79,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 opengl32.lib glu32.lib /nologo /dll /debug /machine:I386 /out:"../../bin/osgDBd.dll" /pdbtype:sept /libpath:"../../lib" +# ADD LINK32 OpenThreadsWin32d.lib opengl32.lib glu32.lib /nologo /dll /debug /machine:I386 /out:"../../bin/osgDBd.dll" /pdbtype:sept /libpath:"../../lib" # SUBTRACT LINK32 /pdb:none !ENDIF diff --git a/examples/osgslideshow/GNUmakefile.inst b/examples/osgslideshow/GNUmakefile.inst deleted file mode 100644 index c41b1d2f5..000000000 --- a/examples/osgslideshow/GNUmakefile.inst +++ /dev/null @@ -1,16 +0,0 @@ -TOPDIR = ../.. -include $(TOPDIR)/Make/makedefs - -CXXFILES =\ - SlideEventHandler.cpp\ - DefaultPresentation.cpp\ - osgviewer.cpp\ - -LIBS += -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) - -EXEC = osgslideshow - -INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include -LDFLAGS += $(PRODUCER_LIB_DIR) - -include $(TOPDIR)/Make/makerules diff --git a/examples/osgslideshow/DefaultPresentation.cpp b/examples/slideshow3D/DefaultPresentation.cpp similarity index 100% rename from examples/osgslideshow/DefaultPresentation.cpp rename to examples/slideshow3D/DefaultPresentation.cpp diff --git a/examples/osgslideshow/GNUmakefile b/examples/slideshow3D/GNUmakefile similarity index 54% rename from examples/osgslideshow/GNUmakefile rename to examples/slideshow3D/GNUmakefile index f59a0bd2f..7ac378370 100644 --- a/examples/osgslideshow/GNUmakefile +++ b/examples/slideshow3D/GNUmakefile @@ -2,17 +2,20 @@ TOPDIR = ../.. include $(TOPDIR)/Make/makedefs CXXFILES =\ + SlideShowConstructor.cpp\ SlideEventHandler.cpp\ DefaultPresentation.cpp\ - osgslideshow.cpp\ + ReaderWriterXML.cpp\ + slideshow3D.cpp\ -LIBS += -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) +CXXFLAGS += -I/usr/include/libxml2 +LIBS += -lxml2 -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) INSTFILES = \ $(CXXFILES)\ GNUmakefile.inst=GNUmakefile -EXEC = osgslideshow +EXEC = slideshow3D INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include LDFLAGS += $(PRODUCER_LIB_DIR) diff --git a/examples/slideshow3D/GNUmakefile.inst b/examples/slideshow3D/GNUmakefile.inst new file mode 100644 index 000000000..0616019fe --- /dev/null +++ b/examples/slideshow3D/GNUmakefile.inst @@ -0,0 +1,19 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + SlideShowConstructor.cpp\ + SlideEventHandler.cpp\ + DefaultPresentation.cpp\ + ReaderWriterXML.cpp\ + slideshow3D.cpp\ + +CXXFLAGS += -I/usr/include/libxml2 +LIBS += -lxml2 -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = slideshow3D + +INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include +LDFLAGS += $(PRODUCER_LIB_DIR) + +include $(TOPDIR)/Make/makerules diff --git a/examples/slideshow3D/ReaderWriterXML.cpp b/examples/slideshow3D/ReaderWriterXML.cpp new file mode 100644 index 000000000..5bbb5cb29 --- /dev/null +++ b/examples/slideshow3D/ReaderWriterXML.cpp @@ -0,0 +1,256 @@ +#include +#include +#include + +#include "SlideShowConstructor.h" + +#include +#include +#include +#include +#include + + +/** + * OpenSceneGraph plugin wrapper/converter. + */ +class ReaderWriterSS3D : public osgDB::ReaderWriter +{ +public: + ReaderWriterSS3D() { } + + virtual const char* className() + { + return "slideshow3D XML Reader/Writer"; + } + + virtual bool acceptsExtension(const std::string& extension) + { + return osgDB::equalCaseInsensitive(extension,"ss3d") || + osgDB::equalCaseInsensitive(extension,"xml") ; + } + + virtual ReadResult readNode(const std::string& fileName, + const osgDB::ReaderWriter::Options* options); + + + void parseModel(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur); + + void parseLayer(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur); + + void parseSlide (SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur); + + osg::Vec4 mapStringToColor(const std::string& str) + { + if (str=="BLACK") return osg::Vec4(0.0f,0.0f,0.0f,1.0f); + else return osg::Vec4(1.0f,1.0f,1.0f,1.0f); + } + +}; + +// Register with Registry to instantiate the above reader/writer. +osgDB::RegisterReaderWriterProxy g_readerWriter_SS3D_Proxy; + + +void ReaderWriterSS3D::parseModel(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) +{ + std::string filename; + float scale = 1.0f; + float rotation = 0.0f; + float position = 0.5f; + + printf(" new model\n"); + xmlChar *key; + cur = cur->xmlChildrenNode; + while (cur != NULL) + { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"filename"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + printf(" filename: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"scale"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + printf(" scale: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"rotation"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + printf(" rotation: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"position"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + printf(" position: %s\n", key); + xmlFree(key); + } + cur = cur->next; + } + + if (!filename.empty()) constructor.addModel(filename,scale,rotation,position); +} + +void ReaderWriterSS3D::parseLayer(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) +{ + constructor.addLayer(); + + printf(" new layer\n"); + xmlChar *key; + cur = cur->xmlChildrenNode; + while (cur != NULL) + { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"bullet"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + constructor.addBullet((const char*)key); + printf(" bullet: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"paragraph"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + printf(" paragraph: %s\n", key); + constructor.addParagraph((const char*)key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"image"))) + { + std::string filename; + float height = 1.0f; + + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + printf(" image: %s\n", key); + filename = (const char*)key; + xmlFree(key); + + key = xmlGetProp (cur, (const xmlChar *)"height"); + if (key) + { + printf(" height: %s\n", key); + height = atoi((const char*)key); + xmlFree(key); + } + + constructor.addImage(filename,height); + + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"model"))) + { + parseModel(constructor, doc,cur); + } + cur = cur->next; + } +} + + +void ReaderWriterSS3D::parseSlide (SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) +{ + + printf("new slide\n"); + + constructor.addSlide(); + + xmlChar *key; + cur = cur->xmlChildrenNode; + while (cur != NULL) + { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"title"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + constructor.setSlideTitle((const char*)key); + printf(" title: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"background"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + constructor.setSlideBackground((const char*)key); + printf(" background: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"layer"))) + { + parseLayer (constructor, doc, cur); + } + cur = cur->next; + } + return; +} + +osgDB::ReaderWriter::ReadResult ReaderWriterSS3D::readNode(const std::string& fileName, + const osgDB::ReaderWriter::Options* options) +{ + std::string ext = osgDB::getLowerCaseFileExtension(fileName); + if (!acceptsExtension(ext)) + return ReadResult::FILE_NOT_HANDLED; + + + + xmlDocPtr doc; + xmlNodePtr cur; + + doc = xmlParseFile(fileName.c_str()); + + if (doc == NULL ) { + fprintf(stderr,"Document not parsed successfully. \n"); + return ReadResult::FILE_NOT_HANDLED; + } + + cur = xmlDocGetRootElement(doc); + + if (cur == NULL) { + fprintf(stderr,"empty document\n"); + xmlFreeDoc(doc); + return ReadResult::FILE_NOT_HANDLED; + } + + if (xmlStrcmp(cur->name, (const xmlChar *) "presentation")) { + fprintf(stderr,"document of the wrong type, root node != story"); + xmlFreeDoc(doc); + return ReadResult::FILE_NOT_HANDLED; + } + + SlideShowConstructor constructor; + + xmlChar *key; + cur = cur->xmlChildrenNode; + while (cur != NULL) { + + if ((!xmlStrcmp(cur->name, (const xmlChar *)"name"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + constructor.setPresentationName((const char*)key); + printf("name: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bgcolor"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + constructor.setBackgroundColor(mapStringToColor((const char*)key)); + printf("bgcolor: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"textcolor"))) + { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + constructor.setTextColor(mapStringToColor((const char*)key)); + printf("textcolor: %s\n", key); + xmlFree(key); + } + else if ((!xmlStrcmp(cur->name, (const xmlChar *)"slide"))) + { + parseSlide (constructor, doc, cur); + } + + cur = cur->next; + } + + xmlFreeDoc(doc); + + return constructor.takePresentation(); +} + diff --git a/examples/osgslideshow/SlideEventHandler.cpp b/examples/slideshow3D/SlideEventHandler.cpp similarity index 100% rename from examples/osgslideshow/SlideEventHandler.cpp rename to examples/slideshow3D/SlideEventHandler.cpp diff --git a/examples/osgslideshow/SlideEventHandler.h b/examples/slideshow3D/SlideEventHandler.h similarity index 100% rename from examples/osgslideshow/SlideEventHandler.h rename to examples/slideshow3D/SlideEventHandler.h diff --git a/examples/slideshow3D/SlideShowConstructor.cpp b/examples/slideshow3D/SlideShowConstructor.cpp new file mode 100644 index 000000000..a2ccf40af --- /dev/null +++ b/examples/slideshow3D/SlideShowConstructor.cpp @@ -0,0 +1,262 @@ +#include "SlideShowConstructor.h" + +#include +#include +#include +#include +#include + +#include + +#include + + +SlideShowConstructor::SlideShowConstructor() +{ + _slideOrigin.set(0.0f,0.0f,0.0f); + _slideWidth = 1280.0f; + _slideHeight = 1024.0f; + + _backgroundColor.set(0.0f,0.0f,0.0f,1.0f); + _textColor.set(1.0f,1.0f,1.0f,1.0f); + _textFont = "fonts/arial.ttf"; + +} + +void SlideShowConstructor::createPresentation() +{ + _titleHeight = _slideHeight*0.08f; + _titleOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.5f,0.0f,_slideHeight*0.98f-_titleHeight); + + _textHeight = _slideHeight*0.05f; + + _textOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.1f,0.0f,_titleOrigin.z()-2*_textHeight); + _imageOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.7f,0.0f,_titleOrigin.z()*0.5f); + _modelLeft = _slideOrigin + osg::Vec3(_slideWidth*0.0f,0.0f,_titleOrigin.z()*0.5f); + _modelRight = _slideOrigin + osg::Vec3(_slideWidth*1.0f,0.0f,_titleOrigin.z()*0.5f); + + _root = new osg::ClearNode; + _root->setClearColor(_backgroundColor); + + _presentationSwitch = new osg::Switch; + _presentationSwitch->setName(std::string("Presentation_")+_presentationName); + + _root->addChild(_presentationSwitch.get()); + +} + +void SlideShowConstructor::setBackgroundColor(const osg::Vec4& color) +{ + _backgroundColor = color; + if (_root.valid()) _root->setClearColor(_backgroundColor); +} + +void SlideShowConstructor::setTextColor(const osg::Vec4& color) +{ + _textColor = color; +} + +void SlideShowConstructor::setPresentationName(const std::string& name) +{ + _presentationName = name; + if (_presentationSwitch.valid()) _presentationSwitch->setName(std::string("Presentation_")+_presentationName); +} + + +void SlideShowConstructor::addSlide() +{ + if (!_presentationSwitch) createPresentation(); + + // reset cursors + _textCursor = _textOrigin; + _imageCursor = _imageOrigin; + _modelCursor = _modelLeft*0.5f + _modelRight*0.5f; + + _slide = new osg::Switch; + _slide->setName(std::string("Slide_")+_slideTitle); + + _presentationSwitch->addChild(_slide.get()); + + _previousLayer = 0; + _currentLayer = 0; +} + +void SlideShowConstructor::addLayer() +{ + if (!_slide) addSlide(); + + _previousLayer = _currentLayer; + + _currentLayer = new osg::Group; + + _slide->addChild(_currentLayer.get()); + + if (!_previousLayer) + { + // create the background and title.. + if (!_slideBackgroundImageFileName.empty()) + { + osg::Geometry* backgroundQuad = osg::createTexturedQuadGeometry(_slideOrigin, + osg::Vec3(_slideWidth,0.0f,0.0f), + osg::Vec3(0.0f,0.0f,_slideHeight)); + + osg::Geode* background = new osg::Geode; + + osg::StateSet* backgroundStateSet = background->getOrCreateStateSet(); + backgroundStateSet->setAttributeAndModes( + new osg::PolygonOffset(1.0f,1.0f), + osg::StateAttribute::ON); + + backgroundStateSet->setTextureAttributeAndModes(0, + new osg::Texture2D(osgDB::readImageFile(_slideBackgroundImageFileName)), + osg::StateAttribute::ON); + + background->addDrawable(backgroundQuad); + + _currentLayer->addChild(background); + } + + if (!_slideTitle.empty()) + { + osg::Geode* geode = new osg::Geode; + + osgText::Text* text = new osgText::Text; + text->setFont(_textFont); + text->setColor(_textColor); + text->setCharacterSize(_titleHeight); + text->setAxisAlignment(osgText::Text::XZ_PLANE); + text->setAlignment(osgText::Text::CENTER_BASE_LINE); + text->setPosition(_titleOrigin); + + text->setText(_slideTitle); + + geode->addDrawable(text); + + _currentLayer->addChild(geode); + } + + } + else + { + // copy previous layer's children across into new layer. + for(unsigned int i=0;i<_previousLayer->getNumChildren();++i) + { + _currentLayer->addChild(_previousLayer->getChild(i)); + } + } + +} + +void SlideShowConstructor::addBullet(const std::string& bullet) +{ + if (!_currentLayer) addLayer(); + + osg::Geode* geode = new osg::Geode; + + osgText::Text* text = new osgText::Text; + + text->setFont(_textFont); + text->setColor(_textColor); + text->setCharacterSize(_textHeight); + text->setAxisAlignment(osgText::Text::XZ_PLANE); + text->setAlignment(osgText::Text::BASE_LINE); + text->setPosition(_textCursor); + + text->setText(bullet); + + osg::BoundingBox bb = text->getBound(); + _textCursor.z() = bb.zMin()-_textHeight; + + geode->addDrawable(text); + + _currentLayer->addChild(geode); + +} + +void SlideShowConstructor::addParagraph(const std::string& paragraph) +{ + if (!_currentLayer) addLayer(); + + osg::Geode* geode = new osg::Geode; + + osgText::Text* text = new osgText::Text; + + text->setFont(_textFont); + text->setColor(_textColor); + text->setCharacterSize(_textHeight); + text->setAxisAlignment(osgText::Text::XZ_PLANE); + text->setAlignment(osgText::Text::BASE_LINE); + text->setPosition(_textCursor); + + text->setText(paragraph); + + osg::BoundingBox bb = text->getBound(); + _textCursor.z() = bb.zMin()-_textHeight; + + geode->addDrawable(text); + + _currentLayer->addChild(geode); +} + +void SlideShowConstructor::addImage(const std::string& filename,float height) +{ + if (!_currentLayer) addLayer(); + + osg::Image* image = osgDB::readImageFile(filename); + + if (!image) return; + + float s = image->s(); + float t = image->t(); + + float image_height = _slideHeight*0.6f; + float image_width = image_height*s/t; + + osg::Vec3 pos = _imageCursor + osg::Vec3(-image_width*0.5f,-height*image_height*0.1f,-image_height*0.5f); + + osg::Geometry* backgroundQuad = osg::createTexturedQuadGeometry(pos, + osg::Vec3(image_width,0.0f,0.0f), + osg::Vec3(0.0f,0.0f,image_height)); + + osg::Geode* background = new osg::Geode; + + osg::StateSet* backgroundStateSet = background->getOrCreateStateSet(); + + backgroundStateSet->setTextureAttributeAndModes(0, + new osg::Texture2D(image), + osg::StateAttribute::ON); + + background->addDrawable(backgroundQuad); + + _currentLayer->addChild(background); +} + +void SlideShowConstructor::addModel(const std::string& filename,float scale,float rotation,float position) +{ + if (!_currentLayer) addLayer(); + + osg::Node* model = osgDB::readNodeFile(filename); + + if (!model) return; + + osg::Vec3 pos = _modelLeft*(1.0f-position) + _modelRight*position; + float radius = scale*_slideHeight*0.7f; + osg::Quat quat; + quat.makeRotate(osg::DegreesToRadians(rotation),0.0f,0.0f,1.0f); + + osg::MatrixTransform* transform = new osg::MatrixTransform; + + const osg::BoundingSphere& bs = model->getBound(); + + transform->setDataVariance(osg::Object::STATIC); + transform->setMatrix(osg::Matrix::translate(-bs.center())* + osg::Matrix::scale(radius/bs.radius(),radius/bs.radius(),radius/bs.radius())* + osg::Matrix::rotate(quat)* + osg::Matrix::translate(pos)); + + transform->addChild(model); + + _currentLayer->addChild(transform); + +} + diff --git a/examples/slideshow3D/SlideShowConstructor.h b/examples/slideshow3D/SlideShowConstructor.h new file mode 100644 index 000000000..8940bfffe --- /dev/null +++ b/examples/slideshow3D/SlideShowConstructor.h @@ -0,0 +1,86 @@ +#ifndef SLIDESHOWCONSTUCTOR +#define SLIDESHOWCONSTRUCTOR + +#include +#include +#include +#include +#include + +class SlideShowConstructor +{ +public: + + SlideShowConstructor(); + + void createPresentation(); + + void setBackgroundColor(const osg::Vec4& color); + + void setTextColor(const osg::Vec4& color); + + void setPresentationName(const std::string& name); + + void addSlide(); + + void setSlideTitle(const std::string& name) { _slideTitle = name; } + + void setSlideBackground(const std::string& name) { _slideBackgroundImageFileName = name; } + + void addLayer(); + + void addBullet(const std::string& bullet); + + void addParagraph(const std::string& paragraph); + + void addImage(const std::string& filename,float height); + + void addModel(const std::string& filename,float scale,float rotation,float position); + + osg::ClearNode* takePresentation() { return _root.release(); } + + osg::ClearNode* getPresentation() { return _root.get(); } + + osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); } + + osg::Switch* getCurrentSlide() { return _slide.get(); } + + osg::Group* getCurrentLayer() { return _currentLayer.get(); } + +protected: + + osg::Vec3 _slideOrigin; + float _slideWidth; + float _slideHeight; + + osg::Vec4 _backgroundColor; + osg::Vec4 _textColor; + std::string _textFont; + float _titleHeight; + float _textHeight; + std::string _presentationName; + + + osg::Vec3 _titleOrigin; + osg::Vec3 _textOrigin; + osg::Vec3 _imageOrigin; + osg::Vec3 _modelLeft; + osg::Vec3 _modelRight; + + osg::Vec3 _textCursor; + osg::Vec3 _imageCursor; + osg::Vec3 _modelCursor; + + osg::ref_ptr _root; + osg::ref_ptr _presentationSwitch; + + osg::ref_ptr _slide; + std::string _slideTitle; + std::string _slideBackgroundImageFileName; + + osg::ref_ptr _previousLayer; + osg::ref_ptr _currentLayer; + +}; + +#endif diff --git a/examples/osgslideshow/osgslideshow.cpp b/examples/slideshow3D/slideshow3D.cpp similarity index 100% rename from examples/osgslideshow/osgslideshow.cpp rename to examples/slideshow3D/slideshow3D.cpp