RavEngine
Loading...
Searching...
No Matches
PxExtended.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 PX_EXTENDED_H
30#define PX_EXTENDED_H
35// This needs to be included in Foundation just for the debug renderer
36
37#include "PxPhysXConfig.h"
38#include "foundation/PxTransform.h"
39#include "foundation/PxAssert.h"
40
41#if !PX_DOXYGEN
42namespace physx
43{
44#endif
45
46// This has to be done here since it also changes the top-level "Px" and "Np" APIs
47#define PX_BIG_WORLDS
48
49#ifdef PX_BIG_WORLDS
50typedef double PxExtended;
51#define PX_MAX_EXTENDED PX_MAX_F64
52#define PxExtendedAbs(x) fabs(x)
53
55{
57 PX_INLINE PxExtendedVec3(PxExtended _x, PxExtended _y, PxExtended _z) : x(_x), y(_y), z(_z) {}
58
59 PX_INLINE bool isZero() const
60 {
61 if(x!=0.0 || y!=0.0 || z!=0.0) return false;
62 return true;
63 }
64
65 PX_INLINE PxExtended dot(const PxVec3& v) const
66 {
67 return x * PxExtended(v.x) + y * PxExtended(v.y) + z * PxExtended(v.z);
68 }
69
70 PX_INLINE PxExtended distanceSquared(const PxExtendedVec3& v) const
71 {
72 PxExtended dx = x - v.x;
73 PxExtended dy = y - v.y;
74 PxExtended dz = z - v.z;
75 return dx * dx + dy * dy + dz * dz;
76 }
77
78 PX_INLINE PxExtended magnitudeSquared() const
79 {
80 return x * x + y * y + z * z;
81 }
82
83 PX_INLINE PxExtended magnitude() const
84 {
85 return PxSqrt(x * x + y * y + z * z);
86 }
87
88 PX_INLINE PxExtended normalize()
89 {
90 PxExtended m = magnitude();
91 if (m != 0.0)
92 {
93 const PxExtended il = PxExtended(1.0) / m;
94 x *= il;
95 y *= il;
96 z *= il;
97 }
98 return m;
99 }
100
101 PX_INLINE bool isFinite() const
102 {
103 return PxIsFinite(x) && PxIsFinite(y) && PxIsFinite(z);
104 }
105
106 PX_INLINE void maximum(const PxExtendedVec3& v)
107 {
108 if (x < v.x) x = v.x;
109 if (y < v.y) y = v.y;
110 if (z < v.z) z = v.z;
111 }
112
113
114 PX_INLINE void minimum(const PxExtendedVec3& v)
115 {
116 if (x > v.x) x = v.x;
117 if (y > v.y) y = v.y;
118 if (z > v.z) z = v.z;
119 }
120
121 PX_INLINE void set(PxExtended x_, PxExtended y_, PxExtended z_)
122 {
123 this->x = x_;
124 this->y = y_;
125 this->z = z_;
126 }
127
128 PX_INLINE void setPlusInfinity()
129 {
130 x = y = z = PX_MAX_EXTENDED;
131 }
132
133 PX_INLINE void setMinusInfinity()
134 {
135 x = y = z = -PX_MAX_EXTENDED;
136 }
137
138 PX_INLINE void cross(const PxExtendedVec3& left, const PxVec3& right)
139 {
140 // temps needed in case left or right is this.
141 PxExtended a = (left.y * PxExtended(right.z)) - (left.z * PxExtended(right.y));
142 PxExtended b = (left.z * PxExtended(right.x)) - (left.x * PxExtended(right.z));
143 PxExtended c = (left.x * PxExtended(right.y)) - (left.y * PxExtended(right.x));
144
145 x = a;
146 y = b;
147 z = c;
148 }
149
150 PX_INLINE void cross(const PxExtendedVec3& left, const PxExtendedVec3& right)
151 {
152 // temps needed in case left or right is this.
153 PxExtended a = (left.y * right.z) - (left.z * right.y);
154 PxExtended b = (left.z * right.x) - (left.x * right.z);
155 PxExtended c = (left.x * right.y) - (left.y * right.x);
156
157 x = a;
158 y = b;
159 z = c;
160 }
161
162 PX_INLINE PxExtendedVec3 cross(const PxExtendedVec3& v) const
163 {
164 PxExtendedVec3 temp;
165 temp.cross(*this,v);
166 return temp;
167 }
168
169 PX_INLINE void cross(const PxVec3& left, const PxExtendedVec3& right)
170 {
171 // temps needed in case left or right is this.
172 PxExtended a = (PxExtended(left.y) * right.z) - (PxExtended(left.z) * right.y);
173 PxExtended b = (PxExtended(left.z) * right.x) - (PxExtended(left.x) * right.z);
174 PxExtended c = (PxExtended(left.x) * right.y) - (PxExtended(left.y) * right.x);
175
176 x = a;
177 y = b;
178 z = c;
179 }
180
181 PX_INLINE PxExtendedVec3 operator-() const
182 {
183 return PxExtendedVec3(-x, -y, -z);
184 }
185
186 PX_INLINE PxExtendedVec3& operator+=(const PxExtendedVec3& v)
187 {
188 x += v.x;
189 y += v.y;
190 z += v.z;
191 return *this;
192 }
193
194 PX_INLINE PxExtendedVec3& operator-=(const PxExtendedVec3& v)
195 {
196 x -= v.x;
197 y -= v.y;
198 z -= v.z;
199 return *this;
200 }
201
202 PX_INLINE PxExtendedVec3& operator+=(const PxVec3& v)
203 {
204 x += PxExtended(v.x);
205 y += PxExtended(v.y);
206 z += PxExtended(v.z);
207 return *this;
208 }
209
210 PX_INLINE PxExtendedVec3& operator-=(const PxVec3& v)
211 {
212 x -= PxExtended(v.x);
213 y -= PxExtended(v.y);
214 z -= PxExtended(v.z);
215 return *this;
216 }
217
218 PX_INLINE PxExtendedVec3& operator*=(const PxReal& s)
219 {
220 x *= PxExtended(s);
221 y *= PxExtended(s);
222 z *= PxExtended(s);
223 return *this;
224 }
225
226 PX_INLINE PxExtendedVec3 operator+(const PxExtendedVec3& v) const
227 {
228 return PxExtendedVec3(x + v.x, y + v.y, z + v.z);
229 }
230
231 PX_INLINE PxVec3 operator-(const PxExtendedVec3& v) const
232 {
233 return PxVec3(PxReal(x - v.x), PxReal(y - v.y), PxReal(z - v.z));
234 }
235
236 PX_INLINE PxExtended& operator[](int index)
237 {
238 PX_ASSERT(index>=0 && index<=2);
239
240 return reinterpret_cast<PxExtended*>(this)[index];
241 }
242
243
244 PX_INLINE PxExtended operator[](int index) const
245 {
246 PX_ASSERT(index>=0 && index<=2);
247
248 return reinterpret_cast<const PxExtended*>(this)[index];
249 }
250
251 PxExtended x,y,z;
252};
253
254 PX_FORCE_INLINE PxVec3 toVec3(const PxExtendedVec3& v)
255 {
256 return PxVec3(float(v.x), float(v.y), float(v.z));
257 }
258
259#else
260// Big worlds not defined
261
262typedef PxVec3 PxExtendedVec3;
263typedef PxReal PxExtended;
264#define PX_MAX_EXTENDED PX_MAX_F32
265#define PxExtendedAbs(x) fabsf(x)
266#endif
267
268#if !PX_DOXYGEN
269} // namespace physx
270#endif
271
273#endif
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
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 bool PxIsFinite(float f)
returns true if the passed number is a finite floating point number as opposed to INF,...
Definition PxMath.h:326
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxSqrt(float a)
Square root.
Definition PxMath.h:146
Definition PxExtended.h:55