Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ObjectLayerPairFilterMask.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
16{
17public:
19
21 static constexpr uint32 cNumBits = JPH_OBJECT_LAYER_BITS / 2;
22 static constexpr uint32 cMask = (1 << cNumBits) - 1;
23
25 static ObjectLayer sGetObjectLayer(uint32 inGroup, uint32 inMask = cMask)
26 {
27 JPH_ASSERT((inGroup & ~cMask) == 0);
28 JPH_ASSERT((inMask & ~cMask) == 0);
29 return ObjectLayer((inGroup & cMask) | (inMask << cNumBits));
30 }
31
33 static inline uint32 sGetGroup(ObjectLayer inObjectLayer)
34 {
35 return uint32(inObjectLayer) & cMask;
36 }
37
39 static inline uint32 sGetMask(ObjectLayer inObjectLayer)
40 {
41 return uint32(inObjectLayer) >> cNumBits;
42 }
43
45 virtual bool ShouldCollide(ObjectLayer inObject1, ObjectLayer inObject2) const override
46 {
47 return (sGetGroup(inObject1) & sGetMask(inObject2)) != 0
48 && (sGetGroup(inObject2) & sGetMask(inObject1)) != 0;
49 }
50};
51
#define JPH_NAMESPACE_END
Definition Core.h:377
std::uint32_t uint32
Definition Core.h:451
#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
#define JPH_OBJECT_LAYER_BITS
Layer that objects can be in, determines which other objects it can collide with.
Definition ObjectLayer.h:13
uint16 ObjectLayer
Definition ObjectLayer.h:16
Filter class to test if two objects can collide based on their object layer. Used while finding colli...
Definition ObjectLayer.h:50
Definition ObjectLayerPairFilterMask.h:16
virtual bool ShouldCollide(ObjectLayer inObject1, ObjectLayer inObject2) const override
Returns true if two layers can collide.
Definition ObjectLayerPairFilterMask.h:45
static uint32 sGetGroup(ObjectLayer inObjectLayer)
Get the group bits from an ObjectLayer.
Definition ObjectLayerPairFilterMask.h:33
static JPH_OVERRIDE_NEW_DELETE constexpr uint32 cNumBits
Number of bits for the group and mask bits.
Definition ObjectLayerPairFilterMask.h:21
static uint32 sGetMask(ObjectLayer inObjectLayer)
Get the mask bits from an ObjectLayer.
Definition ObjectLayerPairFilterMask.h:39
static ObjectLayer sGetObjectLayer(uint32 inGroup, uint32 inMask=cMask)
Construct an ObjectLayer from a group and mask bits.
Definition ObjectLayerPairFilterMask.h:25
static constexpr uint32 cMask
Definition ObjectLayerPairFilterMask.h:22