Torque3D Documentation / _generateds / scenePolyhedralObject.h

scenePolyhedralObject.h

Engine/source/scene/mixin/scenePolyhedralObject.h

More...

Classes:

class

Shared interface for polyhedral objects.

class

Helper template for mixing a polyhedral volume definition into the superclass hierarchy of a SceneSpace-derived class.

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 _SCENEPOLYHEDRALOBJECT_H_
 25#define _SCENEPOLYHEDRALOBJECT_H_
 26
 27#ifndef _MPOLYHEDRON_H_
 28#include "math/mPolyhedron.h"
 29#endif
 30
 31
 32/// Shared interface for polyhedral objects.
 33struct IScenePolyhedralObject
 34{
 35      /// Convert the polyhedral object to a raw polyhedron.
 36      virtual AnyPolyhedron ToAnyPolyhedron() const = 0;
 37};
 38
 39
 40/// Helper template for mixing a polyhedral volume definition into
 41/// the superclass hierarchy of a SceneSpace-derived class.
 42template< typename Base, typename P = Polyhedron >
 43class ScenePolyhedralObject : public Base, public IScenePolyhedralObject
 44{
 45   public:
 46
 47      typedef Base Parent;
 48      typedef P PolyhedronType;
 49
 50      enum
 51      {
 52         MAX_PLANES = 256,
 53         MAX_POINTS = 256,
 54         MAX_EDGES = 256
 55      };
 56
 57   protected:
 58
 59      enum
 60      {
 61         PolyMask = Parent::NextFreeMask << 0,
 62         NextFreeMask = Parent::NextFreeMask << 1
 63      };
 64
 65      /// Whether the polyhedron corresponds to the object box.  If so,
 66      /// several things can be fast-tracked.  For example, serializing the
 67      /// polyhedron is pointless as it can be easily reconstructed from the
 68      /// object box on load time.  Also, certain operations like containment
 69      /// tests have significantly faster formulations for AABBs (given that the
 70      /// input data is transformed into object space) than for general
 71      /// polyhedrons.
 72      bool mIsBox;
 73
 74      /// The polyhedron that defines the volume of the object.
 75      /// @note Defined in object space by default.
 76      PolyhedronType mPolyhedron;
 77
 78      ///
 79      virtual void _renderObject( ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat );
 80
 81   public:
 82
 83      ScenePolyhedralObject()
 84         : mIsBox( true ) {}
 85
 86      ScenePolyhedralObject( const PolyhedronType& polyhedron )
 87         : mIsBox( false ),
 88           mPolyhedron( polyhedron ) {}
 89
 90      /// Return the polyhedron that describes the space.
 91      const PolyhedronType& getPolyhedron() const { return mPolyhedron; }
 92
 93      // SimObject.
 94      virtual bool onAdd();
 95      virtual void writeFields( Stream& stream, U32 tabStop );
 96      virtual bool writeField( StringTableEntry name, const char* value );
 97
 98      static void initPersistFields();
 99
100      // NetObject.
101      virtual U32 packUpdate( NetConnection* connection, U32 mask, BitStream* stream );
102      virtual void unpackUpdate( NetConnection* connection, BitStream* stream );
103      
104      // SceneObject.
105      virtual bool containsPoint( const Point3F& point );
106
107      // IScenePolyhedralObject.
108      virtual AnyPolyhedron ToAnyPolyhedron() const { return getPolyhedron(); }
109
110   private:
111
112      static bool _setPlane( void* object, const char* index, const char* data );
113      static bool _setPoint( void* object, const char* index, const char* data );
114      static bool _setEdge( void* object, const char* index, const char* data );
115};
116
117#endif // !_SCENEPOLYHEDRALOBJECT_H_
118