1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_COMMON_MATRIX34
#define PX_PHYSICS_COMMON_MATRIX34
#include "foundation/PxVec3.h"
#include "foundation/PxTransform.h"
#include "foundation/PxMat33.h"
#include "CmPhysXCommon.h"
namespace physx
{
namespace Cm
{
/*!
Basic mathematical 3x4 matrix, implemented as a 3x3 rotation matrix and a translation
See PxMat33 for the format of the rotation matrix.
*/
class Matrix34
{
public:
//! Default constructor
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34()
{}
//! Construct from four base vectors
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34(const PxVec3& b0, const PxVec3& b1, const PxVec3& b2, const PxVec3& b3)
: m(b0, b1, b2), p(b3)
{}
//! Construct from float[12]
explicit PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34(PxReal values[]):
m(values), p(values[9], values[10], values[11])
{
}
//! Construct from a 3x3 matrix
explicit PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34(const PxMat33& other)
: m(other), p(PxZero)
{
}
//! Construct from a 3x3 matrix and a translation vector
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34(const PxMat33& other, const PxVec3& t)
: m(other), p(t)
{}
//! Construct from a PxTransform
explicit PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34(const PxTransform& other):
m(other.q), p(other.p)
{
}
//! Construct from a quaternion
explicit PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34(const PxQuat& q):
m(q), p(PxZero)
{
}
//! Copy constructor
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34(const Matrix34& other):
m(other.m), p(other.p)
{
}
//! Assignment operator
PX_CUDA_CALLABLE PX_FORCE_INLINE const Matrix34& operator=(const Matrix34& other)
{
m = other.m;
p = other.p;
return *this;
}
//! Set to identity matrix
PX_CUDA_CALLABLE PX_FORCE_INLINE void setIdentity()
{
m = PxMat33(PxIdentity);
p = PxVec3(0);
}
// Simpler operators
//! Equality operator
PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator==(const Matrix34& other) const
{
return m == other.m && p == other.p;
}
//! Inequality operator
PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator!=(const Matrix34& other) const
{
return !operator==(other);
}
//! Unary minus
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34 operator-() const
{
return Matrix34(-m, -p);
}
//! Add
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34 operator+(const Matrix34& other) const
{
return Matrix34(m + other.m, p + other.p);
}
//! Subtract
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34 operator-(const Matrix34& other) const
{
return Matrix34(m - other.m, p - other.p);
}
//! Scalar multiplication
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34 operator*(PxReal scalar) const
{
return Matrix34(m*scalar, p*scalar);
}
friend Matrix34 operator*(PxReal, const Matrix34&);
//! Matrix multiplication
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34 operator*(const Matrix34& other) const
{
//Rows from this <dot> columns from other
//base0 = rotate(other.m.column0) etc
return Matrix34(m*other.m, m*other.p + p);
}
//! Matrix multiplication, extend the second matrix
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34 operator*(const PxMat33& other) const
{
//Rows from this <dot> columns from other
//base0 = transform(other.m.column0) etc
return Matrix34(m*other, p);
}
friend Matrix34 operator*(const PxMat33& a, const Matrix34& b);
// a <op>= b operators
//! Equals-add
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34& operator+=(const Matrix34& other)
{
m += other.m;
p += other.p;
return *this;
}
//! Equals-sub
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34& operator-=(const Matrix34& other)
{
m -= other.m;
p -= other.p;
return *this;
}
//! Equals scalar multiplication
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34& operator*=(PxReal scalar)
{
m *= scalar;
p *= scalar;
return *this;
}
//! Element access, mathematical way!
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal operator()(PxU32 row, PxU32 col) const
{
return (*this)[col][row];
}
//! Element access, mathematical way!
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal& operator()(PxU32 row, PxU32 col)
{
return (*this)[col][row];
}
// Transform etc
//! Transform vector by matrix, equal to v' = M*v
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotate(const PxVec3& other) const
{
return m*other;
}
//! Transform vector by transpose of matrix, equal to v' = M^t*v
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotateTranspose(const PxVec3& other) const
{
return m.transformTranspose(other);
}
//! Transform point by matrix
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transform(const PxVec3& other) const
{
return m*other + p;
}
//! Transform point by transposed matrix
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transformTranspose(const PxVec3& other) const
{
return m.transformTranspose(other - p);
}
//! Transform point by transposed matrix
PX_CUDA_CALLABLE PX_FORCE_INLINE Cm::Matrix34 transformTranspose(const Cm::Matrix34& other) const
{
return Cm::Matrix34(m.transformTranspose(other.m.column0),
m.transformTranspose(other.m.column1),
m.transformTranspose(other.m.column2),
m.transformTranspose(other.p - p));
}
//! Invert matrix treating it as a rotation+translation matrix only
PX_CUDA_CALLABLE PX_FORCE_INLINE Matrix34 getInverseRT() const
{
return Matrix34(m.getTranspose(), m.transformTranspose(-p));
}
// Conversion
//! Set matrix from quaternion
PX_CUDA_CALLABLE PX_FORCE_INLINE void set(const PxQuat& q)
{
m = PxMat33(q);
p = PxVec3(PxZero);
}
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator[](unsigned int num){return (&m.column0)[num];}
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator[](int num) { return (&m.column0)[num]; }
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3& operator[](unsigned int num) const { return (&m.column0)[num]; }
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3& operator[](int num) const { return (&m.column0)[num]; }
//Data, see above for format!
PxMat33 m;
PxVec3 p;
};
//! Multiply a*b, a is extended
PX_INLINE Matrix34 operator*(const PxMat33& a, const Matrix34& b)
{
return Matrix34(a * b.m, a * b.p);
}
} // namespace Cm
}
#endif
|