PxExtended.h
Go to the documentation of this file.
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-2018 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 
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
44 namespace 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
52 typedef double PxExtended;
53 #define PX_MAX_EXTENDED PX_MAX_F64
54 #define PxExtendedAbs(x) fabs(x)
55 
57 {
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 
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 
81  {
82  return x * x + y * y + z * z;
83  }
84 
86  {
87  return PxSqrt(x * x + y * y + z * z);
88  }
89 
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(x) && PxIsFinite(y) && PxIsFinite(z);
106  }
107 
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 
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 
124  {
125  this->x = x_;
126  this->y = y_;
127  this->z = z_;
128  }
129 
131  {
132  x = y = z = PX_MAX_EXTENDED;
133  }
134 
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 
165  {
166  PxExtendedVec3 temp;
167  temp.cross(*this,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 
184  {
185  return PxExtendedVec3(-x, -y, -z);
186  }
187 
189  {
190  x += v.x;
191  y += v.y;
192  z += v.z;
193  return *this;
194  }
195 
197  {
198  x -= v.x;
199  y -= v.y;
200  z -= v.z;
201  return *this;
202  }
203 
205  {
206  x += PxExtended(v.x);
207  y += PxExtended(v.y);
208  z += PxExtended(v.z);
209  return *this;
210  }
211 
213  {
214  x -= PxExtended(v.x);
215  y -= PxExtended(v.y);
216  z -= PxExtended(v.z);
217  return *this;
218  }
219 
221  {
222  x *= PxExtended(s);
223  y *= PxExtended(s);
224  z *= PxExtended(s);
225  return *this;
226  }
227 
229  {
230  return PxExtendedVec3(x + v.x, y + v.y, z + v.z);
231  }
232 
234  {
235  return PxVec3(PxReal(x - v.x), PxReal(y - v.y), PxReal(z - v.z));
236  }
237 
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 
254 };
255 
257  {
258  return PxVec3(float(v.x), float(v.y), float(v.z));
259  }
260 
261 #else
262 // Big worlds not defined
263 
264 typedef PxVec3 PxExtendedVec3;
265 typedef 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 
275 #endif
Definition: GuContactBuffer.h:37
PX_INLINE void setMinusInfinity()
Definition: PxExtended.h:135
PX_INLINE void cross(const PxExtendedVec3 &left, const PxExtendedVec3 &right)
Definition: PxExtended.h:152
PX_INLINE PxExtended magnitude() const
Definition: PxExtended.h:85
PX_INLINE PxExtended dot(const PxVec3 &v) const
Definition: PxExtended.h:67
PX_INLINE void setPlusInfinity()
Definition: PxExtended.h:130
PX_INLINE bool isFinite() const
Definition: PxExtended.h:103
PX_INLINE PxExtendedVec3 & operator-=(const PxExtendedVec3 &v)
Definition: PxExtended.h:196
PX_INLINE void minimum(const PxExtendedVec3 &v)
Definition: PxExtended.h:116
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:364
float PxReal
Definition: PxSimpleTypes.h:78
PX_INLINE PxVec3 operator-(const PxExtendedVec3 &v) const
Definition: PxExtended.h:233
PxExtended y
Definition: PxExtended.h:253
PX_INLINE PxExtendedVec3 cross(const PxExtendedVec3 &v) const
Definition: PxExtended.h:164
#define PX_MAX_EXTENDED
Definition: PxExtended.h:53
PX_INLINE PxExtended normalize()
Definition: PxExtended.h:90
PX_INLINE PxExtendedVec3 & operator-=(const PxVec3 &v)
Definition: PxExtended.h:212
PX_INLINE PxExtendedVec3 & operator+=(const PxVec3 &v)
Definition: PxExtended.h:204
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxSqrt(float a)
Square root.
Definition: PxMath.h:144
PX_INLINE PxExtendedVec3(PxExtended _x, PxExtended _y, PxExtended _z)
Definition: PxExtended.h:59
float y
Definition: PxVec3.h:381
PX_INLINE void cross(const PxVec3 &left, const PxExtendedVec3 &right)
Definition: PxExtended.h:171
PxExtended x
Definition: PxExtended.h:253
PX_INLINE PxExtendedVec3 & operator+=(const PxExtendedVec3 &v)
Definition: PxExtended.h:188
PX_INLINE PxExtendedVec3 operator-() const
Definition: PxExtended.h:183
PxExtended z
Definition: PxExtended.h:253
PX_INLINE void cross(const PxExtendedVec3 &left, const PxVec3 &right)
Definition: PxExtended.h:140
PX_INLINE PxExtendedVec3()
Definition: PxExtended.h:58
double PxExtended
Definition: PxExtended.h:52
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:292
PX_INLINE PxExtended operator[](int index) const
Definition: PxExtended.h:246
PX_INLINE PxExtendedVec3 & operator*=(const PxReal &s)
Definition: PxExtended.h:220
PX_INLINE PxExtendedVec3 operator+(const PxExtendedVec3 &v) const
Definition: PxExtended.h:228
PX_INLINE PxExtended distanceSquared(const PxExtendedVec3 &v) const
Definition: PxExtended.h:72
PX_INLINE bool isZero() const
Definition: PxExtended.h:61
#define PX_ASSERT(exp)
Definition: PxAssert.h:61
PX_INLINE PxExtended magnitudeSquared() const
Definition: PxExtended.h:80
PX_INLINE void maximum(const PxExtendedVec3 &v)
Definition: PxExtended.h:108
PX_FORCE_INLINE PxVec3 toVec3(const PxExtendedVec3 &v)
Definition: PxExtended.h:256
float z
Definition: PxVec3.h:381
#define PX_INLINE
Definition: PxPreprocessor.h:349
3 Element vector class.
Definition: PxVec3.h:49
PX_INLINE PxExtended & operator[](int index)
Definition: PxExtended.h:238
Definition: PxExtended.h:56
float x
Definition: PxVec3.h:381