PxExtended.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12 
13 
14 #ifndef PX_PHYSICS_CCT_EXTENDED
15 #define PX_PHYSICS_CCT_EXTENDED
16 
20 // This needs to be included in Foundation just for the debug renderer
21 
22 #include "PxPhysXConfig.h"
23 #include "foundation/PxTransform.h"
24 
25 #ifndef PX_DOXYGEN
26 namespace physx
27 {
28 #endif
29 
30 // This has to be done here since it also changes the top-level "Nx" API (as well as "Nv" and "Np" ones)
31 #define PX_BIG_WORLDS
32 
33 #ifdef PX_BIG_WORLDS
34 typedef double PxExtended;
35 #define PX_MAX_EXTENDED PX_MAX_F64
36 #define PxExtendedAbs(x) fabs(x)
37 
39 {
41  PX_INLINE PxExtendedVec3(PxExtended _x, PxExtended _y, PxExtended _z) : x(_x), y(_y), z(_z) {}
42 
43  PX_INLINE bool isZero() const
44  {
45  if(x!=0.0 || y!=0.0 || z!=0.0) return false;
46  return true;
47  }
48 
49  PX_INLINE PxExtended dot(const PxVec3& v) const
50  {
51  return x * v.x + y * v.y + z * v.z;
52  }
53 
54  PX_INLINE PxExtended distanceSquared(const PxExtendedVec3& v) const
55  {
56  PxExtended dx = x - v.x;
57  PxExtended dy = y - v.y;
58  PxExtended dz = z - v.z;
59  return dx * dx + dy * dy + dz * dz;
60  }
61 
62  PX_INLINE PxExtended magnitudeSquared() const
63  {
64  return x * x + y * y + z * z;
65  }
66 
67  PX_INLINE PxExtended magnitude() const
68  {
69  return PxSqrt(x * x + y * y + z * z);
70  }
71 
72  PX_INLINE PxExtended normalize()
73  {
74  PxExtended m = magnitude();
75  if (m)
76  {
77  const PxExtended il = PxExtended(1.0) / m;
78  x *= il;
79  y *= il;
80  z *= il;
81  }
82  return m;
83  }
84 
85  PX_INLINE bool isFinite() const
86  {
87  return PxIsFinite(x) && PxIsFinite(y) && PxIsFinite(z);
88  }
89 
90  PX_INLINE void maximum(const PxExtendedVec3& v)
91  {
92  if (x < v.x) x = v.x;
93  if (y < v.y) y = v.y;
94  if (z < v.z) z = v.z;
95  }
96 
97 
98  PX_INLINE void minimum(const PxExtendedVec3& v)
99  {
100  if (x > v.x) x = v.x;
101  if (y > v.y) y = v.y;
102  if (z > v.z) z = v.z;
103  }
104 
106  {
107  this->x = x_;
108  this->y = y_;
109  this->z = z_;
110  }
111 
112  PX_INLINE void setPlusInfinity()
113  {
114  x = y = z = PX_MAX_EXTENDED;
115  }
116 
117  PX_INLINE void setMinusInfinity()
118  {
119  x = y = z = -PX_MAX_EXTENDED;
120  }
121 
122  PX_INLINE void cross(const PxExtendedVec3& left, const PxVec3& right)
123  {
124  // temps needed in case left or right is this.
125  PxExtended a = (left.y * right.z) - (left.z * right.y);
126  PxExtended b = (left.z * right.x) - (left.x * right.z);
127  PxExtended c = (left.x * right.y) - (left.y * right.x);
128 
129  x = a;
130  y = b;
131  z = c;
132  }
133 
134  PX_INLINE void cross(const PxExtendedVec3& left, const PxExtendedVec3& right)
135  {
136  // temps needed in case left or right is this.
137  PxExtended a = (left.y * right.z) - (left.z * right.y);
138  PxExtended b = (left.z * right.x) - (left.x * right.z);
139  PxExtended c = (left.x * right.y) - (left.y * right.x);
140 
141  x = a;
142  y = b;
143  z = c;
144  }
145 
147  {
148  PxExtendedVec3 temp;
149  temp.cross(*this,v);
150  return temp;
151  }
152 
153  PX_INLINE void cross(const PxVec3& left, const PxExtendedVec3& right)
154  {
155  // temps needed in case left or right is this.
156  PxExtended a = (left.y * right.z) - (left.z * right.y);
157  PxExtended b = (left.z * right.x) - (left.x * right.z);
158  PxExtended c = (left.x * right.y) - (left.y * right.x);
159 
160  x = a;
161  y = b;
162  z = c;
163  }
164 
165  PX_INLINE PxExtendedVec3 operator-() const
166  {
167  return PxExtendedVec3(-x, -y, -z);
168  }
169 
171  {
172  x += v.x;
173  y += v.y;
174  z += v.z;
175  return *this;
176  }
177 
179  {
180  x -= v.x;
181  y -= v.y;
182  z -= v.z;
183  return *this;
184  }
185 
186  PX_INLINE PxExtendedVec3& operator+=(const PxVec3& v)
187  {
188  x += PxExtended(v.x);
189  y += PxExtended(v.y);
190  z += PxExtended(v.z);
191  return *this;
192  }
193 
194  PX_INLINE PxExtendedVec3& operator-=(const PxVec3& v)
195  {
196  x -= PxExtended(v.x);
197  y -= PxExtended(v.y);
198  z -= PxExtended(v.z);
199  return *this;
200  }
201 
202  PX_INLINE PxExtendedVec3& operator*=(const PxReal& s)
203  {
204  x *= PxExtended(s);
205  y *= PxExtended(s);
206  z *= PxExtended(s);
207  return *this;
208  }
209 
211  {
212  return PxExtendedVec3(x + v.x, y + v.y, z + v.z);
213  }
214 
215  PX_INLINE PxVec3 operator-(const PxExtendedVec3& v) const
216  {
217  return PxVec3(PxReal(x - v.x), PxReal(y - v.y), PxReal(z - v.z));
218  }
219 
220  PX_INLINE PxExtended& operator[](int index)
221  {
222  PX_ASSERT(index>=0 && index<=2);
223 
224  return reinterpret_cast<PxExtended*>(this)[index];
225  }
226 
227 
228  PX_INLINE PxExtended operator[](int index) const
229  {
230  PX_ASSERT(index>=0 && index<=2);
231 
232  return reinterpret_cast<const PxExtended*>(this)[index];
233  }
234 
236 };
237 
239  {
240  return PxVec3(float(v.x), float(v.y), float(v.z));
241  }
242 
243 #else
244 // Big worlds not defined
245 
246 typedef PxVec3 PxExtendedVec3;
247 typedef PxReal PxExtended;
248 #define PX_MAX_EXTENDED PX_MAX_F32
249 #define PxExtendedAbs(x) fabsf(x)
250 #endif
251 
252 #ifndef PX_DOXYGEN
253 } // namespace physx
254 #endif
255 
257 #endif


Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com