1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30
31#ifndef PX_PHYSICS_CCT_EXTENDED
32#define PX_PHYSICS_CCT_EXTENDED
33/** \addtogroup character
34 @{
35*/
36
37// This needs to be included in Foundation just for the debug renderer
38
39#include "PxPhysXConfig.h"
40#include "foundation/PxTransform.h"
41#include "foundation/PxAssert.h"
42
43#if !PX_DOXYGEN
44namespace physx
45{
46#endif
47
48// This has to be done here since it also changes the top-level "Px" and "Np" APIs
49#define PX_BIG_WORLDS
50
51#ifdef PX_BIG_WORLDS
52typedef double PxExtended;
53#define PX_MAX_EXTENDED PX_MAX_F64
54#define PxExtendedAbs(x) fabs(x)
55
56struct PxExtendedVec3
57{
58 PX_INLINE PxExtendedVec3() {}
59 PX_INLINE PxExtendedVec3(PxExtended _x, PxExtended _y, PxExtended _z) : x(_x), y(_y), z(_z) {}
60
61 PX_INLINE bool isZero() const
62 {
63 if(x!=0.0 || y!=0.0 || z!=0.0) return false;
64 return true;
65 }
66
67 PX_INLINE PxExtended dot(const PxVec3& v) const
68 {
69 return x * PxExtended(v.x) + y * PxExtended(v.y) + z * PxExtended(v.z);
70 }
71
72 PX_INLINE PxExtended distanceSquared(const PxExtendedVec3& v) const
73 {
74 PxExtended dx = x - v.x;
75 PxExtended dy = y - v.y;
76 PxExtended dz = z - v.z;
77 return dx * dx + dy * dy + dz * dz;
78 }
79
80 PX_INLINE PxExtended magnitudeSquared() const
81 {
82 return x * x + y * y + z * z;
83 }
84
85 PX_INLINE PxExtended magnitude() const
86 {
87 return PxSqrt(a: x * x + y * y + z * z);
88 }
89
90 PX_INLINE PxExtended normalize()
91 {
92 PxExtended m = magnitude();
93 if (m != 0.0)
94 {
95 const PxExtended il = PxExtended(1.0) / m;
96 x *= il;
97 y *= il;
98 z *= il;
99 }
100 return m;
101 }
102
103 PX_INLINE bool isFinite() const
104 {
105 return PxIsFinite(f: x) && PxIsFinite(f: y) && PxIsFinite(f: z);
106 }
107
108 PX_INLINE void maximum(const PxExtendedVec3& v)
109 {
110 if (x < v.x) x = v.x;
111 if (y < v.y) y = v.y;
112 if (z < v.z) z = v.z;
113 }
114
115
116 PX_INLINE void minimum(const PxExtendedVec3& v)
117 {
118 if (x > v.x) x = v.x;
119 if (y > v.y) y = v.y;
120 if (z > v.z) z = v.z;
121 }
122
123 PX_INLINE void set(PxExtended x_, PxExtended y_, PxExtended z_)
124 {
125 this->x = x_;
126 this->y = y_;
127 this->z = z_;
128 }
129
130 PX_INLINE void setPlusInfinity()
131 {
132 x = y = z = PX_MAX_EXTENDED;
133 }
134
135 PX_INLINE void setMinusInfinity()
136 {
137 x = y = z = -PX_MAX_EXTENDED;
138 }
139
140 PX_INLINE void cross(const PxExtendedVec3& left, const PxVec3& right)
141 {
142 // temps needed in case left or right is this.
143 PxExtended a = (left.y * PxExtended(right.z)) - (left.z * PxExtended(right.y));
144 PxExtended b = (left.z * PxExtended(right.x)) - (left.x * PxExtended(right.z));
145 PxExtended c = (left.x * PxExtended(right.y)) - (left.y * PxExtended(right.x));
146
147 x = a;
148 y = b;
149 z = c;
150 }
151
152 PX_INLINE void cross(const PxExtendedVec3& left, const PxExtendedVec3& right)
153 {
154 // temps needed in case left or right is this.
155 PxExtended a = (left.y * right.z) - (left.z * right.y);
156 PxExtended b = (left.z * right.x) - (left.x * right.z);
157 PxExtended c = (left.x * right.y) - (left.y * right.x);
158
159 x = a;
160 y = b;
161 z = c;
162 }
163
164 PX_INLINE PxExtendedVec3 cross(const PxExtendedVec3& v) const
165 {
166 PxExtendedVec3 temp;
167 temp.cross(left: *this,right: v);
168 return temp;
169 }
170
171 PX_INLINE void cross(const PxVec3& left, const PxExtendedVec3& right)
172 {
173 // temps needed in case left or right is this.
174 PxExtended a = (PxExtended(left.y) * right.z) - (PxExtended(left.z) * right.y);
175 PxExtended b = (PxExtended(left.z) * right.x) - (PxExtended(left.x) * right.z);
176 PxExtended c = (PxExtended(left.x) * right.y) - (PxExtended(left.y) * right.x);
177
178 x = a;
179 y = b;
180 z = c;
181 }
182
183 PX_INLINE PxExtendedVec3 operator-() const
184 {
185 return PxExtendedVec3(-x, -y, -z);
186 }
187
188 PX_INLINE PxExtendedVec3& operator+=(const PxExtendedVec3& v)
189 {
190 x += v.x;
191 y += v.y;
192 z += v.z;
193 return *this;
194 }
195
196 PX_INLINE PxExtendedVec3& operator-=(const PxExtendedVec3& v)
197 {
198 x -= v.x;
199 y -= v.y;
200 z -= v.z;
201 return *this;
202 }
203
204 PX_INLINE PxExtendedVec3& operator+=(const PxVec3& v)
205 {
206 x += PxExtended(v.x);
207 y += PxExtended(v.y);
208 z += PxExtended(v.z);
209 return *this;
210 }
211
212 PX_INLINE PxExtendedVec3& operator-=(const PxVec3& v)
213 {
214 x -= PxExtended(v.x);
215 y -= PxExtended(v.y);
216 z -= PxExtended(v.z);
217 return *this;
218 }
219
220 PX_INLINE PxExtendedVec3& operator*=(const PxReal& s)
221 {
222 x *= PxExtended(s);
223 y *= PxExtended(s);
224 z *= PxExtended(s);
225 return *this;
226 }
227
228 PX_INLINE PxExtendedVec3 operator+(const PxExtendedVec3& v) const
229 {
230 return PxExtendedVec3(x + v.x, y + v.y, z + v.z);
231 }
232
233 PX_INLINE PxVec3 operator-(const PxExtendedVec3& v) const
234 {
235 return PxVec3(PxReal(x - v.x), PxReal(y - v.y), PxReal(z - v.z));
236 }
237
238 PX_INLINE PxExtended& operator[](int index)
239 {
240 PX_ASSERT(index>=0 && index<=2);
241
242 return reinterpret_cast<PxExtended*>(this)[index];
243 }
244
245
246 PX_INLINE PxExtended operator[](int index) const
247 {
248 PX_ASSERT(index>=0 && index<=2);
249
250 return reinterpret_cast<const PxExtended*>(this)[index];
251 }
252
253 PxExtended x,y,z;
254};
255
256 PX_FORCE_INLINE PxVec3 toVec3(const PxExtendedVec3& v)
257 {
258 return PxVec3(float(v.x), float(v.y), float(v.z));
259 }
260
261#else
262// Big worlds not defined
263
264typedef PxVec3 PxExtendedVec3;
265typedef PxReal PxExtended;
266#define PX_MAX_EXTENDED PX_MAX_F32
267#define PxExtendedAbs(x) fabsf(x)
268#endif
269
270#if !PX_DOXYGEN
271} // namespace physx
272#endif
273
274/** @} */
275#endif
276

source code of qtquick3dphysics/src/3rdparty/PhysX/include/characterkinematic/PxExtended.h