From e95768417ce24132d75410e3749365398c53d7de Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 23 Jul 2003 14:06:32 +0000 Subject: [PATCH] From Gideon May, added support for osgSim into .osg file format. --- Make/makedirdefs | 1 + VisualStudio/VisualStudio.dsw | 22 ++ VisualStudio/osgPlugins/osgSim/dot_osgSim.dsp | 242 ++++++++++++++++++ dist/RPM/OpenSceneGraph.spec | 1 + include/osgSim/BlinkSequence | 27 +- include/osgSim/LightPointNode | 6 +- include/osgSim/Sector | 3 + src/osgPlugins/osgSim/IO_BlinkSequence.cpp | 120 +++++++++ src/osgPlugins/osgSim/IO_LightPoint.cpp | 119 +++++++++ src/osgPlugins/osgSim/IO_LightPoint.h | 11 + src/osgPlugins/osgSim/IO_LightPointNode.cpp | 98 +++++++ src/osgPlugins/osgSim/IO_Sector.cpp | 223 ++++++++++++++++ src/osgSim/BlinkSequence.cpp | 6 + src/osgSim/LightPointNode.cpp | 8 +- src/osgSim/Sector.cpp | 32 +++ 15 files changed, 905 insertions(+), 14 deletions(-) create mode 100644 VisualStudio/osgPlugins/osgSim/dot_osgSim.dsp create mode 100644 src/osgPlugins/osgSim/IO_BlinkSequence.cpp create mode 100644 src/osgPlugins/osgSim/IO_LightPoint.cpp create mode 100644 src/osgPlugins/osgSim/IO_LightPoint.h create mode 100644 src/osgPlugins/osgSim/IO_LightPointNode.cpp create mode 100644 src/osgPlugins/osgSim/IO_Sector.cpp diff --git a/Make/makedirdefs b/Make/makedirdefs index 8cc3ceff8..e633c0d6a 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -38,6 +38,7 @@ PLUGIN_DIRS = \ obj\ osgParticle\ osgText\ + osgSim\ osg\ osgtgz\ pic\ diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 9874e5fe1..5093b2532 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -1711,6 +1711,28 @@ Package=<4> End Project Dependency }}} + +############################################################################### + +Project: "osgPlugin osgSim"=.\osgPlugins\osgSim\dot_osgSim.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 osgSim + End Project Dependency +}}} + ############################################################################### Project: "osgPlugin osgtgz"=.\osgPlugins\osgtgz\osgtgz.dsp - Package Owner=<4> diff --git a/VisualStudio/osgPlugins/osgSim/dot_osgSim.dsp b/VisualStudio/osgPlugins/osgSim/dot_osgSim.dsp new file mode 100644 index 000000000..64bec2baa --- /dev/null +++ b/VisualStudio/osgPlugins/osgSim/dot_osgSim.dsp @@ -0,0 +1,242 @@ +# Microsoft Developer Studio Project File - Name="osgPlugin osgSim" - Package Owner=<4> + +# Microsoft Developer Studio Generated Build File, Format Version 6.00 + +# ** DO NOT EDIT ** + + + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + + + +CFG=osgPlugin osgSim - 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 "dot_osgSim.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 "dot_osgSim.mak" CFG="osgPlugin osgSim - Win32 Release" + +!MESSAGE + +!MESSAGE Possible choices for configuration are: + +!MESSAGE + +!MESSAGE "osgPlugin osgSim - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") + +!MESSAGE "osgPlugin osgSim - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") + +!MESSAGE + + + +# Begin Project + +# PROP AllowPerConfigDependencies 0 + +# PROP Scc_ProjName "" + +# PROP Scc_LocalPath "" + +CPP=cl.exe + +MTL=midl.exe + +RSC=rc.exe + + + +!IF "$(CFG)" == "osgPlugin osgSim - 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 "../../../lib" + +# PROP Intermediate_Dir "Release" + +# PROP Ignore_Export_Lib 0 + +# PROP Target_Dir "" + +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c + +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c + +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 + +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 + +# 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 /dll /machine:I386 + +# ADD LINK32 /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_osgSim.dll" /libpath:"../../../lib" + +# SUBTRACT LINK32 /nodefaultlib + + + +!ELSEIF "$(CFG)" == "osgPlugin osgSim - 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 "../../../lib" + +# PROP Intermediate_Dir "Debug" + +# PROP Ignore_Export_Lib 0 + +# PROP Target_Dir "" + +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c + +# ADD CPP /nologo /MDd /W3 /Gm /vmg /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIN32" /D "_DEBUG" /YX /FD /GZ /c + +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 + +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 + +# 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 /dll /debug /machine:I386 /pdbtype:sept + +# ADD LINK32 /nologo /dll /debug /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_osgSim.dll" /pdbtype:sept /libpath:"../../../lib" + +# SUBTRACT LINK32 /pdb:none /nodefaultlib + + + +!ENDIF + + + +# Begin Target + + + +# Name "osgPlugin osgSim - Win32 Release" + +# Name "osgPlugin osgSim - Win32 Debug" + +# Begin Group "Source Files" + + + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" + +# Begin Source File + + + +SOURCE=..\..\..\src\osgPlugins\osgSim\IO_LightPointNode.cpp + +# End Source File + +# Begin Source File + + + +SOURCE=..\..\..\src\osgPlugins\osgSim\IO_LightPoint.cpp + +# End Source File + +# Begin Source File + + + +SOURCE=..\..\..\src\osgPlugins\osgSim\IO_Sector.cpp + +# End Source File + +# Begin Source File + + + +SOURCE=..\..\..\src\osgPlugins\osgSim\IO_BlinkSequence.cpp + +# End Source File + +# End Group + +# Begin Group "Header Files" + + + +# PROP Default_Filter "h;hpp;hxx;hm;inl" + +# End Group + +# Begin Group "Resource Files" + + + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" + +# End Group + +# End Target + +# End Project + diff --git a/dist/RPM/OpenSceneGraph.spec b/dist/RPM/OpenSceneGraph.spec index 23f08afae..532cdfccd 100644 --- a/dist/RPM/OpenSceneGraph.spec +++ b/dist/RPM/OpenSceneGraph.spec @@ -57,6 +57,7 @@ tar cvf - . | tar xvfC - / %attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_osgParticle.so %attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_osg.so %attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_osgText.so +%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_osgSim.so %attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_osgtgz.so %attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_pfb.so %attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_pic.so diff --git a/include/osgSim/BlinkSequence b/include/osgSim/BlinkSequence index 9ec2ee1ab..ffcf8e582 100644 --- a/include/osgSim/BlinkSequence +++ b/include/osgSim/BlinkSequence @@ -30,13 +30,16 @@ class OSGSIM_EXPORT BlinkSequence : public osg::Object public: /** sequence group which can be used to synchronize related blink sequences.*/ - class OSGSIM_EXPORT SequenceGroup : public osg::Referenced + class OSGSIM_EXPORT SequenceGroup : public osg::Object { public: SequenceGroup(); + SequenceGroup(const SequenceGroup& bs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); SequenceGroup(double baseTime); + META_Object(osgSim,SequenceGroup); + double _baseTime; }; @@ -44,22 +47,27 @@ class OSGSIM_EXPORT BlinkSequence : public osg::Object BlinkSequence(); BlinkSequence(const BlinkSequence& bs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); - + META_Object(osgSim,BlinkSequence); - /** add a pulse of specified color and duration to the BlinkSequence.*/ inline void addPulse(double length,const osg::Vec4& color); + /** return the number of pulses. */ + inline int getNumPulses() const { return _pulseData.size(); } + + /** return the pulse data at position i. */ + inline void getPulse(unsigned int i, double& length,osg::Vec4& color) const; + /** get the total pulse period of the blink sequence, which is equal to the sum of all the pulse periods.*/ inline double getPulsePeriod() const { return _pulsePeriod; } /** set the sequence group which can be used to synchronize related blink sequences.*/ inline void setSequenceGroup(SequenceGroup* sg) { _sequenceGroup = sg; } - + /** get the non const sequence group.*/ inline SequenceGroup* getSequenceGroup() { return _sequenceGroup.get(); } - + /** get the const sequence group.*/ inline const SequenceGroup* getSequenceGroup() const { return _sequenceGroup.get(); } @@ -68,8 +76,6 @@ class OSGSIM_EXPORT BlinkSequence : public osg::Object /** get the pahse shift.*/ inline double getPhaseShift() const { return _phaseShift; } - - /** compute the local time clamped to this BlinkSequences period, and accounting for the phase shift and sequence group.*/ inline double localTime(double time) const; @@ -104,6 +110,13 @@ inline void BlinkSequence::addPulse(double length,const osg::Vec4& color) _pulsePeriod += length; } +inline void BlinkSequence::getPulse(unsigned int i, double& length, osg::Vec4& color) const +{ + const IntervalColor& ic = _pulseData[i]; + length = ic.first; + color = ic.second; +} + inline osg::Vec4 BlinkSequence::color(double time,double length) const { if (_pulseData.empty()) return osg::Vec4(1.0f,1.0f,1.0f,1.0f); diff --git a/include/osgSim/LightPointNode b/include/osgSim/LightPointNode index 0e3032507..3d87236ac 100644 --- a/include/osgSim/LightPointNode +++ b/include/osgSim/LightPointNode @@ -73,9 +73,9 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node float getMaxPixelSize() const { return _maxPixelSize; } - void setMaxVisableDistance2(float maxVisableDistance2) { _maxVisableDistance2 = maxVisableDistance2; } + void setMaxVisibleDistance2(float maxVisibleDistance2) { _maxVisibleDistance2 = maxVisibleDistance2; } - float setMaxVisableDistance2() const { return _maxVisableDistance2; } + float getMaxVisibleDistance2() const { return _maxVisibleDistance2; } protected: @@ -91,7 +91,7 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node float _minPixelSize; float _maxPixelSize; - float _maxVisableDistance2; + float _maxVisibleDistance2; }; diff --git a/include/osgSim/Sector b/include/osgSim/Sector index d52dbc4de..369138e1c 100644 --- a/include/osgSim/Sector +++ b/include/osgSim/Sector @@ -54,6 +54,7 @@ class OSGSIM_EXPORT AzimRange _cosFadeAngle(-1.0f) {} void setAzimuthRange(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f); + void getAzimuthRange(float& minAzimuth, float& maxAzimuth, float& fadeAngle) const; inline float azimSector(const osg::Vec3& eyeLocal) const @@ -91,6 +92,8 @@ class OSGSIM_EXPORT ElevationRange float getMaxElevation() const; + float getFadeAngle() const; + inline float elevationSector(const osg::Vec3& eyeLocal) const { float dotproduct = eyeLocal.z(); // against z axis - eyeLocal*(0,0,1). diff --git a/src/osgPlugins/osgSim/IO_BlinkSequence.cpp b/src/osgPlugins/osgSim/IO_BlinkSequence.cpp new file mode 100644 index 000000000..f73179493 --- /dev/null +++ b/src/osgPlugins/osgSim/IO_BlinkSequence.cpp @@ -0,0 +1,120 @@ +#include + +#include +#include + +#include +#include +#include +#include + +using namespace osgSim; + +bool BlinkSequence_readLocalData(osg::Object &obj, osgDB::Input &fr); +bool BlinkSequence_writeLocalData(const osg::Object &obj, osgDB::Output &fw); + +osgDB::RegisterDotOsgWrapperProxy BlinkSequence_Proxy +( + new BlinkSequence, + "BlinkSequence", + "Object BlinkSequence", + &BlinkSequence_readLocalData, + &BlinkSequence_writeLocalData, + osgDB::DotOsgWrapper::READ_AND_WRITE +); + +bool BlinkSequence_readLocalData(osg::Object &obj, osgDB::Input &fr) +{ + bool iteratorAdvanced = false; + BlinkSequence &seq = static_cast(obj); + + if (fr.matchSequence("phaseShift %f")) + { + double ps; + fr[1].getDouble(ps); + fr += 2; + seq.setPhaseShift(ps); + iteratorAdvanced = true; + } + if (fr.matchSequence("pulse %f %f %f %f %f")) + { + double length; + float r, g, b, a; + fr[1].getDouble(length); + fr[2].getFloat(r); + fr[3].getFloat(g); + fr[4].getFloat(b); + fr[5].getFloat(a); + fr += 6; + + seq.addPulse(length, osg::Vec4(r, g, b, a)); + iteratorAdvanced = true; + } + + BlinkSequence::SequenceGroup * sg = static_cast + (fr.readObjectOfType(osgDB::type_wrapper())); + + if (sg) { + seq.setSequenceGroup(sg); + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool BlinkSequence_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + const BlinkSequence &seq = static_cast(obj); + + fw.indent()<<"phaseShift "<< seq.getPhaseShift() << std::endl; + + if (seq.getSequenceGroup() != NULL) { + fw.writeObject(*seq.getSequenceGroup()); + } + for (int i=0; i(obj); + + if (fr.matchSequence("baseTime %f")) + { + fr[1].getDouble(sg._baseTime); + fr += 2; + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool BlinkSequence_SequenceGroup_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + const BlinkSequence::SequenceGroup &sg = static_cast(obj); + + fw.indent()<<"baseTime "<< sg._baseTime << std::endl; + return true; +} diff --git a/src/osgPlugins/osgSim/IO_LightPoint.cpp b/src/osgPlugins/osgSim/IO_LightPoint.cpp new file mode 100644 index 000000000..31e60ff85 --- /dev/null +++ b/src/osgPlugins/osgSim/IO_LightPoint.cpp @@ -0,0 +1,119 @@ +#include +#include +#include "IO_LightPoint.h" + +using namespace osgSim; + +bool readLightPoint(LightPoint & lp, osgDB::Input &fr) +{ + if (fr.matchSequence("lightPoint {")) + { + fr += 2; + int entry = fr[0].getNoNestedBrackets(); + bool itAdvanced = true; + while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry && itAdvanced) { + itAdvanced = false; + if (fr[0].matchWord("isOn")) { + const char * ptstr = fr[1].getStr(); + if (ptstr) { + if (std::string(ptstr) == "TRUE") { + lp._on = true; + } else if (std::string(ptstr) == "FALSE") { + lp._on = false; + } else { + osg::notify(osg::WARN) << "osg::Sim reader warning: invalid isOn: " << ptstr << std::endl; + } + fr += 2; + itAdvanced = true; + } + } + if (fr[0].matchWord("position")) { + float x, y, z; + if (fr[1].getFloat(x) && fr[2].getFloat(y) && fr[3].getFloat(z)) { + lp._position.set(x, y, z); + fr += 4; + itAdvanced = true; + } + } + if (fr[0].matchWord("color")) { + float r, g, b, a; + if (fr[1].getFloat(r) && fr[2].getFloat(g) && fr[3].getFloat(b) && fr[4].getFloat(a)) { + lp._color.set(r, g, b, a); + fr += 5; + itAdvanced = true; + } + } + if (fr[0].matchWord("intensity")) { + if (fr[1].getFloat(lp._intensity)) { + fr += 2; + itAdvanced = true; + } + } + if (fr[0].matchWord("radius")) { + if (fr[1].getFloat(lp._radius)) { + fr += 2; + itAdvanced = true; + } + } + if (fr[0].matchWord("blendingMode")) { + const char * ptstr = fr[1].getStr(); + if (ptstr) { + if (std::string(ptstr) == "ADDITIVE") { + lp._blendingMode = LightPoint::ADDITIVE; + fr += 2; + itAdvanced = true; + } else if (std::string(ptstr) == "BLENDED") { + lp._blendingMode = LightPoint::BLENDED; + fr += 2; + itAdvanced = true; + } else { + osg::notify(osg::WARN) << "osg::Sim reader warning: invalid blendingMode: " << ptstr << std::endl; + } + } + } + Sector * sector = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); + if (sector) { + lp._sector = sector; + itAdvanced = true; + } + BlinkSequence * seq = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); + if (seq) { + lp._blinkSequence = seq; + itAdvanced = true; + } + } + return true; + } + return false; +} + +bool writeLightPoint(const LightPoint & lp, osgDB::Output &fw) +{ + fw.indent() << "lightPoint {" << std::endl; + fw.moveIn(); + fw.indent() << "isOn " << ( lp._on ? "TRUE" : "FALSE") << std::endl; + fw.indent() << "position " << lp._position << std::endl; + fw.indent() << "color " << lp._color << std::endl; + fw.indent() << "intensity " << lp._intensity << std::endl; + fw.indent() << "radius " << lp._radius << std::endl; + fw.indent() << "blendingMode "; + switch (lp._blendingMode) { + case LightPoint::ADDITIVE: + fw << "ADDITIVE" << std::endl; + break; + case LightPoint::BLENDED: + default : + fw << "BLENDED" << std::endl; + break; + } + if (lp._sector.valid()) { + fw.writeObject(*lp._sector); + } + if (lp._blinkSequence.valid()) { + fw.writeObject(*lp._blinkSequence); + } + + fw.moveOut(); + fw.indent() << "}" << std::endl; + return true; +} diff --git a/src/osgPlugins/osgSim/IO_LightPoint.h b/src/osgPlugins/osgSim/IO_LightPoint.h new file mode 100644 index 000000000..1264fd3d0 --- /dev/null +++ b/src/osgPlugins/osgSim/IO_LightPoint.h @@ -0,0 +1,11 @@ +#ifndef DOTOSGSIM_LIGHTPOINT +#define DOTOSGSIM_LIGHTPOINT + +#include +#include +#include + +extern bool readLightPoint(osgSim::LightPoint & lp, osgDB::Input &fr); +extern bool writeLightPoint(const osgSim::LightPoint & lp, osgDB::Output &fw); + +#endif diff --git a/src/osgPlugins/osgSim/IO_LightPointNode.cpp b/src/osgPlugins/osgSim/IO_LightPointNode.cpp new file mode 100644 index 000000000..119c719e6 --- /dev/null +++ b/src/osgPlugins/osgSim/IO_LightPointNode.cpp @@ -0,0 +1,98 @@ +#include +#include +#include + +#include "IO_LightPoint.h" + +#include +#include + +#include +#include +#include +#include + +using namespace osgSim; + +bool LightPointNode_readLocalData(osg::Object &obj, osgDB::Input &fr); +bool LightPointNode_writeLocalData(const osg::Object &obj, osgDB::Output &fw); + +osgDB::RegisterDotOsgWrapperProxy LightPointNode_Proxy +( + new LightPointNode, + "LightPointNode", + "Object Node LightPointNode", + &LightPointNode_readLocalData, + &LightPointNode_writeLocalData +); + +bool LightPointNode_readLocalData(osg::Object &obj, osgDB::Input &fr) +{ + LightPointNode &lightpointnode = static_cast(obj); + bool itAdvanced = false; + + if (fr.matchSequence("num_lightpoints %d")) { + // Could allocate space for lightpoints here + fr += 2; + itAdvanced = true; + } + + if (fr.matchSequence("minPixelSize %f")) { + float size = 0.0f; + fr[1].getFloat(size); + lightpointnode.setMinPixelSize(size); + + fr += 2; + itAdvanced = true; + } + + if (fr.matchSequence("maxPixelSize %f")) { + float size = 30.0f; + fr[1].getFloat(size); + lightpointnode.setMaxPixelSize(size); + + fr += 2; + itAdvanced = true; + } + + if (fr.matchSequence("maxVisibleDistance2 %f")) { + float distance = FLT_MAX; + fr[1].getFloat(distance); + lightpointnode.setMaxVisibleDistance2(distance); + + fr += 2; + itAdvanced = true; + } + + if (fr[0].matchWord("lightPoint")) { + LightPoint lp; + if (readLightPoint(lp, fr)) { + lightpointnode.addLightPoint(lp); + itAdvanced = true; + } + } + + return itAdvanced; +} + +bool LightPointNode_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + const LightPointNode &lightpointnode = static_cast(obj); + + fw.indent() << "num_lightpoints " << lightpointnode.getNumLightPoints() << std::endl; + + fw.indent() << "minPixelSize " << lightpointnode.getMinPixelSize() << std::endl; + + fw.indent() << "maxPixelSize " << lightpointnode.getMaxPixelSize() << std::endl; + + fw.indent() << "maxVisibleDistance2 " << lightpointnode.getMaxVisibleDistance2() << std::endl; + + LightPointNode::LightPointList const lightpointlist = lightpointnode.getLightPointList(); + LightPointNode::LightPointList::const_iterator itr; + + for (itr = lightpointlist.begin(); itr != lightpointlist.end(); itr++) { + writeLightPoint((*itr), fw); + } + + return true; +} diff --git a/src/osgPlugins/osgSim/IO_Sector.cpp b/src/osgPlugins/osgSim/IO_Sector.cpp new file mode 100644 index 000000000..e848a757a --- /dev/null +++ b/src/osgPlugins/osgSim/IO_Sector.cpp @@ -0,0 +1,223 @@ +#include + +#include +#include + +#include +#include +#include +#include + +bool AzimSector_readLocalData(osg::Object &obj, osgDB::Input &fr); +bool AzimSector_writeLocalData(const osg::Object &obj, osgDB::Output &fw); + +osgDB::RegisterDotOsgWrapperProxy AzimSector_Proxy +( + new osgSim::AzimSector, + "AzimSector", + "Object AzimSector", + &AzimSector_readLocalData, + &AzimSector_writeLocalData, + osgDB::DotOsgWrapper::READ_AND_WRITE +); + +bool AzimSector_readLocalData(osg::Object &obj, osgDB::Input &fr) +{ + bool iteratorAdvanced = false; + osgSim::AzimSector §or = static_cast(obj); + + if (fr.matchSequence("azimuthRange %f %f %f")) + { + float minAzimuth; + float maxAzimuth; + float fadeRange; + fr[1].getFloat(minAzimuth); + fr[2].getFloat(maxAzimuth); + fr[3].getFloat(fadeRange); + fr += 4; + sector.setAzimuthRange(minAzimuth, maxAzimuth, fadeRange); + iteratorAdvanced = true; + } + return iteratorAdvanced; +} + +bool AzimSector_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + float minAzimuth, maxAzimuth, fadeAngle; + + const osgSim::AzimSector §or = static_cast(obj); + sector.getAzimuthRange(minAzimuth, maxAzimuth, fadeAngle); + fw.indent()<<"azimuthRange "<(obj); + + if (fr.matchSequence("elevationRange %f %f %f")) + { + float minElevation; + float maxElevation; + float fadeAngle; + + fr[1].getFloat(minElevation); + fr[2].getFloat(maxElevation); + fr[3].getFloat(fadeAngle); + fr += 4; + sector.setElevationRange(minElevation, maxElevation, fadeAngle); + iteratorAdvanced = true; + } + return iteratorAdvanced; +} + +bool ElevationSector_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + + const osgSim::ElevationSector §or = static_cast(obj); + + float minElevation = sector.getMinElevation(); + float maxElevation = sector.getMaxElevation(); + float fadeAngle = sector.getFadeAngle(); + fw.indent()<<"elevationRange "<(obj); + + if (fr.matchSequence("azimuthRange %f %f %f")) + { + float minAzimuth; + float maxAzimuth; + float fadeAngle; + fr[1].getFloat(minAzimuth); + fr[2].getFloat(maxAzimuth); + fr[3].getFloat(fadeAngle); + fr += 4; + sector.setAzimuthRange(minAzimuth, maxAzimuth, fadeAngle); + iteratorAdvanced = true; + } + if (fr.matchSequence("elevationRange %f %f %f")) + { + float minElevation; + float maxElevation; + float fadeAngle; + + fr[1].getFloat(minElevation); + fr[2].getFloat(maxElevation); + fr[3].getFloat(fadeAngle); + fr += 4; + sector.setElevationRange(minElevation, maxElevation, fadeAngle); + iteratorAdvanced = true; + } + return iteratorAdvanced; +} + +bool AzimElevationSector_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + + const osgSim::AzimElevationSector §or = static_cast(obj); + + float minElevation = sector.getMinElevation(); + float maxElevation = sector.getMaxElevation(); + float fadeAngle = sector.getFadeAngle(); + fw.indent()<<"elevationRange "<(obj); + + if (fr.matchSequence("axis %f %f %f")) + { + float x, y, z; + + fr[1].getFloat(x); + fr[2].getFloat(y); + fr[3].getFloat(z); + fr += 4; + sector.setAxis(osg::Vec3(x, y, z)); + iteratorAdvanced = true; + } + if (fr.matchSequence("angle %f %f")) + { + float angle; + float fadeangle; + fr[1].getFloat(angle); + fr[2].getFloat(fadeangle); + fr += 3; + sector.setAngle(angle, fadeangle); + iteratorAdvanced; + } + return iteratorAdvanced; +} + +bool ConeSector_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + const osgSim::ConeSector §or = static_cast(obj); + + const osg::Vec3& axis = sector.getAxis(); + fw.indent()<<"axis "<_maxVisableDistance2) continue; + if (dv.length2()>_maxVisibleDistance2) continue; } diff --git a/src/osgSim/Sector.cpp b/src/osgSim/Sector.cpp index 65c5f6e63..85c6a5523 100644 --- a/src/osgSim/Sector.cpp +++ b/src/osgSim/Sector.cpp @@ -42,6 +42,19 @@ void AzimRange::setAzimuthRange(float minAzimuth,float maxAzimuth,float fadeAngl } +void AzimRange::getAzimuthRange(float& minAzimuth, float& maxAzimuth, float& fadeAngle) const +{ + float centerAzim = atan2(_sinAzim, _cosAzim); + float angle = acos(_cosAngle); + minAzimuth = centerAzim - angle; + maxAzimuth = centerAzim + angle; + if (_cosFadeAngle == -1.0f) { + fadeAngle = 2.0f * osg::PI; + } else { + fadeAngle = acos(_cosFadeAngle) - angle; + } +} + // // Elevation Range @@ -83,6 +96,25 @@ float ElevationRange::getMaxElevation() const return osg::PI_2-acos(_cosMaxElevation); } +float ElevationRange::getFadeAngle() const +{ + float fadeAngle = 0.0; + + // Take the appropriate (unclipped) elevation angle to calculate the fade angle + if (_cosMinFadeElevation != -1.0f) { + float minFadeAngle = acos(_cosMinFadeElevation); + float minElevation = osg::PI_2 - acos(_cosMinElevation); + fadeAngle = minFadeAngle + minElevation - osg::PI_2; + + } else if (_cosMaxFadeElevation != 1.0f) { + float maxFadeAngle = acos(_cosMaxFadeElevation); + float maxElevation = osg::PI_2 - acos(_cosMaxElevation); + fadeAngle = osg::PI_2 - maxFadeAngle - maxElevation; + } + + return fadeAngle; +} + // // ElevationSector //