Torque3D Documentation / _generateds / sceneCullingVolume.h

sceneCullingVolume.h

Engine/source/scene/culling/sceneCullingVolume.h

More...

Classes:

class

A volume used to include or exclude space in a scene.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SCENECULLINGVOLUME_H_
 25#define _SCENECULLINGVOLUME_H_
 26
 27#ifndef _MPLANESET_H_
 28#include "math/mPlaneSet.h"
 29#endif
 30
 31
 32/// A volume used to include or exclude space in a scene.
 33///
 34/// Culling volumes are represented as sets of clipping planes.
 35///
 36/// @note Culling is performed in world space so the plane data for culling volumes
 37///   must be in world space too.
 38class SceneCullingVolume
 39{
 40   public:
 41
 42      /// Type of culling.
 43      enum Type
 44      {
 45         Includer,
 46         Occluder,
 47      };
 48
 49   protected:
 50
 51      /// What type of culling volume this is.
 52      Type mType;
 53
 54      ///
 55      F32 mSortPoint;
 56
 57      /// The set of clipping planes that defines the clipping volume for this culler.
 58      PlaneSetF mClippingPlanes;
 59
 60      /// Test the given bounds against this culling volume.
 61      ///
 62      /// Note that we allow false positives here for includers.  This will only cause an
 63      /// occasional object to be classified as intersecting when in fact it is outside.
 64      /// This is still better though than requiring the expensive intersection tests for
 65      /// all intersecting objects.
 66      ///
 67      /// @return True if the culling volume accepts the given bounds.
 68      template< typename B > bool _testBounds( const B& bounds ) const
 69      {
 70         if( isOccluder() )
 71            return getPlanes().isContained( bounds );
 72         else
 73            return ( getPlanes().testPotentialIntersection( bounds ) != GeometryOutside );
 74      }
 75
 76   public:
 77
 78      /// Create an *uninitialized* culling volume.
 79      SceneCullingVolume() : mType(Includer), mSortPoint(1.f) {}
 80
 81      ///
 82      SceneCullingVolume( Type type, const PlaneSetF& planes )
 83         : mType( type ), mSortPoint( 1.f ), mClippingPlanes( planes ) {}
 84
 85      /// Return the type of volume defined by this culling volume, i.e. whether it includes
 86      /// or excludes space.
 87      Type getType() const { return mType; }
 88
 89      /// Return true if this is an inclusion volume.
 90      bool isIncluder() const { return ( getType() == Includer ); }
 91
 92      /// Return true if this is an occlusion volume.
 93      bool isOccluder() const { return ( getType() == Occluder ); }
 94
 95      /// Return the set of clipping planes that defines the culling volume.
 96      const PlaneSetF& getPlanes() const { return mClippingPlanes; }
 97
 98      /// @name Sorting
 99      ///
100      /// Before testing, culling volumes will be sorted by decreasing probability of causing
101      /// test positives.  Thus, the sort point of a volume should be a rough metric of the amount
102      /// of scene/screen space it covers.
103      ///
104      /// Note that sort points for occluders are independent of sort points for includers.
105      /// @{
106
107      /// Return the sort point value of the volume.  The larger the value, the more likely the
108      /// volume is to cause positive test results with bounding volumes.
109      F32 getSortPoint() const { return mSortPoint; }
110
111      ///
112      void setSortPoint( F32 value ) { mSortPoint = value; }
113
114      /// @}
115
116      /// @name Testing
117      /// @{
118
119      /// Return true if the volume accepts the given AABB.
120      bool test( const Box3F& aabb ) const { return _testBounds( aabb ); }
121
122      /// Return true if the volume accepts the given OBB.
123      bool test( const OrientedBox3F& obb ) const { return _testBounds( obb ); }
124
125      /// Return true if the volume accepts the given sphere.
126      bool test( const SphereF& sphere ) const { return _testBounds( sphere ); }
127
128      /// @}
129};
130
131#endif // !_SCENECULLINGVOLUME_H_
132