From e87a08f1c31f41765ea6e1eadde0e8563190cf72 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 16 Mar 2003 21:58:27 +0000 Subject: [PATCH] Fixes to osgcluster demo as new Producer based example. Added extra pragrma remove a warning about float to int cast under VS.NET. --- Make/makedirdefs | 2 +- VisualStudio/Demos/hangglide/hangglide.dsp | 156 -------- examples/osgcluster/osgcluster.cpp | 364 +++++------------- .../osgvertexprogram/osgvertexprogram.cpp | 6 +- include/osg/Export | 1 + include/osgDB/Export | 1 + include/osgGA/Export | 1 + include/osgParticle/Export | 1 + include/osgProducer/Export | 1 + include/osgSim/Export | 1 + include/osgText/Export | 1 + include/osgUtil/Export | 1 + 12 files changed, 111 insertions(+), 425 deletions(-) delete mode 100755 VisualStudio/Demos/hangglide/hangglide.dsp diff --git a/Make/makedirdefs b/Make/makedirdefs index 29b0d6a62..6f8c72965 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -122,4 +122,4 @@ EXAMPLE_DIRS = \ osgviewer\ # comment in you want to compile the cluster demo. -# EXAMPLE_DIRS += osgcluster +EXAMPLE_DIRS += osgcluster diff --git a/VisualStudio/Demos/hangglide/hangglide.dsp b/VisualStudio/Demos/hangglide/hangglide.dsp deleted file mode 100755 index 3bf50502d..000000000 --- a/VisualStudio/Demos/hangglide/hangglide.dsp +++ /dev/null @@ -1,156 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Demo hangglide" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=Demo hangglide - 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 "hangglide.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 "hangglide.mak" CFG="Demo hangglide - Win32 Release" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Demo hangglide - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "Demo hangglide - 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 hangglide - 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/hangglide.exe" /libpath:"../../../lib" - -!ELSEIF "$(CFG)" == "Demo hangglide - 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" /YX /FD /c -# SUBTRACT CPP /Fr -# 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 /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/hangglided.exe" /pdbtype:sept /libpath:"../../../lib" -# SUBTRACT LINK32 /incremental:no - -!ENDIF - -# Begin Target - -# Name "Demo hangglide - Win32 Release" -# Name "Demo hangglide - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\Base.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\GliderManipulator.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\hangglide.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\Hat.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\ReaderWriterFLY.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\Sky.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\Tank.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\Terrain.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\Trees.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter ";h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=..\..\..\Src\Demos\hangglide\GliderManipulator.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\Demos\hangglide\Hat.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\Demos\hangglide\terrain_coords.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\Demos\hangglide\terrain_normals.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\Demos\hangglide\terrain_texcoords.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "" -# End Group -# End Target -# End Project diff --git a/examples/osgcluster/osgcluster.cpp b/examples/osgcluster/osgcluster.cpp index 24254ba00..353d4d30a 100644 --- a/examples/osgcluster/osgcluster.cpp +++ b/examples/osgcluster/osgcluster.cpp @@ -41,56 +41,31 @@ class CameraPacket { _byte_order = 0x12345678; } - void setPacket(const osg::Camera& camera,const osg::FrameStamp* frameStamp) + void setPacket(const osg::Matrix& matrix,const osg::FrameStamp* frameStamp) { - _eye = camera.getEyePoint(); - _center = camera.getCenterPoint(); - _up = camera.getUpVector(); + _matrix = matrix; if (frameStamp) { _frameStamp = *frameStamp; } } - void getCamera(osg::Camera& camera,float angle_offset=0.0f) + void getModelView(osg::Matrix& matrix,float angle_offset=0.0f) { - osg::Vec3 lv = _center-_eye; - osg::Matrix matrix; - matrix.makeIdentity(); - matrix.makeRotate(angle_offset,_up.x(),_up.y(),_up.z()); - lv = lv*matrix; - - camera.setLookAt(_eye,_eye+lv,_up); - + matrix = _matrix * osg::Matrix::rotate(angle_offset,0.0f,1.0f,1.0f); } - void getSceneViewUpdate(osgUtil::SceneView& sv) - { - // note pass a separate reference counted FrameStamp - // rather than this frame stamp as it can get overwritten. - sv.setFrameStamp(new osg::FrameStamp(_frameStamp)); - } - - void checkByteOrder( void ) { if( _byte_order == 0x78563412 ) // We're backwards { swapBytes( _byte_order ); swapBytes( _masterKilled ); - swapBytes( _eye[0] ); - swapBytes( _eye[1] ); - swapBytes( _eye[2] ); - swapBytes( _center[0] ); - swapBytes( _center[1] ); - swapBytes( _center[2] ); - swapBytes( _up[0] ); - swapBytes( _up[1] ); - swapBytes( _up[2] ); - swapBytes( _attachMatrix ); for( int i = 0; i < 16; i++ ) swapBytes( _matrix.ptr()[i] ); + + // umm.. we should byte swap _frameStamp too... } } @@ -100,10 +75,6 @@ class CameraPacket { unsigned long _byte_order; bool _masterKilled; - osg::Vec3 _eye; - osg::Vec3 _center; - osg::Vec3 _up; - bool _attachMatrix; osg::Matrix _matrix; // note don't use a ref_ptr as used elsewhere for FrameStamp @@ -114,222 +85,12 @@ class CameraPacket { }; -// using namespace osgUtil required to get round VisualStudio's inablility -// to handle osgUtil::SceneView::app() in the code below, only SceneView::app -// works..but this breaks the IRIX build, unless you have the osgUtil??! -// Robert Osfield, July 2002. -using namespace osgUtil; - -class MySceneView : public SceneView { - - public: - - enum ViewerMode - { - STAND_ALONE, - SLAVE, - MASTER - }; - - MySceneView(ViewerMode viewerMode,int socketNumber,float camera_fov, float camera_offset): - _viewerMode(viewerMode),_socketNumber(socketNumber), - _camera_fov(camera_fov), _camera_offset(camera_offset) - { - setDefaults(); - getCamera()->setAdjustAspectRatioMode(osg::Camera::ADJUST_VERTICAL); - getCamera()->setFOV(camera_fov,camera_fov*(600.0f/800.0f),1.0f,1000.0f); - - _bc.setPort(socketNumber); - _rc.setPort(socketNumber); - }; - - ~MySceneView() - { - if (_viewerMode==MASTER) - { - // need to broadcast my death. - CameraPacket cp; - cp.setPacket(*getCamera(),getFrameStamp()); - cp.setMasterKilled(true); - - _bc.setBuffer(&cp, sizeof( CameraPacket )); - _bc.sync(); - - std::cout << "broadcasting death"< NodeList; - NodeList nodeList; - for( i = 1; i < argc; i++ ) - { - - if (argv[i][0]=='-') - { - switch(argv[i][1]) - { - - case('m'): - viewerMode = MySceneView::MASTER; - break; - case('s'): - viewerMode = MySceneView::SLAVE; - break; - case('n'): - ++i; - if (iloadLibrary(argv[i]); - } - break; - case('e'): - ++i; - if (icreateLibraryNameForExt(argv[i]); - osgDB::Registry::instance()->loadLibrary(libName); - } - break; - } - } else - { - osg::Node *node = osgDB::readNodeFile( argv[i] ); - - if( node != (osg::Node *)0L ) - { - if (node->getName().empty()) node->setName( argv[i] ); - nodeList.push_back(node); - } - } - - } - - if (nodeList.size()==0) - { - osg::notify(osg::WARN) << "No data loaded."<1 - { - osg::Group* group = new osg::Group(); - for(NodeList::iterator itr=nodeList.begin(); - itr!=nodeList.end(); - ++itr) - { - group->addChild(*itr); - } - - rootnode = group; - } - - return rootnode; -} - + STAND_ALONE, + SLAVE, + MASTER +}; int main( int argc, char **argv ) { @@ -340,6 +101,11 @@ int main( int argc, char **argv ) // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + arguments.getApplicationUsage()->addCommandLineOption("-m","Set viewer to MASTER mode, sending view via packets."); + arguments.getApplicationUsage()->addCommandLineOption("-s","Set viewer to SLAVE mode, reciving view via packets."); + arguments.getApplicationUsage()->addCommandLineOption("-n ","Socket number to transmit packets"); + arguments.getApplicationUsage()->addCommandLineOption("-f ","Field of view of camera"); + arguments.getApplicationUsage()->addCommandLineOption("-o ","Offset angle of camera"); // construct the viewer. osgProducer::Viewer viewer(arguments); @@ -350,6 +116,22 @@ int main( int argc, char **argv ) // get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(*arguments.getApplicationUsage()); + + // read up the osgcluster specific arguments. + ViewerMode viewerMode = STAND_ALONE; + while (arguments.read("-m")) viewerMode = MASTER; + while (arguments.read("-s")) viewerMode = SLAVE; + + float socketNumber=8100.0f; + while (arguments.read("-n",socketNumber)) ; + + float camera_fov=45.0f; + while (arguments.read("-f",camera_fov)) ; + + float camera_offset=45.0f; + while (arguments.read("-o",camera_offset)) ; + + // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { @@ -366,30 +148,21 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } - - - osg::Timer timer; - osg::Timer_t before_load = timer.tick(); - MySceneView::ViewerMode viewerMode = MySceneView::STAND_ALONE; - int socketNumber=8100; - float camera_fov=45.0f; - float camera_offset=45.0f; - - osg::Node* rootnode = getNodeFromFiles( argc, argv, viewerMode, socketNumber,camera_fov,camera_offset); - osg::Timer_t after_load = timer.tick(); - std::cout << "Time for load = "< rootnode = osgDB::readNodeFiles(arguments); - osg::ref_ptr mySceneView = new MySceneView(viewerMode,socketNumber,camera_fov,osg::inDegrees(camera_offset)); - mySceneView->setSceneData(rootnode); // set the scene to render - viewer.setSceneData(mySceneView.get()); + viewer.setSceneData(rootnode.get()); // create the windows and run the threads. viewer.realize(Producer::CameraGroup::ThreadPerCamera); + Broadcaster bc; + Receiver rc; + while( !viewer.done() ) { // wait for all cull and draw threads to complete. @@ -399,10 +172,71 @@ int main( int argc, char **argv ) // call all node update callbacks and animations. viewer.update(); + + // special handling for working as a cluster. + switch (viewerMode) + { + case(MASTER): + { + CameraPacket cp; + + // take camera zero as the guide. + osg::Matrix modelview(viewer.getCameraConfig()->getCamera(0)->getViewMatrix()); + + cp.setPacket(modelview,viewer.getFrameStamp()); + + bc.setBuffer(&cp, sizeof( CameraPacket )); + bc.sync(); + + } + break; + case(SLAVE): + { + CameraPacket cp; + + rc.setBuffer(&cp, sizeof( CameraPacket )); + rc.sync(); + + cp.checkByteOrder(); + + osg::Matrix modelview; + cp.getModelView(modelview,camera_offset); + + viewer.setView(modelview.ptr()); + + if (cp.getMasterKilled()) + { + std::cout << "recieved master killed"< -#include - #include #include #include @@ -27,6 +24,9 @@ #include #include +#include + + float refract = 1.01; // ratio of indicies of refraction float fresnel = 1.1; // Fresnel multiplier diff --git a/include/osg/Export b/include/osg/Export index 51feb63bc..2178966f9 100644 --- a/include/osg/Export +++ b/include/osg/Export @@ -26,6 +26,7 @@ #pragma warning( disable : 4275 ) #pragma warning( disable : 4290 ) #pragma warning( disable : 4786 ) + #pragma warning( disable : 4305 ) #endif #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) diff --git a/include/osgDB/Export b/include/osgDB/Export index f77434394..5de7c4ce9 100644 --- a/include/osgDB/Export +++ b/include/osgDB/Export @@ -21,6 +21,7 @@ #pragma warning( disable : 4275 ) #pragma warning( disable : 4290 ) #pragma warning( disable : 4786 ) + #pragma warning( disable : 4305 ) #endif #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) diff --git a/include/osgGA/Export b/include/osgGA/Export index 4b719121c..5e2c4d9c7 100644 --- a/include/osgGA/Export +++ b/include/osgGA/Export @@ -22,6 +22,7 @@ #pragma warning( disable : 4275 ) #pragma warning( disable : 4290 ) #pragma warning( disable : 4786 ) + #pragma warning( disable : 4305 ) #endif #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) diff --git a/include/osgParticle/Export b/include/osgParticle/Export index 0edb8c4f0..97ab4c878 100644 --- a/include/osgParticle/Export +++ b/include/osgParticle/Export @@ -21,6 +21,7 @@ #pragma warning( disable : 4275 ) #pragma warning( disable : 4786 ) #pragma warning( disable : 4290 ) + #pragma warning( disable : 4305 ) #endif diff --git a/include/osgProducer/Export b/include/osgProducer/Export index 52f3c6bb0..f9f3b98c7 100644 --- a/include/osgProducer/Export +++ b/include/osgProducer/Export @@ -22,6 +22,7 @@ #pragma warning( disable : 4275 ) #pragma warning( disable : 4290 ) #pragma warning( disable : 4786 ) + #pragma warning( disable : 4305 ) #endif #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) diff --git a/include/osgSim/Export b/include/osgSim/Export index f88da09bc..d39986469 100644 --- a/include/osgSim/Export +++ b/include/osgSim/Export @@ -20,6 +20,7 @@ #pragma warning( disable : 4275 ) #pragma warning( disable : 4786 ) #pragma warning( disable : 4290 ) + #pragma warning( disable : 4305 ) #endif #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) diff --git a/include/osgText/Export b/include/osgText/Export index e16898895..c161138af 100644 --- a/include/osgText/Export +++ b/include/osgText/Export @@ -21,6 +21,7 @@ #pragma warning( disable : 4275 ) #pragma warning( disable : 4290 ) #pragma warning( disable : 4786 ) + #pragma warning( disable : 4305 ) #endif #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) diff --git a/include/osgUtil/Export b/include/osgUtil/Export index 9302ef507..ba0fdb07a 100644 --- a/include/osgUtil/Export +++ b/include/osgUtil/Export @@ -22,6 +22,7 @@ #pragma warning( disable : 4275 ) #pragma warning( disable : 4290 ) #pragma warning( disable : 4786 ) + #pragma warning( disable : 4305 ) #endif #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)