Added XML support and slideshow constructor to slideshow3D example, now
renamed from the previous osgslideshow.
This commit is contained in:
parent
31115ffd2d
commit
f7ad937020
@ -48,7 +48,7 @@ PLUGIN_DIRS = \
|
|||||||
txp\
|
txp\
|
||||||
zip\
|
zip\
|
||||||
3dc\
|
3dc\
|
||||||
ive
|
ive\
|
||||||
|
|
||||||
|
|
||||||
# comment in if you have Performer installed.
|
# comment in if you have Performer installed.
|
||||||
@ -137,7 +137,6 @@ EXAMPLE_DIRS = \
|
|||||||
osgshaders\
|
osgshaders\
|
||||||
osgshadowtexture\
|
osgshadowtexture\
|
||||||
osgshape\
|
osgshape\
|
||||||
osgslideshow\
|
|
||||||
osgstereoimage\
|
osgstereoimage\
|
||||||
osgteapot\
|
osgteapot\
|
||||||
osgtext\
|
osgtext\
|
||||||
@ -150,6 +149,7 @@ EXAMPLE_DIRS = \
|
|||||||
osgvertexprogram\
|
osgvertexprogram\
|
||||||
osgviewer\
|
osgviewer\
|
||||||
osgwindows\
|
osgwindows\
|
||||||
|
slideshow3D\
|
||||||
|
|
||||||
# osgpagedlod\
|
# osgpagedlod\
|
||||||
# osgsimulation\
|
# osgsimulation\
|
||||||
|
@ -53,7 +53,7 @@ BSC32=bscmake.exe
|
|||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LINK32=link.exe
|
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 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"
|
!ELSEIF "$(CFG)" == "Core osgDB - Win32 Debug"
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ BSC32=bscmake.exe
|
|||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LINK32=link.exe
|
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 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
|
# SUBTRACT LINK32 /pdb:none
|
||||||
|
|
||||||
!ENDIF
|
!ENDIF
|
||||||
|
@ -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
|
|
@ -2,17 +2,20 @@ TOPDIR = ../..
|
|||||||
include $(TOPDIR)/Make/makedefs
|
include $(TOPDIR)/Make/makedefs
|
||||||
|
|
||||||
CXXFILES =\
|
CXXFILES =\
|
||||||
|
SlideShowConstructor.cpp\
|
||||||
SlideEventHandler.cpp\
|
SlideEventHandler.cpp\
|
||||||
DefaultPresentation.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 = \
|
INSTFILES = \
|
||||||
$(CXXFILES)\
|
$(CXXFILES)\
|
||||||
GNUmakefile.inst=GNUmakefile
|
GNUmakefile.inst=GNUmakefile
|
||||||
|
|
||||||
EXEC = osgslideshow
|
EXEC = slideshow3D
|
||||||
|
|
||||||
INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include
|
INC += $(PRODUCER_INCLUDE_DIR) -I/usr/X11R6/include
|
||||||
LDFLAGS += $(PRODUCER_LIB_DIR)
|
LDFLAGS += $(PRODUCER_LIB_DIR)
|
19
examples/slideshow3D/GNUmakefile.inst
Normal file
19
examples/slideshow3D/GNUmakefile.inst
Normal file
@ -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
|
256
examples/slideshow3D/ReaderWriterXML.cpp
Normal file
256
examples/slideshow3D/ReaderWriterXML.cpp
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
#include <osgDB/ReaderWriter>
|
||||||
|
#include <osgDB/FileNameUtils>
|
||||||
|
#include <osgDB/Registry>
|
||||||
|
|
||||||
|
#include "SlideShowConstructor.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <libxml/xmlmemory.h>
|
||||||
|
#include <libxml/parser.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<ReaderWriterSS3D> 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();
|
||||||
|
}
|
||||||
|
|
262
examples/slideshow3D/SlideShowConstructor.cpp
Normal file
262
examples/slideshow3D/SlideShowConstructor.cpp
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
#include "SlideShowConstructor.h"
|
||||||
|
|
||||||
|
#include <osg/Geometry>
|
||||||
|
#include <osg/PolygonOffset>
|
||||||
|
#include <osg/Geode>
|
||||||
|
#include <osg/Texture2D>
|
||||||
|
#include <osg/MatrixTransform>
|
||||||
|
|
||||||
|
#include <osgDB/ReadFile>
|
||||||
|
|
||||||
|
#include <osgText/Text>
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
86
examples/slideshow3D/SlideShowConstructor.h
Normal file
86
examples/slideshow3D/SlideShowConstructor.h
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#ifndef SLIDESHOWCONSTUCTOR
|
||||||
|
#define SLIDESHOWCONSTRUCTOR
|
||||||
|
|
||||||
|
#include <osg/Vec3>
|
||||||
|
#include <osg/Vec4>
|
||||||
|
#include <osg/Group>
|
||||||
|
#include <osg/ClearNode>
|
||||||
|
#include <osg/Switch>
|
||||||
|
|
||||||
|
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<osg::ClearNode> _root;
|
||||||
|
osg::ref_ptr<osg::Switch> _presentationSwitch;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Switch> _slide;
|
||||||
|
std::string _slideTitle;
|
||||||
|
std::string _slideBackgroundImageFileName;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Group> _previousLayer;
|
||||||
|
osg::ref_ptr<osg::Group> _currentLayer;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user