collisionInterfaces.h
Engine/source/T3D/components/collision/collisionInterfaces.h
Classes:
class
class
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 COLLISION_INTERFACES_H 25#define COLLISION_INTERFACES_H 26 27#ifndef _CONVEX_H_ 28#include "collision/convex.h" 29#endif 30#ifndef _COLLISION_H_ 31#include "collision/collision.h" 32#endif 33#ifndef _EARLYOUTPOLYLIST_H_ 34#include "collision/earlyOutPolyList.h" 35#endif 36#ifndef _SIM_H_ 37#include "console/sim.h" 38#endif 39#ifndef _SCENECONTAINER_H_ 40#include "scene/sceneContainer.h" 41#endif 42#ifndef _T3D_PHYSICSCOMMON_H_ 43#include "T3D/physics/physicsCommon.h" 44#endif 45 46struct ContactInfo 47{ 48 bool contacted, move; 49 SceneObject *contactObject; 50 VectorF idealContactNormal; 51 VectorF contactNormal; 52 Point3F contactPoint; 53 F32 contactTime; 54 S32 contactTimer; 55 BaseMatInstance *contactMaterial; 56 57 void clear() 58 { 59 contacted=<a href="/coding/class/structcontactinfo/#structcontactinfo_1a35e8f0c0aa831c6f044fae144c936f90">move</a>=false; 60 contactObject = NULL; 61 contactNormal.set(0,0,0); 62 contactTime = 0.f; 63 contactTimer = 0; 64 idealContactNormal.set(0, 0, 1); 65 contactMaterial = NULL; 66 } 67 68 ContactInfo() { clear(); } 69 70}; 71 72class CollisionInterface// : public Interface<CollisionInterface> 73{ 74public: 75 // CollisionTimeout 76 // This struct lets us track our collisions and estimate when they've have timed out and we'll need to act on it. 77 struct CollisionTimeout 78 { 79 CollisionTimeout* next; 80 SceneObject* object; 81 U32 objectNumber; 82 SimTime expireTime; 83 VectorF vector; 84 }; 85 86 Signal< void( SceneObject* ) > onCollisionSignal; 87 Signal< void( SceneObject* ) > onContactSignal; 88 89protected: 90 CollisionTimeout* mTimeoutList; 91 static CollisionTimeout* sFreeTimeoutList; 92 93 CollisionList mCollisionList; 94 Vector<CollisionInterface*> mCollisionNotifyList; 95 96 ContactInfo mContactInfo; 97 98 Box3F mWorkingQueryBox; 99 100 U32 CollisionMoveMask; 101 102 Convex *mConvexList; 103 104 bool mBlockColliding; 105 106 void handleCollisionNotifyList(); 107 108 void queueCollision( SceneObject *obj, const VectorF &vec); 109 110 /// checkEarlyOut 111 /// This function lets you trying and early out of any expensive collision checks by using simple extruded poly boxes representing our objects 112 /// If it returns true, we know we won't hit with the given parameters and can successfully early out. If it returns false, our test case collided 113 /// and we should do the full collision sim. 114 bool checkEarlyOut(Point3F start, VectorF velocity, F32 time, Box3F objectBox, Point3F objectScale, 115 Box3F collisionBox, U32 collisionMask, CollisionWorkingList &colWorkingList); 116 117public: 118 /// checkCollisions 119 // This is our main function for checking if a collision is happening based on the start point, velocity and time 120 // We do the bulk of the collision checking in here 121 //virtual bool checkCollisions( const F32 travelTime, Point3F *velocity, Point3F start )=0; 122 123 CollisionList *getCollisionList() { return &mCollisionList; } 124 125 void clearCollisionList() { mCollisionList.clear(); } 126 127 void clearCollisionNotifyList() { mCollisionNotifyList.clear(); } 128 129 Collision *getCollision(S32 col); 130 131 ContactInfo* getContactInfo() { return &mContactInfo; } 132 133 Convex *getConvexList() { return mConvexList; } 134 135 virtual bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere) = 0; 136 137 enum PublicConstants { 138 CollisionTimeoutValue = 250 139 }; 140 141 bool doesBlockColliding() { return mBlockColliding; } 142 143 /// handleCollisionList 144 /// This basically takes in a CollisionList and calls handleCollision for each. 145 void handleCollisionList(CollisionList &collisionList, VectorF velocity); 146 147 /// handleCollision 148 /// This will take a collision and queue the collision info for the object so that in knows about the collision. 149 void handleCollision(Collision &col, VectorF velocity); 150 151 virtual PhysicsCollision* getCollisionData() = 0; 152 153 Signal< void(PhysicsCollision* collision) > onCollisionChanged; 154}; 155 156class BuildConvexInterface //: public Interface<CollisionInterface> 157{ 158public: 159 virtual void buildConvex(const Box3F& box, Convex* convex)=0; 160}; 161 162class BuildPolyListInterface// : public Interface<CollisionInterface> 163{ 164public: 165 virtual bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere) = 0; 166}; 167 168#endif 169
