RavEngine
Loading...
Searching...
No Matches
PxsMaterialCombiner.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 PXS_MATERIAL_COMBINER_H
30#define PXS_MATERIAL_COMBINER_H
31
32#include "PxsMaterialCore.h"
33
34namespace physx
35{
36 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal combineScalars(PxReal a, PxReal b, PxI32 combineMode)
37 {
38 switch (combineMode)
39 {
41 return 0.5f * (a + b);
43 return PxMin(a,b);
45 return a * b;
47 return PxMax(a,b);
48 default:
49 return PxReal(0);
50 }
51 }
52
53 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal PxsCombineRestitution(const PxsMaterialData& mat0, const PxsMaterialData& mat1)
54 {
55 return combineScalars(mat0.restitution, mat1.restitution, ((mat0.flags | mat1.flags) & PxMaterialFlag::eCOMPLIANT_CONTACT) ?
56 PxCombineMode::eMIN : PxMax(mat0.getRestitutionCombineMode(), mat1.getRestitutionCombineMode()));
57 }
58
59 //ML:: move this function to header file to avoid LHS in Xbox
60 //PT: also called by CUDA code now
61 PX_CUDA_CALLABLE PX_FORCE_INLINE void PxsCombineIsotropicFriction(const PxsMaterialData& mat0, const PxsMaterialData& mat1, PxReal& dynamicFriction, PxReal& staticFriction, PxU32& flags)
62 {
63 const PxU32 combineFlags = (mat0.flags | mat1.flags); //& (PxMaterialFlag::eDISABLE_STRONG_FRICTION|PxMaterialFlag::eDISABLE_FRICTION); //eventually set DisStrongFric flag, lower all others.
64
65 if (!(combineFlags & PxMaterialFlag::eDISABLE_FRICTION))
66 {
67 const PxI32 fictionCombineMode = PxMax(mat0.getFrictionCombineMode(), mat1.getFrictionCombineMode());
68 PxReal dynFriction = 0.0f;
69 PxReal staFriction = 0.0f;
70
71 switch (fictionCombineMode)
72 {
74 dynFriction = 0.5f * (mat0.dynamicFriction + mat1.dynamicFriction);
75 staFriction = 0.5f * (mat0.staticFriction + mat1.staticFriction);
76 break;
78 dynFriction = PxMin(mat0.dynamicFriction, mat1.dynamicFriction);
79 staFriction = PxMin(mat0.staticFriction, mat1.staticFriction);
80 break;
82 dynFriction = (mat0.dynamicFriction * mat1.dynamicFriction);
83 staFriction = (mat0.staticFriction * mat1.staticFriction);
84 break;
86 dynFriction = PxMax(mat0.dynamicFriction, mat1.dynamicFriction);
87 staFriction = PxMax(mat0.staticFriction, mat1.staticFriction);
88 break;
89 }
90
91 //isotropic case
92 const PxReal fDynFriction = PxMax(dynFriction, 0.0f);
93
94 // PT: TODO: the two branches aren't actually doing the same thing:
95 // - one is ">", the other is ">="
96 // - one uses a clamped dynFriction, the other not
97#ifdef __CUDACC__
98 const PxReal fStaFriction = (staFriction - fDynFriction) > 0 ? staFriction : dynFriction;
99#else
100 const PxReal fStaFriction = physx::intrinsics::fsel(staFriction - fDynFriction, staFriction, fDynFriction);
101#endif
102 dynamicFriction = fDynFriction;
103 staticFriction = fStaFriction;
104 flags = combineFlags;
105 }
106 else
107 {
108 flags = combineFlags | PxMaterialFlag::eDISABLE_STRONG_FRICTION;
109 dynamicFriction = 0.0f;
110 staticFriction = 0.0f;
111 }
112 }
113}
114
115#endif
#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
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMax(T a, T b)
The return value is the greater of the two specified values.
Definition PxMath.h:72
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b)
The return value is the lesser of the two specified values.
Definition PxMath.h:88
@ eMAX
Maximum: maximum(a,b)
Definition PxMaterial.h:137
@ eMULTIPLY
Multiply: a*b.
Definition PxMaterial.h:136
@ eMIN
Minimum: minimum(a,b)
Definition PxMaterial.h:135
@ eAVERAGE
Average: (a + b)/2.
Definition PxMaterial.h:134
@ eDISABLE_STRONG_FRICTION
Whether to use strong friction. The difference between "normal" and "strong" friction is that the str...
Definition PxMaterial.h:78
@ eCOMPLIANT_CONTACT
This flag has the effect of enabling an implicit spring model for the normal force computation.
Definition PxMaterial.h:98
@ eDISABLE_FRICTION
If this flag is set, friction computations are always skipped between shapes with this material and a...
Definition PxMaterial.h:57