RavEngine
Loading...
Searching...
No Matches
BpFiltering.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef BP_FILTERING_H
30#define BP_FILTERING_H
31
32#include "PxvConfig.h"
33#include "foundation/PxAssert.h"
34
35namespace physx
36{
37 namespace Bp
38 {
39
40#define BP_USE_AGGREGATE_GROUP_TAIL
41#define BP_FILTERING_TYPE_SHIFT_BIT 3
42#define BP_FILTERING_TYPE_MASK 7
43
44 /*
45 \brief AABBManager volumes with the same filter group value are guaranteed never to generate an overlap pair.
46 \note To ensure that static pairs never overlap, add static shapes with eSTATICS.
47 The value eDYNAMICS_BASE provides a minimum recommended group value for dynamic shapes.
48 If dynamics shapes are assigned group values greater than or equal to eDYNAMICS_BASE then
49 they are allowed to generate broadphase overlaps with statics, and other dynamic shapes provided
50 they have different group values.
51 @see AABBManager::createVolume
52 */
54 {
55 enum Enum
56 {
57 eSTATICS = 0,
58 ePARTICLES = 1,
59 eDYNAMICS_BASE = 2,
60#ifdef BP_USE_AGGREGATE_GROUP_TAIL
61 eAGGREGATE_BASE = 0xfffffffe,
62#endif
63 eINVALID = 0xffffffff
64 };
65 };
66
68 {
69 enum Enum
70 {
71 STATIC = 0,
72 KINEMATIC = 1,
73 DYNAMIC = 2,
74 AGGREGATE = 3,
75 SOFTBODY = 4,
76 PARTICLESYSTEM = 5,
77 FEMCLOTH = 6,
78 HAIRSYSTEM = 7,
79
80 COUNT = 8
81 };
82 };
83
84 PX_FORCE_INLINE Bp::FilterGroup::Enum getFilterGroup_Statics()
85 {
86 return Bp::FilterGroup::eSTATICS;
87 }
88
89 PX_FORCE_INLINE Bp::FilterGroup::Enum getFilterGroup_Dynamics(PxU32 rigidId, bool isKinematic)
90 {
91 const PxU32 group = rigidId + Bp::FilterGroup::eDYNAMICS_BASE;
92 const PxU32 type = isKinematic ? FilterType::KINEMATIC : FilterType::DYNAMIC;
93 return Bp::FilterGroup::Enum((group<< BP_FILTERING_TYPE_SHIFT_BIT)|type);
94 }
95
96 PX_FORCE_INLINE Bp::FilterGroup::Enum getFilterGroup(bool isStatic, PxU32 rigidId, bool isKinematic)
97 {
98 return isStatic ? getFilterGroup_Statics() : getFilterGroup_Dynamics(rigidId, isKinematic);
99 }
100
101 PX_FORCE_INLINE bool groupFiltering(const Bp::FilterGroup::Enum group0, const Bp::FilterGroup::Enum group1, const bool* PX_RESTRICT lut)
102 {
103/* const int g0 = group0 & ~3;
104 const int g1 = group1 & ~3;
105 if(g0==g1)
106 return false;*/
107 if(group0==group1)
108 {
109 PX_ASSERT((group0 & ~BP_FILTERING_TYPE_MASK)==(group1 & ~BP_FILTERING_TYPE_MASK));
110 return false;
111 }
112
113 const int type0 = group0 & BP_FILTERING_TYPE_MASK;
114 const int type1 = group1 & BP_FILTERING_TYPE_MASK;
115 return lut[type0*Bp::FilterType::COUNT+type1];
116 }
117
119 {
120 public:
121 BpFilter(bool discardKineKine, bool discardStaticKine);
122 ~BpFilter();
123
124 PX_FORCE_INLINE const bool* getLUT() const { return &mLUT[0][0]; }
125
126 bool mLUT[Bp::FilterType::COUNT][Bp::FilterType::COUNT];
127 };
128 }
129}
130
131#endif
132
Definition BpFiltering.h:119
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition BpFiltering.h:54
Definition BpFiltering.h:68