Spinning Topp Logo BlackTopp Studios
inc
collision.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _physicscollision_h
41 #define _physicscollision_h
42 
43 #include "Physics/physicsenumerations.h"
44 #ifndef SWIG
45  #include "vector3.h"
46  #include "XML/xml.h"
47 #endif
48 
49 class btPersistentManifold;
50 class btBroadphasePair;
51 class btCollisionAlgorithm;
52 class btManifoldPoint;
53 
54 namespace Mezzanine
55 {
56  class WorldObject;
57  namespace Physics
58  {
59  class PhysicsManager;
60  class CollisionDispatcher;
61  class ParallelCollisionDispatcher;
62  struct CollisionInternalData;
63  class CollidableProxy;
64  ///////////////////////////////////////////////////////////////////////////////
65  /// @brief This is an event class used to track collsions in the physics world.
66  /// @details This class will be used for tracking collisions in the physics world and will keep track of basic data related to the collision.
67  /// This class stores the information in the form of contact points. Often when a collision occurs there will be more then one place where
68  /// the collision occured, this is a contact point. Internally collisions only store up to a maximum of 4 contact points. When querying for
69  /// collision information, you have to provide the desired contact point index, and it must be valid. If the requested index isn't valid an
70  /// exception will be thrown. So always make sure to verify with GetNumContactPoints().
71  ///////////////////////////////////////
73  {
74  protected:
78 
79  /// @internal
80  /// @brief The internal collision class this event is based on.
81  btCollisionAlgorithm* InternalAlgo;
82  /// @internal
83  /// @brief Array of manifolds that apply to this collision.
85  /// @internal
86  /// @brief The first CollidableProxy involved in the collision.
88  /// @internal
89  /// @brief The second CollidableProxy invovled in the collision.
91  /// @internal
92  /// @brief This stores the distance of each contact point in this collision, for using to track updates.
93  std::vector<Real> PenetrationDistances;
94 
95  /// @internal
96  /// @brief Class Constructor.
97  /// @details This will construct a basic event class with the minimum data needed.
98  /// @param A The first CollidableProxy involved in the collision.
99  /// @param B The second CollidableProxy invovled in the collision.
100  /// @param PhysicsAlgo The internal algorithm used for generating collision data.
101  Collision(CollidableProxy* A, CollidableProxy* B, btCollisionAlgorithm* PhysicsAlgo);
102  /// @internal
103  /// @brief Internal function responsible for fetching the appropriate contact point.
104  btManifoldPoint& GetManifoldPoint(const Whole& Index);
105  /// @internal
106  /// @brief Updates the PenetrationDistances vector on this object.
107  void UpdatePenetrationDistances();
108  public:
109  /// @brief Default Constructor
110  Collision();
111  /// @brief Copy Constructor.
112  /// @param Other The other Collision to copy
113  Collision(const Collision& Other);
114  /// @brief Class Destructor.
115  /// @details Basic Class Destructor.
116  virtual ~Collision();
117 
118  ///////////////////////////////////////////////////////////////////////////////
119  // Utility
120 
121  /// @brief Gets the first CollidableProxy this collision applies to.
122  /// @return Returns a pointer to the first CollidableProxy in this event.
123  virtual CollidableProxy* GetProxyA() const;
124  /// @brief Gets the second CollidableProxy this collision applies to.
125  /// @return Returns a pointer to the second CollidableProxy in this event.
126  virtual CollidableProxy* GetProxyB() const;
127  /// @brief Gets the parent Object of CollidableProxy A.
128  /// @return Returns a pointer to the parent WorldObject of CollidableProxyA.
129  virtual WorldObject* GetObjectA() const;
130  /// @brief Gets the parent Object of CollidableProxy B.
131  /// @return Returns a pointer to the parent WorldObject of CollidableProxyB.
132  virtual WorldObject* GetObjectB() const;
133 
134  /// @brief Convenience function to see if the provided WorldObject pair match the pair in this class.
135  /// @param A The first WorldObject to be compared. Will be checked against both objects in this collision.
136  /// @param B The second WorldObject to be compared. Will be checked against both objects in this collision.
137  /// @return Returns a Boole, true if the pairs match, false otherwise.
138  virtual Boole PairsMatch(WorldObject* A, WorldObject* B) const;
139  /// @brief Convenience function to see if the provided CollidableProxy pair match the pair in this class.
140  /// @param A The first CollidableProxy to be compared. Will be checked against both objects in this collision.
141  /// @param B The second CollidableProxy to be compared. Will be checked against both objects in this collision.
142  /// @return Returns a Boole, true if the pairs match, false otherwise.
143  virtual Boole PairsMatch(CollidableProxy* A, CollidableProxy* B) const;
144  /// @brief Updates this collisions contact point data if it needs updating.
145  virtual void Update();
146 
147  ///////////////////////////////////////////////////////////////////////////////
148  // Contact Query
149 
150  /// @brief Gets the number of contact points this collision is storing.
151  /// @return Returns the number of contact points that currently exist for this collision.
152  virtual Whole GetNumContactPoints();
153  /// @brief Gets the location in the world where the collision occured.
154  /// @param Point The index of the contact point for this collision.
155  /// @return Returns a vector3 containing the approximate world location of the collision.
156  virtual Vector3 GetWorldLocation(const Whole& Point);
157  /// @brief Gets the location in ObjectA's local space where the collision occured.
158  /// @param Point The index of the contact point for this collision.
159  /// @return Returns a vector3 with the point of the collision in ObjectA's local space.
160  virtual Vector3 GetLocalALocation(const Whole& Point);
161  /// @brief Gets the location in ObjectB's local space where the collision occured.
162  /// @param Point The index of the contact point for this collision.
163  /// @return Returns a vector3 with the point of the collision in ObjectB's local space.
164  virtual Vector3 GetLocalBLocation(const Whole& Point);
165  /// @brief GEts the collision normal for a contact point.
166  /// @param Point The index of the contact point for this collision.
167  /// @return Returns a vector3 representing the collision normal for a contact point.
168  virtual Vector3 GetNormal(const Whole& Point);
169  /// @brief Gets the amount of force of the collision.
170  /// @param Point The index of the contact point for this collision.
171  /// @return Returns a real representing the amount of force applied from the collision.
172  virtual Real GetAppliedImpulse(const Whole& Point);
173  /// @brief Gets the penetration depth of the collision.
174  /// @remarks You should double check the return of this to verify that it is <0, sometimes a collision or contact point can be
175  /// reported while there is no actual overlap depending on your physics setup.
176  /// @param Point The index of the contact point for this collision.
177  /// @return Returns a real representing the depth of penetration between the two objects in this collision.
178  virtual Real GetDistance(const Whole& Point);
179  /// @brief Gets the number of simulation steps the contact point has existed.
180  /// @param Point The index of the contact point for this collision.
181  /// @return Returns a Whole representing the amount of simulation steps a point has existed.
182  virtual Whole GetAge(const Whole& Point);
183 
184  ///////////////////////////////////////////////////////////////////////////////
185  // Internal Methods
186 
187  /// @brief Sets the first Collidable this collision applies to.
188  /// @warning Collision events can't/shouldn't have the bodies they apply to changed. This function
189  /// exists mostly just for the blank constructor when you need to set them afterward. If you attempt
190  /// to set this when the pointer is already set, it will log the event but otherwise silently fail.
191  /// @param A The first Object in this event.
192  virtual void _SetProxyA(CollidableProxy* A);
193  /// @brief Sets the second Collidable this collision applies to.
194  /// @warning Collision events can't/shouldn't have the bodies they apply to changed. This function
195  /// exists mostly just for the blank constructor when you need to set them afterward. If you attempt
196  /// to set this when the pointer is already set, it will log the event but otherwise silently fail.
197  /// @param B The second Object in this event.
198  virtual void _SetProxyB(CollidableProxy* B);
199  };// Collision
200  }//Physics
201 }//Mezzanine
202 
203 #endif
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
This is the base class from which classes that are insertable into the physical world.
Definition: worldobject.h:60
std::vector< Real > PenetrationDistances
This stores the distance of each contact point in this collision, for using to track updates...
Definition: collision.h:93
Used to insulate the interface from the implementation details for bullet.
Definition: collision.cpp:61
This is an event class used to track collsions in the physics world.
Definition: collision.h:72
Used to provide better reporting of collisions.
CollidableProxy * ProxyB
The second CollidableProxy invovled in the collision.
Definition: collision.h:90
This is a proxy from which physics objects that can collide with each other are handled.
Used to provide better reporting of collisions in a multithreaded environment.
This is simply a place for storing all the Physics Related functions.
CollidableProxy * ProxyA
The first CollidableProxy involved in the collision.
Definition: collision.h:87
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
CollisionInternalData * InternalData
Array of manifolds that apply to this collision.
Definition: collision.h:84
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
btCollisionAlgorithm * InternalAlgo
The internal collision class this event is based on.
Definition: collision.h:81