Leviathan  0.8.0.0
Leviathan game engine
Leviathan::LeviathanPhysicsOverlapFilter Class Reference

Handles AABB material callbacks. More...

+ Inheritance diagram for Leviathan::LeviathanPhysicsOverlapFilter:

Public Member Functions

 LeviathanPhysicsOverlapFilter (PhysicalWorld *world)
 
bool needBroadphaseCollision (btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const override
 

Detailed Description

Handles AABB material callbacks.

Definition at line 14 of file PhysicalWorld.cpp.

Constructor & Destructor Documentation

◆ LeviathanPhysicsOverlapFilter()

Leviathan::LeviathanPhysicsOverlapFilter::LeviathanPhysicsOverlapFilter ( PhysicalWorld world)
inline

Definition at line 16 of file PhysicalWorld.cpp.

16 : World(world) {}

Member Function Documentation

◆ needBroadphaseCollision()

bool Leviathan::LeviathanPhysicsOverlapFilter::needBroadphaseCollision ( btBroadphaseProxy *  proxy0,
btBroadphaseProxy *  proxy1 
) const
inlineoverride

Definition at line 18 of file PhysicalWorld.cpp.

20  {
21  bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
22  collides =
23  collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
24 
25  if(!collides)
26  return false;
27 
28  // Custom material check (this is after the fast inbuilt bullet mask check mimicking
29  // check)
30  const btCollisionObject* obj0 =
31  static_cast<btCollisionObject*>(proxy0->m_clientObject);
32  const btCollisionObject* obj1 =
33  static_cast<btCollisionObject*>(proxy1->m_clientObject);
34 
35  // TODO: remove this check once it is confirmed that both objects must always exist
36  if(obj0 && obj1) {
37 
38  PhysicsBody* body1 = static_cast<PhysicsBody*>(obj0->getUserPointer());
39  PhysicsBody* body2 = static_cast<PhysicsBody*>(obj1->getUserPointer());
40 
41  if(body1 && body2) {
42 
43  const auto materialID1 = body1->GetPhysicalMaterialID();
44  const auto materialID2 = body2->GetPhysicalMaterialID();
45 
46  // Find contact callbacks
47  if(materialID1 >= 0 && materialID2 >= 0) {
48 
49  auto pair = World->GetMaterialPair(materialID1, materialID2);
50 
51  if(pair && pair->AABBCallback) {
52 
53  return pair->AABBCallback(*World, *body1, *body2);
54  }
55  }
56  } else {
57  LOG_ERROR("Physics body doesn't have user pointer");
58  }
59 
60  } else {
61  LOG_ERROR("Physics btCollisionObject doesn't exist");
62  }
63 
64  // Needs collision
65  return true;
66  }
#define LOG_ERROR(x)
Definition: Define.h:84
This is an instance of a collision body.
Definition: PhysicsBody.h:74
const PhysMaterialDataPair * GetMaterialPair(int id1, int id2) const
Finds the information for contact between objects with two materials.
auto GetPhysicalMaterialID() const
Definition: PhysicsBody.h:173
PhysicsMaterialAABBCallback AABBCallback

The documentation for this class was generated from the following file: