RavEngine
Loading...
Searching...
No Matches
GuVecConvex.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 GU_VEC_CONVEX_H
30#define GU_VEC_CONVEX_H
31
32#include "foundation/PxVecMath.h"
33
34#define PX_SUPPORT_INLINE PX_FORCE_INLINE
35#define PX_SUPPORT_FORCE_INLINE PX_FORCE_INLINE
36
37namespace physx
38{
39namespace Gu
40{
41
43 {
44 enum Type
45 {
46 eCONVEXHULL,
47 eCONVEXHULLNOSCALE,
48 eSPHERE,
49 eBOX,
50 eCAPSULE,
51 eTRIANGLE,
52 eTETRAHEDRON,
53 eCUSTOM
54 };
55 };
56
57 class ConvexV
58 {
59 public:
60
61 PX_FORCE_INLINE ConvexV(const ConvexType::Type type_) : type(type_), bMarginIsRadius(false)
62 {
63 margin = 0.f;
64 minMargin = 0.f;
65 sweepMargin = 0.f;
66 center = aos::V3Zero();
67 }
68
69 PX_FORCE_INLINE ConvexV(const ConvexType::Type type_, const aos::Vec3VArg center_) : type(type_), bMarginIsRadius(false)
70 {
71 using namespace aos;
72 center = center_;
73 margin = 0.f;
74 minMargin = 0.f;
75 sweepMargin = 0.f;
76 }
77
78 //everytime when someone transform the object, they need to up
79 PX_FORCE_INLINE void setCenter(const aos::Vec3VArg _center)
80 {
81 center = _center;
82 }
83
84 PX_FORCE_INLINE void setMargin(const aos::FloatVArg margin_)
85 {
86 aos::FStore(margin_, &margin);
87 }
88
89 PX_FORCE_INLINE void setMargin(const PxReal margin_)
90 {
91 margin = margin_;
92 }
93
94
95 PX_FORCE_INLINE void setMinMargin(const aos::FloatVArg minMargin_)
96 {
97 aos::FStore(minMargin_, & minMargin);
98 }
99
100 PX_FORCE_INLINE void setSweepMargin(const aos::FloatVArg sweepMargin_)
101 {
102 aos::FStore(sweepMargin_, &sweepMargin);
103 }
104
105 PX_FORCE_INLINE aos::Vec3V getCenter()const
106 {
107 return center;
108 }
109
110 PX_FORCE_INLINE aos::FloatV getMargin() const
111 {
112 return aos::FLoad(margin);
113 }
114
115 PX_FORCE_INLINE aos::FloatV getMinMargin() const
116 {
117 return aos::FLoad(minMargin);
118 }
119
120 PX_FORCE_INLINE aos::FloatV getSweepMargin() const
121 {
122 return aos::FLoad(sweepMargin);
123 }
124
125 PX_FORCE_INLINE ConvexType::Type getType() const
126 {
127 return type;
128 }
129
130 PX_FORCE_INLINE aos::BoolV isMarginEqRadius()const
131 {
132 return aos::BLoad(bMarginIsRadius);
133 }
134
135 PX_FORCE_INLINE bool getMarginIsRadius() const
136 {
137 return bMarginIsRadius;
138 }
139
140 PX_FORCE_INLINE PxReal getMarginF() const
141 {
142 return margin;
143 }
144
145
146 protected:
147 ~ConvexV(){}
148 aos::Vec3V center;
149 PxReal margin; //margin is the amount by which we shrunk the shape for a convex or box. If the shape are sphere/capsule, margin is the radius
150 PxReal minMargin; //minMargin is some percentage of marginBase, which is used to determine the termination condition for gjk
151 PxReal sweepMargin; //sweepMargin minMargin is some percentage of marginBase, which is used to determine the termination condition for gjkRaycast
152 ConvexType::Type type;
153 bool bMarginIsRadius;
154 };
155
156 PX_FORCE_INLINE aos::FloatV getContactEps(const aos::FloatV& _marginA, const aos::FloatV& _marginB)
157 {
158 using namespace aos;
159
160 const FloatV ratio = FLoad(0.25f);
161 const FloatV minMargin = FMin(_marginA, _marginB);
162
163 return FMul(minMargin, ratio);
164 }
165
166 PX_FORCE_INLINE aos::FloatV getSweepContactEps(const aos::FloatV& _marginA, const aos::FloatV& _marginB)
167 {
168 using namespace aos;
169
170 const FloatV ratio = FLoad(100.f);
171 const FloatV minMargin = FAdd(_marginA, _marginB);
172
173 return FMul(minMargin, ratio);
174 }
175}
176
177}
178
179#endif
Definition GuVecConvex.h:58
#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 GuVecConvex.h:43
Definition PxVecMathAoSScalar.h:90
Definition PxVecMathAoSScalar.h:52
Definition PxVecMathAoSScalar.h:77