From ae5e4f848f7441f59643cee0ffbc8c53f0478274 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 28 May 2002 23:43:22 +0000 Subject: [PATCH] Added new osgcallback demo, and updated small API changes to improve the flexiblity of callbacks. Added beginings of convex planer occlusions culling. --- Make/makedirdefs | 1 + .../Demos/osgcallback/osgcallback.dsp | 95 +++++++ VisualStudio/VisualStudio.dsw | 26 ++ VisualStudio/osg/osg.dsp | 24 ++ include/osg/Billboard | 8 +- include/osg/ConvexPlanerOccluder | 61 +++++ include/osg/ConvexPlanerPolygon | 57 ++++ include/osg/Drawable | 6 +- include/osg/Geode | 15 +- include/osg/LOD | 9 +- include/osg/PositionAttitudeTransform | 6 +- include/osg/ShadowOccluderVolume | 56 ++++ include/osg/Transform | 22 +- src/Demos/osgcallback/Makefile | 16 ++ src/Demos/osgcallback/Makefile.inst | 12 + src/Demos/osgcallback/osgcallback.cpp | 251 ++++++++++++++++++ src/osg/ConvexPlanerOccluder.cpp | 3 + src/osg/ConvexPlanerPolygon.cpp | 4 + src/osg/Drawable.cpp | 7 +- src/osg/Geode.cpp | 6 + src/osg/Makefile | 3 + src/osg/ShadowOccluderVolume.cpp | 3 + 22 files changed, 658 insertions(+), 33 deletions(-) create mode 100755 VisualStudio/Demos/osgcallback/osgcallback.dsp create mode 100644 include/osg/ConvexPlanerOccluder create mode 100644 include/osg/ConvexPlanerPolygon create mode 100644 include/osg/ShadowOccluderVolume create mode 100644 src/Demos/osgcallback/Makefile create mode 100644 src/Demos/osgcallback/Makefile.inst create mode 100644 src/Demos/osgcallback/osgcallback.cpp create mode 100644 src/osg/ConvexPlanerOccluder.cpp create mode 100644 src/osg/ConvexPlanerPolygon.cpp create mode 100644 src/osg/ShadowOccluderVolume.cpp diff --git a/Make/makedirdefs b/Make/makedirdefs index 1ff586505..91e83f387 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -66,6 +66,7 @@ PLUGIN_DIRS += tiff DEMOS_DIRS = \ hangglide\ osgbillboard\ + osgcallback\ osgclip\ osgcluster\ osgconv\ diff --git a/VisualStudio/Demos/osgcallback/osgcallback.dsp b/VisualStudio/Demos/osgcallback/osgcallback.dsp new file mode 100755 index 000000000..aed13c56e --- /dev/null +++ b/VisualStudio/Demos/osgcallback/osgcallback.dsp @@ -0,0 +1,95 @@ +# Microsoft Developer Studio Project File - Name="Demo osgcallback" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Demo osgcallback - 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 "osgcallback.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 "osgcallback.mak" CFG="Demo osgcallback - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Demo osgcallback - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Demo osgcallback - 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 osgcallback - 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/osgcallback.exe" /libpath:"../../../lib" + +!ELSEIF "$(CFG)" == "Demo osgcallback - 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/osgcallbackd.exe" /pdbtype:sept /libpath:"../../../lib" +# SUBTRACT LINK32 /incremental:no + +!ENDIF + +# Begin Target + +# Name "Demo osgcallback - Win32 Release" +# Name "Demo osgcallback - Win32 Debug" +# Begin Source File + +SOURCE=..\..\..\src\Demos\osgcallback\osgcallback.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 480541a6b..720c5329a 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -180,6 +180,32 @@ Package=<4> ############################################################################### +Project: "Demo osgcallback"=".\Demos\osgcallback\osgcallback.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 osgcopy"=".\Demos\osgcopy\osgcopy.dsp" - Package Owner=<4> Package=<5> diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index ab5739055..daaf0a2d8 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -133,6 +133,14 @@ SOURCE=..\..\src\osg\ColorMatrix.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\ConvexPlanerOccluder.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\src\osg\ConvexPlanerPolygon.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\CopyOp.cpp # End Source File # Begin Source File @@ -293,6 +301,10 @@ SOURCE=..\..\src\osg\ShadeModel.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\ShadowOccluderVolume.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\State.cpp # End Source File # Begin Source File @@ -393,6 +405,14 @@ SOURCE=..\..\Include\Osg\ClipPlane # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\ConvexPlanerOccluder +# End Source File +# Begin Source File + +SOURCE=..\..\Include\Osg\ConvexPlanerPolygon +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\ColorMask # End Source File # Begin Source File @@ -597,6 +617,10 @@ SOURCE=..\..\Include\Osg\ShadeModel # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\ShadowOccluderVolume +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\State # End Source File # Begin Source File diff --git a/include/osg/Billboard b/include/osg/Billboard index fb57066a0..9c0a01ac1 100644 --- a/include/osg/Billboard +++ b/include/osg/Billboard @@ -83,10 +83,8 @@ class SG_EXPORT Billboard : public Geode struct ComputeBillboardCallback : public osg::Referenced { /** Get the transformation matrix which moves from local coords to world coords.*/ - virtual const bool computeMatrix(const Matrix& modelview, const Billboard* billboard, const Vec3& eye_local, const Vec3& pos_local) const; + virtual const bool computeMatrix(Matrix& modelview, const Billboard* billboard, const Vec3& eye_local, const Vec3& pos_local) const = 0; }; - - friend struct osg::Billboard::ComputeBillboardCallback; /** Set the ComputeBillboardCallback which allows users to attach custom computation of the local transformation as * seen by cull traversers and alike.*/ @@ -107,14 +105,14 @@ class SG_EXPORT Billboard : public Geode return computeMatrix(modelview,eye_local,pos_local); } + virtual const bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const; + protected: virtual ~Billboard(); virtual const bool computeBound() const; - virtual const bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const; - enum AxisAligned { AXIAL_ROT_X_AXIS=AXIAL_ROT+1, diff --git a/include/osg/ConvexPlanerOccluder b/include/osg/ConvexPlanerOccluder new file mode 100644 index 000000000..5e8490bbe --- /dev/null +++ b/include/osg/ConvexPlanerOccluder @@ -0,0 +1,61 @@ +//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield +//Distributed under the terms of the GNU Library General Public License (LGPL) +//as published by the Free Software Foundation. + +#ifndef OSG_CONVEXPLANEROCCLUDER +#define OSG_CONVEXPLANEROCCLUDER 1 + +#include +#include + +namespace osg { + +class OccluderVolume; + +/** A ClippingVolume class for representing convex clipping volumes made up. + * When adding planes, their normals should point inwards (into the volume) */ +class SG_EXPORT ConvexPlanerOccluder : public Referenced +{ + + public: + + inline ConvexPlanerOccluder() {} + + + + void setOccluder(const ConvexPlanerPolygon& cpp) { _occluder = cpp; } + + ConvexPlanerPolygon& getOccluder() { return _occluder; } + + const ConvexPlanerPolygon& getOccluder() const { return _occluder; } + + + + typedef std::vector HoleList; + + void addHole(const ConvexPlanerPolygon& cpp) { _holeList.push_back(cpp); } + + HoleList& getHoleList() { return _holeList; } + + const HoleList& getHoleList() const { return _holeList; } + + void computeAttributes(); + + void computeBound(BoundingBox& bb) const; + + void computeBound(BoundingSphere& bs) const; + + protected: + + float _area; + Vec3 _center; + Vec3 _normal; + + ConvexPlanerPolygon _occluder; + HoleList _holeList; + +}; + +} // end of namespace + +#endif diff --git a/include/osg/ConvexPlanerPolygon b/include/osg/ConvexPlanerPolygon new file mode 100644 index 000000000..4b7b5fcc1 --- /dev/null +++ b/include/osg/ConvexPlanerPolygon @@ -0,0 +1,57 @@ +//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield +//Distributed under the terms of the GNU Library General Public License (LGPL) +//as published by the Free Software Foundation. + +#ifndef OSG_CONVEXPLANERPOLYGON +#define OSG_CONVEXPLANERPOLYGON 1 + +#include + +#include + +namespace osg { + +class BoundingBox; +class BoundingSphere; + +/** A ClippingVolume class for representing convex clipping volumes made up. + * When adding planes, their normals should point inwards (into the volume) */ +class SG_EXPORT ConvexPlanerPolygon +{ + + public: + + inline ConvexPlanerPolygon() {} + + float area() { return _area; } + + const Vec3& center() { return _center; } + + const Vec3& normal() { return _normal; } + + typedef std::vector VertexList; + + void add(const Vec3& v) { _vertexList.push_back(v); } + + VertexList& getVertexList() { return _vertexList; } + + const VertexList& getVertexList() const { return _vertexList; } + + void computeAttributes(); + + void computeBound(BoundingBox& bb) const; + + void computeBound(BoundingSphere& bs) const; + + protected: + + float _area; + Vec3 _center; + Vec3 _normal; + VertexList _vertexList; + +}; + +} // end of namespace + +#endif diff --git a/include/osg/Drawable b/include/osg/Drawable index e4a61ecfc..e9046e641 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -171,8 +171,6 @@ class SG_EXPORT Drawable : public Object /** do customized draw code.*/ virtual void drawImmediateMode(State& state,osg::Drawable* drawable) const = 0; }; - - friend struct osg::Drawable::DrawCallback; /** Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object.*/ void setDrawCallback(DrawCallback* dc) { _drawCallback=dc; dirtyDisplayList(); } @@ -186,10 +184,8 @@ class SG_EXPORT Drawable : public Object struct CullCallback : public osg::Referenced { /** do customized cull code.*/ - virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable) = 0; + virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable) const = 0; }; - - friend struct osg::Drawable::CullCallback; /** Set the CullCallback which allows users to attach customize the drawing of existing Drawable object.*/ void setCullCallback(CullCallback* cc) { _cullCallback=cc; } diff --git a/include/osg/Geode b/include/osg/Geode index 40922955e..2f21bcb5c 100644 --- a/include/osg/Geode +++ b/include/osg/Geode @@ -8,6 +8,7 @@ #include #include #include +#include namespace osg { @@ -107,6 +108,17 @@ class SG_EXPORT Geode : public Node /** compile OpenGL Display List for each geoset.*/ void compileDrawables(State& state); + + + + /** Attach a ConvexPlanerOccluder to a Geode.*/ + void setOccluder(ConvexPlanerOccluder* occluder) { _occluder = occluder; } + + /** Get the ConvexPlanerOccluder* attached to a Geode. */ + ConvexPlanerOccluder* getOccluder() { return _occluder.get(); } + + /** Get the const ConvexPlanerOccluder* attached to a Geode.*/ + const ConvexPlanerOccluder* getOccluder() const { return _occluder.get(); } protected: @@ -114,7 +126,8 @@ class SG_EXPORT Geode : public Node virtual const bool computeBound() const; - DrawableList _drawables; + DrawableList _drawables; + ref_ptr _occluder; }; diff --git a/include/osg/LOD b/include/osg/LOD index 68863899c..754e0aa65 100644 --- a/include/osg/LOD +++ b/include/osg/LOD @@ -60,10 +60,8 @@ class SG_EXPORT LOD : public Group struct EvaluateLODCallback : public osg::Referenced { /** Compute the child to select.*/ - virtual const int evaluateLODChild(const osg::LOD* lod, const Vec3& eye_local, const float bias) const; + virtual const int evaluateLODChild(const osg::LOD* lod, const Vec3& eye_local, const float bias) const = 0; }; - - friend struct osg::LOD::EvaluateLODCallback; /** Set the EvaluateLODCallback which allows users to attach customize computation of the the selection of LOD children.*/ void setEvaluateLODCallback(EvaluateLODCallback* cbc) { _evaluateLODCallback=cbc; } @@ -74,8 +72,6 @@ class SG_EXPORT LOD : public Group /** Get the const ComputeBillboardCallback.*/ const EvaluateLODCallback* getEvaluateLODCallback() const { return _evaluateLODCallback.get(); } - - /** return the child to traverse. Selected by the distance between the eye point in local coordinates and the LOD center, multiplied by the bias.*/ @@ -88,10 +84,11 @@ class SG_EXPORT LOD : public Group } + virtual const int evaluateLODChild(const Vec3& eye_local,const float bias) const; + protected : virtual ~LOD() {} - virtual const int evaluateLODChild(const Vec3& eye_local,const float bias) const; typedef std::vector RangeList; RangeList _rangeList; diff --git a/include/osg/PositionAttitudeTransform b/include/osg/PositionAttitudeTransform index a4610fb30..b0ffc9db0 100644 --- a/include/osg/PositionAttitudeTransform +++ b/include/osg/PositionAttitudeTransform @@ -36,13 +36,13 @@ class SG_EXPORT PositionAttitudeTransform : public Transform const Quat& getAttitude() const { return _attitude; } - - protected : - virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const; virtual const bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const; + protected : + + Vec3 _position; Quat _attitude; diff --git a/include/osg/ShadowOccluderVolume b/include/osg/ShadowOccluderVolume new file mode 100644 index 000000000..229b3055c --- /dev/null +++ b/include/osg/ShadowOccluderVolume @@ -0,0 +1,56 @@ +//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield +//Distributed under the terms of the GNU Library General Public License (LGPL) +//as published by the Free Software Foundation. + +#ifndef OSG_SHADOWOCCLUDERVOLUME +#define OSG_SHADOWOCCLUDERVOLUME 1 + +#include +#include +#include + +namespace osg { + +/** ShadowOccluderVolume is a helper class for implementating shadow occlusion culling. */ +class SG_EXPORT ShadowOccluderVolume : public Referenced +{ + + public: + + + ShadowOccluderVolume(const ShadowOccluderVolume& soc,Matrix& MVP); + + ShadowOccluderVolume(const ConvexPlanerOccluder& occluder,Matrix& MVP); + + typedef std::vector ClippingHoleList; + + /** Convert shadow occluder into local coords by multiplying the + * clip space occluder by the ModelViewProjectionMatrix.*/ + void set(const ShadowOccluderVolume& soc,Matrix& MVP); + + /** Initialize a ShadowOccluderVolume to a ConvexPlanerOccluder + * transformed into clipspace.*/ + void set(const ConvexPlanerOccluder& occluder,Matrix& MVP); + + /** return true if the specified bounding sphere is contaned entirely + * within this shadow occluder volume.*/ + bool contains(const BoundingSphere& bs); + + /** return true if the specified bounding box is contained entirely + * within this shadow occluder volume.*/ + bool contains(const BoundingBox& bs); + + + + protected: + + // the original shadow occluder computed in clip space + ref_ptr _clipSpaceOccluder; + + ClippingVolume _occluderVolume; + ClippingHoleList _clippingHoleList; +}; + +} // end of namespace + +#endif diff --git a/include/osg/Transform b/include/osg/Transform index a3059c7a2..c86376702 100644 --- a/include/osg/Transform +++ b/include/osg/Transform @@ -69,8 +69,6 @@ class SG_EXPORT Transform : public Group /** Get the transformation matrix which moves from world coords to local coords.*/ virtual const bool computeWorldToLocalMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const = 0; }; - - friend struct osg::Transform::ComputeTransformCallback; /** Set the ComputerTransfromCallback which allows users to attach custom computation of the local transformation as * seen by cull traversers and alike.*/ @@ -118,16 +116,6 @@ class SG_EXPORT Transform : public Group /** postMult transform.*/ void postMult(const Matrix& mat) { _matrix->postMult(mat); _inverseDirty=true; computeInverse(); dirtyBound(); } - - protected : - - virtual ~Transform(); - - /** Override's Group's computeBound. - * There is no need to override in subclasses from osg::Transform since this computeBound() uses - * the underlying matrix (calling computeMatrix if required.) */ - virtual const bool computeBound() const; - virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const { if (_referenceFrame==RELATIVE_TO_PARENTS) @@ -153,6 +141,16 @@ class SG_EXPORT Transform : public Group } return true; } + + protected : + + virtual ~Transform(); + + /** Override's Group's computeBound. + * There is no need to override in subclasses from osg::Transform since this computeBound() uses + * the underlying matrix (calling computeMatrix if required.) */ + virtual const bool computeBound() const; + inline void computeInverse() const { diff --git a/src/Demos/osgcallback/Makefile b/src/Demos/osgcallback/Makefile new file mode 100644 index 000000000..011b48ff5 --- /dev/null +++ b/src/Demos/osgcallback/Makefile @@ -0,0 +1,16 @@ +TOPDIR = ../../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgcallback.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + Makefile.inst=Makefile + +EXEC = osgcallback + +include $(TOPDIR)/Make/makerules + diff --git a/src/Demos/osgcallback/Makefile.inst b/src/Demos/osgcallback/Makefile.inst new file mode 100644 index 000000000..1f8da0563 --- /dev/null +++ b/src/Demos/osgcallback/Makefile.inst @@ -0,0 +1,12 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgcallback.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osgcallback + + +include $(TOPDIR)/Make/makerules diff --git a/src/Demos/osgcallback/osgcallback.cpp b/src/Demos/osgcallback/osgcallback.cpp new file mode 100644 index 000000000..a24341072 --- /dev/null +++ b/src/Demos/osgcallback/osgcallback.cpp @@ -0,0 +1,251 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + + +#include + +void write_usage(std::ostream& out,const std::string& name) +{ + out << std::endl; + out <<"usage:"<< std::endl; + out <<" "<drawImmediateMode(state); + std::cout<<"draw call back - post drawImmediateMode"<evaluateLODChild"<evaluateLODChild(eye_local,bias); + std::cout<<"evaluateLODChild callback - post lod->evaluateLODChild"<computeLocalToWorldMatrix"<computeLocalToWorldMatrix(matrix,nv); + std::cout<<"computeLocalToWorldMatrix - post transform->computeLocalToWorldMatrix"<computeWorldToLocalMatrix"<computeWorldToLocalMatrix(matrix,nv); + std::cout<<"computeWorldToLocalMatrix - post transform->computeWorldToLocalMatrix"<computeMatrix"<computeMatrix(modelview,eye_local,pos_local); + std::cout<<"ComputeBillboardCallback - post billboard->computeMatrix"<setCullCallback(new DrawableCullCallback()); + geode.getDrawable(i)->setDrawCallback(new DrawableCallback()); + } + } + + virtual void apply(osg::Billboard& node) + { + node.setComputeBillboardCallback(new BillboardCallback()); + apply((osg::Geode&)node); + } + + virtual void apply(osg::Transform& node) + { + node.setComputeTransformCallback(new TransformCallback()); + apply((osg::Node&)node); + } + + virtual void apply(osg::LOD& node) + { + node.setEvaluateLODCallback(new LODCallback()); + apply((osg::Node&)node); + } +}; + +int main( int argc, char **argv ) +{ + + // initialize the GLUT + glutInit( &argc, argv ); + + if (argc<2) + { + write_usage(std::cout,argv[0]); + return 0; + } + + // create the commandline args. + std::vector commandLine; + for(int i=1;iaccept(icv); + + // add a viewport to the viewer and attach the scene graph. + viewer.addViewport( rootnode ); + + // register trackball, flight and drive. + viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); + viewer.registerCameraManipulator(new osgUtil::FlightManipulator); + viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + + // open the viewer window. + viewer.open(); + + // fire up the event loop. + viewer.run(); + + return 0; +} diff --git a/src/osg/ConvexPlanerOccluder.cpp b/src/osg/ConvexPlanerOccluder.cpp new file mode 100644 index 000000000..122999c9a --- /dev/null +++ b/src/osg/ConvexPlanerOccluder.cpp @@ -0,0 +1,3 @@ +#include + +using namespace osg; diff --git a/src/osg/ConvexPlanerPolygon.cpp b/src/osg/ConvexPlanerPolygon.cpp new file mode 100644 index 000000000..a750cd86a --- /dev/null +++ b/src/osg/ConvexPlanerPolygon.cpp @@ -0,0 +1,4 @@ +#include + +using namespace osg; + diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 10252145d..e8f80703f 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -103,7 +103,12 @@ void Drawable::compile(State& state) globj = glGenLists( 1 ); glNewList( globj, GL_COMPILE ); - drawImmediateMode(state); + + if (_drawCallback.valid()) + _drawCallback->drawImmediateMode(state,this); + else + drawImmediateMode(state); + glEndList(); } diff --git a/src/osg/Geode.cpp b/src/osg/Geode.cpp index 43cbaf761..a7ccb5d6e 100644 --- a/src/osg/Geode.cpp +++ b/src/osg/Geode.cpp @@ -20,6 +20,8 @@ Geode::Geode(const Geode& geode,const CopyOp& copyop): Drawable* drawable = copyop(itr->get()); if (drawable) addDrawable(drawable); } + + _occluder = dynamic_cast(copyop(geode.getOccluder())); } Geode::~Geode() @@ -101,6 +103,8 @@ const bool Geode::computeBound() const { BoundingBox bb; +// if (_occluder.valid()) _occluder->computeBound(bb); + DrawableList::const_iterator itr; for(itr=_drawables.begin(); itr!=_drawables.end(); @@ -126,6 +130,8 @@ const bool Geode::computeBound() const } } +// if (_occluder.valid()) _occluder->computeBound(_bsphere); + _bsphere_computed=true; return true; } diff --git a/src/osg/Makefile b/src/osg/Makefile index 707ea2249..a2ec2f835 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -12,6 +12,8 @@ CXXFILES =\ ClipPlane.cpp\ ColorMask.cpp\ ColorMatrix.cpp\ + ConvexPlanerPolygon.cpp\ + ConvexPlanerOccluder.cpp\ CopyOp.cpp\ CullFace.cpp\ Depth.cpp\ @@ -52,6 +54,7 @@ CXXFILES =\ Projection.cpp\ Quat.cpp\ ShadeModel.cpp\ + ShadowOccluderVolume.cpp\ State.cpp\ StateSet.cpp\ Stencil.cpp\ diff --git a/src/osg/ShadowOccluderVolume.cpp b/src/osg/ShadowOccluderVolume.cpp new file mode 100644 index 000000000..3d3bdaff1 --- /dev/null +++ b/src/osg/ShadowOccluderVolume.cpp @@ -0,0 +1,3 @@ +#include + +using namespace osg;