From 71bea99ba274a20e676e72cdb8bbd9451a84fd6c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Nov 2002 13:56:12 +0000 Subject: [PATCH] Added Geoff Michel's new osggeomdemo program which allows control of geo models via the mouse. --- Make/makedirdefs | 1 + VisualStudio/Demos/osggeodemo/osggeodemo.dsp | 95 ++++++++ VisualStudio/VisualStudio.dsw | 27 +++ VisualStudio/osgPlugins/geo/geo.dsp | 4 + src/Demos/osggeodemo/Makefile | 16 ++ src/Demos/osggeodemo/Makefile.inst | 12 + src/Demos/osggeodemo/osggeodemo.cpp | 220 +++++++++++++++++++ 7 files changed, 375 insertions(+) create mode 100755 VisualStudio/Demos/osggeodemo/osggeodemo.dsp create mode 100644 src/Demos/osggeodemo/Makefile create mode 100644 src/Demos/osggeodemo/Makefile.inst create mode 100644 src/Demos/osggeodemo/osggeodemo.cpp diff --git a/Make/makedirdefs b/Make/makedirdefs index fbc8b98fd..954b76ecb 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -87,6 +87,7 @@ DEMOS_DIRS = \ osglight\ osgmultitexture\ osgoccluder\ + osggeodemo\ osgparticle\ osgprerender\ osgreflect\ diff --git a/VisualStudio/Demos/osggeodemo/osggeodemo.dsp b/VisualStudio/Demos/osggeodemo/osggeodemo.dsp new file mode 100755 index 000000000..721b03943 --- /dev/null +++ b/VisualStudio/Demos/osggeodemo/osggeodemo.dsp @@ -0,0 +1,95 @@ +# Microsoft Developer Studio Project File - Name="Demo osggeodemo" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Demo osggeodemo - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "osggeodemo.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "osggeodemo.mak" CFG="Demo osggeodemo - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Demo osggeodemo - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Demo osggeodemo - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Demo osggeodemo - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# 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 /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osggeodemo.exe" /libpath:"../../../lib" + +!ELSEIF "$(CFG)" == "Demo osggeodemo - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# 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 /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 glut32.lib glu32.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osggeodemod.exe" /pdbtype:sept /libpath:"../../../lib" +# SUBTRACT LINK32 /incremental:no + +!ENDIF + +# Begin Target + +# Name "Demo osggeodemo - Win32 Release" +# Name "Demo osggeodemo - Win32 Debug" +# Begin Source File + +SOURCE=..\..\..\src\Demos\osggeodemo\osggeodemo.cpp +# End Source File +# End Target +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Project diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 1f5eccd82..7535e9322 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -487,6 +487,33 @@ Package=<4> End Project Dependency }}} +############################################################################################################################################################## + +Project: "Demo osggeodemo"=.\Demos\osggeodemo\osggeodemo.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgGA + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgGLUT + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgUtil + End Project Dependency +}}} + ############################################################################### Project: "Demo osghud"=.\Demos\osghud\osghud.dsp - Package Owner=<4> diff --git a/VisualStudio/osgPlugins/geo/geo.dsp b/VisualStudio/osgPlugins/geo/geo.dsp index 2802e0b65..f64630334 100644 --- a/VisualStudio/osgPlugins/geo/geo.dsp +++ b/VisualStudio/osgPlugins/geo/geo.dsp @@ -116,6 +116,10 @@ SOURCE=..\..\..\src\osgPlugins\geo\geoUnits.h SOURCE=..\..\..\src\osgPlugins\geo\osgGeoStructs.h # End Source File +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\geo\osgGeoAnimation.h +# End Source File # End Group # Begin Group "Resource Files" diff --git a/src/Demos/osggeodemo/Makefile b/src/Demos/osggeodemo/Makefile new file mode 100644 index 000000000..914ea8da2 --- /dev/null +++ b/src/Demos/osggeodemo/Makefile @@ -0,0 +1,16 @@ +TOPDIR = ../../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osggeodemo.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + Makefile.inst=Makefile + +EXEC = osggeodemo + +include $(TOPDIR)/Make/makerules + diff --git a/src/Demos/osggeodemo/Makefile.inst b/src/Demos/osggeodemo/Makefile.inst new file mode 100644 index 000000000..c066f59ab --- /dev/null +++ b/src/Demos/osggeodemo/Makefile.inst @@ -0,0 +1,12 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osggeomdemo.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osggeomdemo + + +include $(TOPDIR)/Make/makerules diff --git a/src/Demos/osggeodemo/osggeodemo.cpp b/src/Demos/osggeodemo/osggeodemo.cpp new file mode 100644 index 000000000..a44f1f00e --- /dev/null +++ b/src/Demos/osggeodemo/osggeodemo.cpp @@ -0,0 +1,220 @@ +// Geo demo written by Geoff Michel, November 2002. + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + + +#include + +// currently not a satisfactory solution, but this is early days for the +// geo loader and having direct links with it. +#include "../../osgPlugins/geo/osgGeoAnimation.h" + +void write_usage(std::ostream& out,const std::string& name) +{ + out << std::endl; + out <<"usage:"<< std::endl; + out <<" "< *lvals=l->getvars(); + for (std::vector::iterator itr=lvals->begin(); + itr!=lvals->end(); + ++itr) {// for each user var + if (itr->getName() == "xpos") { + itr->setVal((*itr->getValue())+speed*sin(heading)); + // std::cout << " nx " << (*itr->getValue()) ; + } else if (itr->getName() == "ypos") { + itr->setVal((*itr->getValue())+speed*cos(heading)); + // std::cout << " ny " << (*itr->getValue()) ; + } else if (itr->getName() == "sped") { + itr->setVal(0.00025*(mouse_y-300)); + speed=(*itr->getValue()); + // std::cout << " nspd " << speed << std::endl; + } else if (itr->getName() == "heading") { + itr->setVal((*itr->getValue())-0.0001*(mouse_x-400)); + heading=(*itr->getValue()); + // std::cout << " nhdg " << heading << std::endl; + } else if (itr->getName() == "conerot") { + itr->setVal((mouse_x-400)); + } else if (itr->getName() == "planrot") { + itr->setVal((mouse_y-300)/200.0); + } + } + } + +private: + int mouse_x, mouse_y; + float speed, heading; +}; + +static geodemoEventHandler *ghand=NULL; + +void moveit(const double t, userVars *l,userVars *e) +{ // all the local and external variables declared in the geo modeller are here available. + ghand->moveit(l); +} + +int main( int argc, char **argv ) +{ + std::string pathfile; + + // initialize the GLUT + glutInit( &argc, argv ); + + if (argc<2) + { + write_usage(std::cout,argv[0]); + return 1; + } + + // create the commandline args. + std::vector commandLine; + for(int i=1;i= argc ) { + write_usage( std::cout, argv[0]); + return 1; + } + else + pathfile = std::string(argv[++i]); + } + else + commandLine.push_back(argv[i]); + } + + // initialize the viewer. + osgGLUT::Viewer viewer; + viewer.setWindowTitle(argv[0]); + + // configure the viewer from the commandline arguments, and eat any + // parameters that have been matched. + viewer.readCommandLine(commandLine); + + // configure the plugin registry from the commandline arguments, and + // eat any parameters that have been matched. + osgDB::readCommandLine(commandLine); + + // load the nodes from the commandline arguments. + osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + if (!rootnode) + { + write_usage(osg::notify(osg::NOTICE),argv[0]); + return 1; + } + + // run optimization over the scene graph + osgUtil::Optimizer optimzer; + optimzer.optimize(rootnode); + + // add a viewport to the viewer and attach the scene graph. + viewer.addViewport( rootnode ); + + // register trackball, flight and drive. + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); + + if( !pathfile.empty() ) { + osgGA::AnimationPathManipulator *apm = new osgGA::AnimationPathManipulator(pathfile); + if( apm->valid() ) + viewer.registerCameraManipulator(apm); + else + delete apm; + } + + geoHeader *gh = dynamic_cast(rootnode); + if (gh) + { // it is a geo file, so set function to update its animation variables. + ghand=new geodemoEventHandler(); + gh->setUserUpdate(moveit); + viewer.prependEventHandler(ghand); + } else { // maybe a group with geo models below. + osg::Group *gpall=dynamic_cast(rootnode); + if (gpall) { + int nchild=gpall->getNumChildren(); + for (int i=0; igetChild(i); + gh = dynamic_cast(nod); + if (gh) + { + ghand=new geodemoEventHandler(); + gh->setUserUpdate(moveit); + viewer.prependEventHandler(ghand); + } + } + } + } + + // open the viewer window. + viewer.open(); + + // fire up the event loop. + viewer.run(); + + return 0; +}