Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ObjectVsBroadPhaseLayerFilterTable.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2023 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
10
14{
15private:
17 uint GetBit(ObjectLayer inLayer1, BroadPhaseLayer inLayer2) const
18 {
19 // Calculate at which bit the entry for this pair resides
20 return inLayer1 * mNumBroadPhaseLayers + (BroadPhaseLayer::Type)inLayer2;
21 }
22
23public:
25
31 ObjectVsBroadPhaseLayerFilterTable(const BroadPhaseLayerInterface &inBroadPhaseLayerInterface, uint inNumBroadPhaseLayers, const ObjectLayerPairFilter &inObjectLayerPairFilter, uint inNumObjectLayers) :
32 mNumBroadPhaseLayers(inNumBroadPhaseLayers)
33 {
34 // Resize table and set all entries to false
35 mTable.resize((inNumBroadPhaseLayers * inNumObjectLayers + 7) / 8, 0);
36
37 // Loop over all object layer pairs
38 for (ObjectLayer o1 = 0; o1 < inNumObjectLayers; ++o1)
39 for (ObjectLayer o2 = 0; o2 < inNumObjectLayers; ++o2)
40 {
41 // Get the broad phase layer for the second object layer
42 BroadPhaseLayer b2 = inBroadPhaseLayerInterface.GetBroadPhaseLayer(o2);
43 JPH_ASSERT((BroadPhaseLayer::Type)b2 < inNumBroadPhaseLayers);
44
45 // If the object layers collide then so should the object and broadphase layer
46 if (inObjectLayerPairFilter.ShouldCollide(o1, o2))
47 {
48 uint bit = GetBit(o1, b2);
49 mTable[bit >> 3] |= 1 << (bit & 0b111);
50 }
51 }
52 }
53
55 virtual bool ShouldCollide(ObjectLayer inLayer1, BroadPhaseLayer inLayer2) const override
56 {
57 uint bit = GetBit(inLayer1, inLayer2);
58 return (mTable[bit >> 3] & (1 << (bit & 0b111))) != 0;
59 }
60
61private:
62 uint mNumBroadPhaseLayers;
63 Array<uint8> mTable;
64};
65
unsigned int uint
Definition Core.h:448
#define JPH_NAMESPACE_END
Definition Core.h:377
#define JPH_NAMESPACE_BEGIN
Definition Core.h:371
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
uint16 ObjectLayer
Definition ObjectLayer.h:16
Definition Array.h:36
void resize(size_type inNewSize)
Resize array to new length.
Definition Array.h:118
Definition BroadPhaseLayer.h:18
uint8 Type
Definition BroadPhaseLayer.h:20
Interface that the application should implement to allow mapping object layers to broadphase layers.
Definition BroadPhaseLayer.h:61
virtual BroadPhaseLayer GetBroadPhaseLayer(ObjectLayer inLayer) const =0
Convert an object layer to the corresponding broadphase layer.
Filter class to test if two objects can collide based on their object layer. Used while finding colli...
Definition ObjectLayer.h:50
virtual bool ShouldCollide(ObjectLayer inLayer1, ObjectLayer inLayer2) const
Returns true if two layers can collide.
Definition ObjectLayer.h:56
Class to test if an object can collide with a broadphase layer. Used while finding collision pairs.
Definition BroadPhaseLayer.h:80
Definition ObjectVsBroadPhaseLayerFilterTable.h:14
JPH_OVERRIDE_NEW_DELETE ObjectVsBroadPhaseLayerFilterTable(const BroadPhaseLayerInterface &inBroadPhaseLayerInterface, uint inNumBroadPhaseLayers, const ObjectLayerPairFilter &inObjectLayerPairFilter, uint inNumObjectLayers)
Definition ObjectVsBroadPhaseLayerFilterTable.h:31
virtual bool ShouldCollide(ObjectLayer inLayer1, BroadPhaseLayer inLayer2) const override
Returns true if an object layer should collide with a broadphase layer.
Definition ObjectVsBroadPhaseLayerFilterTable.h:55