7 #ifndef CAFU_PHYSICS_WORLD_HPP_INCLUDED
8 #define CAFU_PHYSICS_WORLD_HPP_INCLUDED
10 #include "Math3D/BoundingBox.hpp"
11 #include "Math3D/Quaternion.hpp"
12 #include "Math3D/Vector3.hpp"
13 #include "btBulletDynamicsCommon.h"
15 #undef min // See http://stackoverflow.com/questions/5004858/stdmin-gives-error
19 namespace cf {
namespace ClipSys {
class CollisionModelT; } }
20 namespace cf {
namespace GameSys {
class ComponentPhysicsT; } }
26 inline btVector3 conv(
const Vector3T<double>& v) {
return btVector3(
float(v.
x),
float(v.
y),
float(v.
z)); }
33 inline float UnitsToPhys(
float v) {
return v * 0.0254f; }
34 inline double UnitsToPhys(
double v) {
return v * 0.0254; }
38 inline float PhysToUnits(
float v) {
return v / 0.0254f; }
39 inline double PhysToUnits(
double v) {
return v / 0.0254; }
47 class RayResultT :
public btCollisionWorld::ClosestRayResultCallback
54 : btCollisionWorld::ClosestRayResultCallback(btVector3(), btVector3()),
55 m_IgnoreObject(IgnoreObject)
66 if (m_collisionObject==NULL)
return NULL;
72 virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& RayResult,
bool NormalIsInWorldSpace)
74 if (RayResult.m_collisionObject==m_IgnoreObject)
return 1.0;
76 return ClosestRayResultCallback::addSingleResult(RayResult, NormalIsInWorldSpace);
82 const btCollisionObject* m_IgnoreObject;
89 class ShapeResultT :
public btCollisionWorld::ClosestConvexResultCallback
95 : btCollisionWorld::ClosestConvexResultCallback(btVector3(), btVector3()),
104 void Ignore(
const btCollisionObject* Obj)
106 assert(m_IgnoreObjCount<2);
107 if (m_IgnoreObjCount>=2)
return;
109 m_IgnoreObjects[m_IgnoreObjCount++]=Obj;
117 assert(m_IgnoreEntCount<2);
118 if (m_IgnoreEntCount>=2)
return;
120 m_IgnoreEntities[m_IgnoreEntCount++]=Ent;
130 if (m_hitCollisionObject==NULL)
return NULL;
132 return static_cast<TraceUserEntityT*
>(m_hitCollisionObject->getUserPointer());
136 virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& ConvexResult,
bool NormalIsInWorldSpace)
138 for (
unsigned short Count=0; Count<m_IgnoreObjCount; Count++)
139 if (ConvexResult.m_hitCollisionObject==m_IgnoreObjects[Count])
return 1.0;
141 for (
unsigned short Count=0; Count<m_IgnoreEntCount; Count++)
142 if (ConvexResult.m_hitCollisionObject->getUserPointer()==m_IgnoreEntities[Count])
return 1.0;
144 return ClosestConvexResultCallback::addSingleResult(ConvexResult, NormalIsInWorldSpace);
150 unsigned short m_IgnoreObjCount;
151 unsigned short m_IgnoreEntCount;
153 const btCollisionObject* m_IgnoreObjects[2];
165 void AddRigidBody(btRigidBody* RigidBody);
166 void RemoveRigidBody(btRigidBody* RigidBody);
170 void TraceShape()
const;
172 void Think(
float FrameTime);
177 btDefaultCollisionConfiguration* m_CollisionConfiguration;
178 btCollisionDispatcher* m_Dispatcher;
179 btBroadphaseInterface* m_Broadphase;
180 btConstraintSolver* m_Solver;
181 btDiscreteDynamicsWorld* m_PhysicsWorld;
Definition: PhysicsWorld.hpp:158
ShapeResultT()
The constructor.
Definition: PhysicsWorld.hpp:94
TraceUserEntityT * GetHitPhysicsComp() const
If something was hit (hasHit() returns true), this method returns a pointer to the Physics component ...
Definition: PhysicsWorld.hpp:64
RayResultT(const btCollisionObject *IgnoreObject)
The constructor.
Definition: PhysicsWorld.hpp:53
void Ignore(const TraceUserEntityT *Ent)
Adds the given entity to the entities to be ignored for this trace.
Definition: PhysicsWorld.hpp:115
T y
The y-component of this vector.
Definition: Vector3.hpp:41
TraceUserEntityT * GetHitPhysicsComp() const
If something was hit (hasHit() returns true), this method returns a pointer to the Physics component ...
Definition: PhysicsWorld.hpp:128
void Ignore(const btCollisionObject *Obj)
Adds the given collision object to the objects to be ignored for this trace.
Definition: PhysicsWorld.hpp:104
This component includes the body of this entity in the dynamic simulation of physics.
Definition: CompPhysics.hpp:26
This is the base class for collision models, defining their common interface.
Definition: CollisionModel_base.hpp:29
This class handles the results of tracing a convex shape through the world.
Definition: PhysicsWorld.hpp:89
T z
The z-component of this vector.
Definition: Vector3.hpp:42
T x
The x-component of this vector.
Definition: Vector3.hpp:40
This class handles the results of tracing a ray through the world.
Definition: PhysicsWorld.hpp:47