RavEngine
Loading...
Searching...
No Matches
PxVec4.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_VEC4_H
30#define PX_VEC4_H
31
35#include "foundation/PxMath.h"
36#include "foundation/PxVec3.h"
37
43#if !PX_DOXYGEN
44namespace physx
45{
46#endif
47
48template<class Type>
50{
51 public:
55 PX_CUDA_CALLABLE PX_INLINE PxVec4T()
56 {
57 }
58
62 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec4T(PxZERO) : x(Type(0.0)), y(Type(0.0)), z(Type(0.0)), w(Type(0.0))
63 {
64 }
65
73 explicit PX_CUDA_CALLABLE PX_INLINE PxVec4T(Type a) : x(a), y(a), z(a), w(a)
74 {
75 }
76
85 PX_CUDA_CALLABLE PX_INLINE PxVec4T(Type nx, Type ny, Type nz, Type nw) : x(nx), y(ny), z(nz), w(nw)
86 {
87 }
88
95 PX_CUDA_CALLABLE PX_INLINE PxVec4T(const PxVec3T<Type>& v, Type nw) : x(v.x), y(v.y), z(v.z), w(nw)
96 {
97 }
98
104 explicit PX_CUDA_CALLABLE PX_INLINE PxVec4T(const Type v[]) : x(v[0]), y(v[1]), z(v[2]), w(v[3])
105 {
106 }
107
111 PX_CUDA_CALLABLE PX_INLINE PxVec4T(const PxVec4T& v) : x(v.x), y(v.y), z(v.z), w(v.w)
112 {
113 }
114
115 // Operators
116
120 PX_CUDA_CALLABLE PX_INLINE PxVec4T& operator=(const PxVec4T& p)
121 {
122 x = p.x;
123 y = p.y;
124 z = p.z;
125 w = p.w;
126 return *this;
127 }
128
132 PX_CUDA_CALLABLE PX_INLINE Type& operator[](unsigned int index)
133 {
134 PX_ASSERT(index <= 3);
135 return reinterpret_cast<Type*>(this)[index];
136 }
137
141 PX_CUDA_CALLABLE PX_INLINE const Type& operator[](unsigned int index) const
142 {
143 PX_ASSERT(index <= 3);
144 return reinterpret_cast<const Type*>(this)[index];
145 }
146
150 PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxVec4T& v) const
151 {
152 return x == v.x && y == v.y && z == v.z && w == v.w;
153 }
154
158 PX_CUDA_CALLABLE PX_INLINE bool operator!=(const PxVec4T& v) const
159 {
160 return x != v.x || y != v.y || z != v.z || w != v.w;
161 }
162
166 PX_CUDA_CALLABLE PX_INLINE bool isZero() const
167 {
168 return x == Type(0) && y == Type(0) && z == Type(0) && w == Type(0);
169 }
170
174 PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
175 {
176 return PxIsFinite(x) && PxIsFinite(y) && PxIsFinite(z) && PxIsFinite(w);
177 }
178
182 PX_CUDA_CALLABLE PX_INLINE bool isNormalized() const
183 {
184 const Type unitTolerance = Type(1e-4);
185 return isFinite() && PxAbs(magnitude() - Type(1.0)) < unitTolerance;
186 }
187
193 PX_CUDA_CALLABLE PX_INLINE Type magnitudeSquared() const
194 {
195 return x * x + y * y + z * z + w * w;
196 }
197
201 PX_CUDA_CALLABLE PX_INLINE Type magnitude() const
202 {
203 return PxSqrt(magnitudeSquared());
204 }
205
209 PX_CUDA_CALLABLE PX_INLINE PxVec4T operator-() const
210 {
211 return PxVec4T(-x, -y, -z, -w);
212 }
213
217 PX_CUDA_CALLABLE PX_INLINE PxVec4T operator+(const PxVec4T& v) const
218 {
219 return PxVec4T(x + v.x, y + v.y, z + v.z, w + v.w);
220 }
221
225 PX_CUDA_CALLABLE PX_INLINE PxVec4T operator-(const PxVec4T& v) const
226 {
227 return PxVec4T(x - v.x, y - v.y, z - v.z, w - v.w);
228 }
229
233 PX_CUDA_CALLABLE PX_INLINE PxVec4T operator*(Type f) const
234 {
235 return PxVec4T(x * f, y * f, z * f, w * f);
236 }
237
241 PX_CUDA_CALLABLE PX_INLINE PxVec4T operator/(Type f) const
242 {
243 f = Type(1.0) / f;
244 return PxVec4T(x * f, y * f, z * f, w * f);
245 }
246
250 PX_CUDA_CALLABLE PX_INLINE PxVec4T& operator+=(const PxVec4T& v)
251 {
252 x += v.x;
253 y += v.y;
254 z += v.z;
255 w += v.w;
256 return *this;
257 }
258
262 PX_CUDA_CALLABLE PX_INLINE PxVec4T& operator-=(const PxVec4T& v)
263 {
264 x -= v.x;
265 y -= v.y;
266 z -= v.z;
267 w -= v.w;
268 return *this;
269 }
270
274 PX_CUDA_CALLABLE PX_INLINE PxVec4T& operator*=(Type f)
275 {
276 x *= f;
277 y *= f;
278 z *= f;
279 w *= f;
280 return *this;
281 }
285 PX_CUDA_CALLABLE PX_INLINE PxVec4T& operator/=(Type f)
286 {
287 f = Type(1.0) / f;
288 x *= f;
289 y *= f;
290 z *= f;
291 w *= f;
292 return *this;
293 }
294
298 PX_CUDA_CALLABLE PX_INLINE Type dot(const PxVec4T& v) const
299 {
300 return x * v.x + y * v.y + z * v.z + w * v.w;
301 }
302
304 PX_CUDA_CALLABLE PX_INLINE PxVec4T getNormalized() const
305 {
306 const Type m = magnitudeSquared();
307 return m > Type(0.0) ? *this * PxRecipSqrt(m) : PxVec4T(Type(0));
308 }
309
313 PX_CUDA_CALLABLE PX_INLINE Type normalize()
314 {
315 const Type m = magnitude();
316 if(m > Type(0.0))
317 *this /= m;
318 return m;
319 }
320
324 PX_CUDA_CALLABLE PX_INLINE PxVec4T multiply(const PxVec4T& a) const
325 {
326 return PxVec4T(x * a.x, y * a.y, z * a.z, w * a.w);
327 }
328
332 PX_CUDA_CALLABLE PX_INLINE PxVec4T minimum(const PxVec4T& v) const
333 {
334 return PxVec4(PxMin(x, v.x), PxMin(y, v.y), PxMin(z, v.z), PxMin(w, v.w));
335 }
336
340 PX_CUDA_CALLABLE PX_INLINE PxVec4T maximum(const PxVec4T& v) const
341 {
342 return PxVec4T(PxMax(x, v.x), PxMax(y, v.y), PxMax(z, v.z), PxMax(w, v.w));
343 }
344
345 PX_CUDA_CALLABLE PX_INLINE PxVec3T<Type> getXYZ() const
346 {
347 return PxVec3T<Type>(x, y, z);
348 }
349
350 Type x, y, z, w;
351};
352
353template<class Type>
354PX_CUDA_CALLABLE static PX_INLINE PxVec4T<Type> operator*(Type f, const PxVec4T<Type>& v)
355{
356 return PxVec4T<Type>(f * v.x, f * v.y, f * v.z, f * v.w);
357}
358
359typedef PxVec4T<float> PxVec4;
360typedef PxVec4T<double> PxVec4d;
361
362#if !PX_DOXYGEN
363} // namespace physx
364#endif
365
367#endif
368
3 Element vector class.
Definition PxVec3.h:50
Definition PxVec4.h:50
PX_CUDA_CALLABLE PX_INLINE PxVec4T & operator/=(Type f)
scalar division
Definition PxVec4.h:285
PX_CUDA_CALLABLE PX_INLINE PxVec4T(Type nx, Type ny, Type nz, Type nw)
Initializes from 3 scalar parameters.
Definition PxVec4.h:85
PX_CUDA_CALLABLE PX_INLINE PxVec4T multiply(const PxVec4T &a) const
a[i] * b[i], for all i.
Definition PxVec4.h:324
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec4T(PxZERO)
zero constructor.
Definition PxVec4.h:62
PX_CUDA_CALLABLE PX_INLINE Type dot(const PxVec4T &v) const
returns the scalar product of this and other.
Definition PxVec4.h:298
PX_CUDA_CALLABLE PX_INLINE PxVec4T operator+(const PxVec4T &v) const
vector addition
Definition PxVec4.h:217
PX_CUDA_CALLABLE PX_INLINE Type magnitudeSquared() const
returns the squared magnitude
Definition PxVec4.h:193
PX_CUDA_CALLABLE PX_INLINE PxVec4T & operator=(const PxVec4T &p)
Assignment operator.
Definition PxVec4.h:120
PX_CUDA_CALLABLE PX_INLINE PxVec4T(Type a)
Assigns scalar parameter to all elements.
Definition PxVec4.h:73
PX_CUDA_CALLABLE PX_INLINE PxVec4T & operator*=(Type f)
scalar multiplication
Definition PxVec4.h:274
PX_CUDA_CALLABLE PX_INLINE Type magnitude() const
returns the magnitude
Definition PxVec4.h:201
PX_CUDA_CALLABLE PX_INLINE bool operator!=(const PxVec4T &v) const
returns true if the two vectors are not exactly equal.
Definition PxVec4.h:158
PX_CUDA_CALLABLE PX_INLINE PxVec4T(const Type v[])
Initializes from an array of scalar parameters.
Definition PxVec4.h:104
PX_CUDA_CALLABLE PX_INLINE PxVec4T maximum(const PxVec4T &v) const
element-wise maximum
Definition PxVec4.h:340
PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxVec4T &v) const
returns true if the two vectors are exactly equal.
Definition PxVec4.h:150
PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
returns true if all 3 elems of the vector are finite (not NAN or INF, etc.)
Definition PxVec4.h:174
PX_CUDA_CALLABLE PX_INLINE Type & operator[](unsigned int index)
element access
Definition PxVec4.h:132
PX_CUDA_CALLABLE PX_INLINE PxVec4T minimum(const PxVec4T &v) const
element-wise minimum
Definition PxVec4.h:332
PX_CUDA_CALLABLE PX_INLINE PxVec4T operator-(const PxVec4T &v) const
vector difference
Definition PxVec4.h:225
PX_CUDA_CALLABLE PX_INLINE Type normalize()
normalizes the vector in place
Definition PxVec4.h:313
PX_CUDA_CALLABLE PX_INLINE PxVec4T(const PxVec4T &v)
Copy ctor.
Definition PxVec4.h:111
PX_CUDA_CALLABLE PX_INLINE PxVec4T()
default constructor leaves data uninitialized.
Definition PxVec4.h:55
PX_CUDA_CALLABLE PX_INLINE PxVec4T getNormalized() const
Definition PxVec4.h:304
PX_CUDA_CALLABLE PX_INLINE PxVec4T & operator-=(const PxVec4T &v)
vector difference
Definition PxVec4.h:262
PX_CUDA_CALLABLE PX_INLINE bool isZero() const
tests for exact zero vector
Definition PxVec4.h:166
PX_CUDA_CALLABLE PX_INLINE PxVec4T(const PxVec3T< Type > &v, Type nw)
Initializes from 3 scalar parameters.
Definition PxVec4.h:95
PX_CUDA_CALLABLE PX_INLINE PxVec4T operator-() const
negation
Definition PxVec4.h:209
PX_CUDA_CALLABLE PX_INLINE PxVec4T & operator+=(const PxVec4T &v)
vector addition
Definition PxVec4.h:250
PX_CUDA_CALLABLE PX_INLINE PxVec4T operator/(Type f) const
scalar division
Definition PxVec4.h:241
PX_CUDA_CALLABLE PX_INLINE PxVec4T operator*(Type f) const
scalar post-multiplication
Definition PxVec4.h:233
PX_CUDA_CALLABLE PX_INLINE bool isNormalized() const
is normalized - used by API parameter validation
Definition PxVec4.h:182
PX_CUDA_CALLABLE PX_INLINE const Type & operator[](unsigned int index) const
element access
Definition PxVec4.h:141
Definition PxVec4.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 float PxAbs(float a)
abs returns the absolute value of its argument.
Definition PxMath.h:109
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxRecipSqrt(float a)
reciprocal square root.
Definition PxMath.h:158
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
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMax(T a, T b)
The return value is the greater of the two specified values.
Definition PxMath.h:72
PxZERO
Definition Px.h:93
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b)
The return value is the lesser of the two specified values.
Definition PxMath.h:88