Torque3D Documentation / _generateds / collisionTrigger.h

collisionTrigger.h

Engine/source/T3D/components/collision/collisionTrigger.h

More...

Classes:

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 _H_CollisionTrigger
 25#define _H_CollisionTrigger
 26
 27#ifndef _GAMEBASE_H_
 28#include "T3D/gameBase/gameBase.h"
 29#endif
 30#ifndef _MBOX_H_
 31#include "math/mBox.h"
 32#endif
 33#ifndef _EARLYOUTPOLYLIST_H_
 34#include "collision/earlyOutPolyList.h"
 35#endif
 36#ifndef _MPOLYHEDRON_H_
 37#include "math/mPolyhedron.h"
 38#endif
 39#ifndef _TRIGGER_H_
 40#include "T3D/trigger.h"
 41#endif
 42
 43class Convex;
 44class PhysicsBody;
 45class TriggerPolyhedronType;
 46
 47class CollisionTrigger : public GameBase
 48{
 49   typedef GameBase Parent;
 50
 51   /// CollisionTrigger polyhedron with *outward* facing normals and CCW ordered
 52   /// vertices.
 53   Polyhedron mCollisionTriggerPolyhedron;
 54
 55   EarlyOutPolyList  mClippedList;
 56   Vector<GameBase*> mObjects;
 57
 58   PhysicsBody      *mPhysicsRep;
 59
 60   U32               mLastThink;
 61   U32               mCurrTick;
 62   Convex            *mConvexList;
 63
 64   String            mEnterCommand;
 65   String            mLeaveCommand;
 66   String            mTickCommand;
 67
 68   enum CollisionTriggerUpdateBits
 69   {
 70      TransformMask = Parent::NextFreeMask << 0,
 71      PolyMask = Parent::NextFreeMask << 1,
 72      EnterCmdMask = Parent::NextFreeMask << 2,
 73      LeaveCmdMask = Parent::NextFreeMask << 3,
 74      TickCmdMask = Parent::NextFreeMask << 4,
 75      NextFreeMask = Parent::NextFreeMask << 5,
 76   };
 77
 78   static const U32 CMD_SIZE = 1024;
 79
 80protected:
 81
 82   static bool smRenderCollisionTriggers;
 83   bool testObject(GameBase* enter);
 84   void processTick(const Move *move);
 85
 86   void buildConvex(const Box3F& box, Convex* convex);
 87
 88   static bool setEnterCmd(void *object, const char *index, const char *data);
 89   static bool setLeaveCmd(void *object, const char *index, const char *data);
 90   static bool setTickCmd(void *object, const char *index, const char *data);
 91
 92public:
 93   CollisionTrigger();
 94   ~CollisionTrigger();
 95
 96   // SimObject
 97   DECLARE_CONOBJECT(CollisionTrigger);
 98
 99   DECLARE_CALLBACK(void, onAdd, (U32 objectId));
100   DECLARE_CALLBACK(void, onRemove, (U32 objectId));
101
102   static void consoleInit();
103   static void initPersistFields();
104   bool onAdd();
105   void onRemove();
106   void onDeleteNotify(SimObject*);
107   void inspectPostApply();
108
109   // NetObject
110   U32  packUpdate(NetConnection *conn, U32 mask, BitStream* stream);
111   void unpackUpdate(NetConnection *conn, BitStream* stream);
112
113   // SceneObject
114   void setTransform(const MatrixF &mat);
115   void prepRenderImage(SceneRenderState* state);
116
117   // GameBase
118   bool onNewDataBlock(GameBaseData *dptr, bool reload);
119
120   // CollisionTrigger
121   void setTriggerPolyhedron(const Polyhedron&);
122
123   void      potentialEnterObject(GameBase*);
124   U32       getNumCollisionTriggeringObjects() const;
125   GameBase* getObject(const U32);
126   const Vector<GameBase*>& getObjects() const { return mObjects; }
127
128   void renderObject(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat);
129
130   bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
131};
132
133inline U32 CollisionTrigger::getNumCollisionTriggeringObjects() const
134{
135   return mObjects.size();
136}
137
138inline GameBase* CollisionTrigger::getObject(const U32 index)
139{
140   AssertFatal(index < getNumCollisionTriggeringObjects(), "Error, out of range object index");
141
142   return mObjects[index];
143}
144
145#endif // _H_CollisionTrigger
146
147