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 17 of file PhysicalWorld.cpp.

Constructor & Destructor Documentation

◆ LeviathanPhysicsOverlapFilter()

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

Definition at line 19 of file PhysicalWorld.cpp.

19 : World(world) {}

Member Function Documentation

◆ needBroadphaseCollision()

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

Definition at line 21 of file PhysicalWorld.cpp.

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

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