RavEngine
Loading...
Searching...
No Matches
PxMat34.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_MAT34_H
30#define PX_MAT34_H
35#include "foundation/PxTransform.h"
36#include "foundation/PxMat33.h"
37
38#if !PX_DOXYGEN
39namespace physx
40{
41#endif
48template<class Type>
50{
51 public:
53 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T()
54 {
55 }
56
58 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxVec3T<Type>& b0, const PxVec3T<Type>& b1, const PxVec3T<Type>& b2, const PxVec3T<Type>& b3)
59 : m(b0, b1, b2), p(b3)
60 {
61 }
62
64 explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(Type values[]) :
65 m(values), p(values[9], values[10], values[11])
66 {
67 }
68
70 explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxMat33T<Type>& other)
71 : m(other), p(PxZero)
72 {
73 }
74
76 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxMat33T<Type>& other, const PxVec3T<Type>& t)
77 : m(other), p(t)
78 {
79 }
80
82 explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxTransformT<Type>& other)
83 : m(other.q), p(other.p)
84 {
85 }
86
88 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxMat34T& other) : m(other.m), p(other.p)
89 {
90 }
91
93 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxMat34T& operator=(const PxMat34T& other)
94 {
95 m = other.m;
96 p = other.p;
97 return *this;
98 }
99
101 PX_CUDA_CALLABLE PX_FORCE_INLINE void setIdentity()
102 {
103 m = PxMat33T<Type>(PxIdentity);
104 p = PxVec3T<Type>(0);
105 }
106
107 // Simpler operators
109 PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator==(const PxMat34T& other) const
110 {
111 return m == other.m && p == other.p;
112 }
113
115 PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator!=(const PxMat34T& other) const
116 {
117 return !operator==(other);
118 }
119
121 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator-() const
122 {
123 return PxMat34T(-m, -p);
124 }
125
127 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator+(const PxMat34T& other) const
128 {
129 return PxMat34T(m + other.m, p + other.p);
130 }
131
133 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator-(const PxMat34T& other) const
134 {
135 return PxMat34T(m - other.m, p - other.p);
136 }
137
139 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator*(Type scalar) const
140 {
141 return PxMat34T(m*scalar, p*scalar);
142 }
143
145 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator*(const PxMat34T& other) const
146 {
147 //Rows from this <dot> columns from other
148 //base0 = rotate(other.m.column0) etc
149 return PxMat34T(m*other.m, m*other.p + p);
150 }
151
153 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator*(const PxMat33T<Type>& other) const
154 {
155 //Rows from this <dot> columns from other
156 //base0 = transform(other.m.column0) etc
157 return PxMat34T(m*other, p);
158 }
159
160 template<class Type2>
161 friend PxMat34T<Type2> operator*(const PxMat33T<Type2>& a, const PxMat34T<Type2>& b);
162
163 // a <op>= b operators
164
166 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T& operator+=(const PxMat34T& other)
167 {
168 m += other.m;
169 p += other.p;
170 return *this;
171 }
172
174 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T& operator-=(const PxMat34T& other)
175 {
176 m -= other.m;
177 p -= other.p;
178 return *this;
179 }
180
182 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T& operator*=(Type scalar)
183 {
184 m *= scalar;
185 p *= scalar;
186 return *this;
187 }
188
190 PX_CUDA_CALLABLE PX_FORCE_INLINE Type operator()(PxU32 row, PxU32 col) const
191 {
192 return (*this)[col][row];
193 }
194
196 PX_CUDA_CALLABLE PX_FORCE_INLINE Type& operator()(PxU32 row, PxU32 col)
197 {
198 return (*this)[col][row];
199 }
200
201 // Transform etc
202
204 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T<Type> rotate(const PxVec3T<Type>& other) const
205 {
206 return m*other;
207 }
208
210 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T<Type> rotateTranspose(const PxVec3T<Type>& other) const
211 {
212 return m.transformTranspose(other);
213 }
214
216 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T<Type> transform(const PxVec3T<Type>& other) const
217 {
218 return m*other + p;
219 }
220
223 {
224 return m.transformTranspose(other - p);
225 }
226
228 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T transformTranspose(const PxMat34T& other) const
229 {
230 return PxMat34T(m.transformTranspose(other.m.column0),
231 m.transformTranspose(other.m.column1),
232 m.transformTranspose(other.m.column2),
233 m.transformTranspose(other.p - p));
234 }
235
237 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T getInverseRT() const
238 {
239 return PxMat34T(m.getTranspose(), m.transformTranspose(-p));
240 }
241
242 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T<Type>& operator[](PxU32 num) { return (&m.column0)[num]; }
243 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3T<Type>& operator[](PxU32 num) const { return (&m.column0)[num]; }
244
245 //Data, see above for format!
246
247 PxMat33T<Type> m;
248 PxVec3T<Type> p;
249};
250
252template<class Type>
254{
255 return PxMat34T<Type>(a * b.m, a * b.p);
256}
257
258typedef PxMat34T<float> PxMat34;
259typedef PxMat34T<double> PxMat34d;
260
262class PxMat34Padded : public PxMat34
263{
264 public:
265 PX_FORCE_INLINE PxMat34Padded(const PxMat34& src) : PxMat34(src) {}
268 PxU32 padding;
269};
270PX_COMPILE_TIME_ASSERT(0==(sizeof(PxMat34Padded)==16));
271
272#if !PX_DOXYGEN
273} // namespace physx
274#endif
275
277#endif
3x3 matrix class
Definition PxMat33.h:91
A padded version of PxMat34, to safely load its data using SIMD.
Definition PxMat34.h:263
Definition PxMat34.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxMat33T< Type > &other, const PxVec3T< Type > &t)
Construct from a 3x3 matrix and a translation vector.
Definition PxMat34.h:76
PX_CUDA_CALLABLE PX_FORCE_INLINE Type & operator()(PxU32 row, PxU32 col)
Element access, mathematical way!
Definition PxMat34.h:196
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxMat33T< Type > &other)
Construct from a 3x3 matrix.
Definition PxMat34.h:70
PX_CUDA_CALLABLE PX_FORCE_INLINE Type operator()(PxU32 row, PxU32 col) const
Element access, mathematical way!
Definition PxMat34.h:190
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxMat34T & operator=(const PxMat34T &other)
Assignment operator.
Definition PxMat34.h:93
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxMat34T &other)
Copy constructor.
Definition PxMat34.h:88
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T getInverseRT() const
Invert matrix treating it as a rotation+translation matrix only.
Definition PxMat34.h:237
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T< Type > rotateTranspose(const PxVec3T< Type > &other) const
Transform vector by transpose of matrix, equal to v' = M^t*v.
Definition PxMat34.h:210
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxTransformT< Type > &other)
Construct from a PxTransformT<Type>
Definition PxMat34.h:82
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(Type values[])
Construct from Type[12].
Definition PxMat34.h:64
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T & operator-=(const PxMat34T &other)
Equals-sub.
Definition PxMat34.h:174
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T< Type > rotate(const PxVec3T< Type > &other) const
Transform vector by matrix, equal to v' = M*v.
Definition PxMat34.h:204
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T & operator*=(Type scalar)
Equals scalar multiplication.
Definition PxMat34.h:182
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator*(const PxMat33T< Type > &other) const
Matrix multiplication, extend the second matrix.
Definition PxMat34.h:153
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T()
Default constructor.
Definition PxMat34.h:53
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator*(Type scalar) const
Scalar multiplication.
Definition PxMat34.h:139
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T & operator+=(const PxMat34T &other)
Equals-add.
Definition PxMat34.h:166
PX_CUDA_CALLABLE PX_FORCE_INLINE void setIdentity()
Set to identity matrix.
Definition PxMat34.h:101
PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator!=(const PxMat34T &other) const
Inequality operator.
Definition PxMat34.h:115
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator*(const PxMat34T &other) const
Matrix multiplication.
Definition PxMat34.h:145
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T transformTranspose(const PxMat34T &other) const
Transform point by transposed matrix.
Definition PxMat34.h:228
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T< Type > transform(const PxVec3T< Type > &other) const
Transform point by matrix.
Definition PxMat34.h:216
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator-(const PxMat34T &other) const
Subtract.
Definition PxMat34.h:133
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T(const PxVec3T< Type > &b0, const PxVec3T< Type > &b1, const PxVec3T< Type > &b2, const PxVec3T< Type > &b3)
Construct from four base vectors.
Definition PxMat34.h:58
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T< Type > transformTranspose(const PxVec3T< Type > &other) const
Transform point by transposed matrix.
Definition PxMat34.h:222
PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator==(const PxMat34T &other) const
Equality operator.
Definition PxMat34.h:109
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator-() const
Unary minus.
Definition PxMat34.h:121
PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat34T operator+(const PxMat34T &other) const
Add.
Definition PxMat34.h:127
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:48
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#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