#include <Matrix4.h>
|
| Matrix4 (const Any &any) |
|
Any | toAny () const |
|
| Matrix4 (float r1c1, float r1c2, float r1c3, float r1c4, float r2c1, float r2c2, float r2c3, float r2c4, float r3c1, float r3c2, float r3c3, float r3c4, float r4c1, float r4c2, float r4c3, float r4c4) |
|
| Matrix4 (const float *init) |
|
| Matrix4 (const class Matrix3 &upper3x3, const class Vector3 &lastCol=Vector3::zero()) |
|
| Matrix4 (const class CoordinateFrame &c) |
|
| Matrix4 (const double *init) |
|
| Matrix4 () |
|
class CoordinateFrame | approxCoordinateFrame () const |
|
void | getPerspectiveProjectionParameters (double &left, double &right, double &bottom, double &top, double &nearval, double &farval, float updirection=-1.0f) const |
|
float * | operator[] (int r) |
|
const float * | operator[] (int r) const |
|
| operator float * () |
|
| operator const float * () const |
|
Matrix4 | operator* (const Matrix4 &other) const |
|
Matrix4 | operator+ (const Matrix4 &other) const |
|
class Matrix3 | upper3x3 () const |
|
class Matrix2 | upper2x2 () const |
|
class Vector3 | homoMul (const class Vector3 &v, float w) const |
|
void | setRow (int r, const class Vector4 &v) |
|
void | setColumn (int c, const Vector4 &v) |
|
const Vector4 & | row (int r) const |
|
Vector4 | column (int c) const |
|
Matrix4 | operator* (const float s) const |
|
Vector4 | operator* (const Vector4 &vector) const |
|
Matrix4 | transpose () const |
|
bool | operator!= (const Matrix4 &other) const |
|
bool | operator== (const Matrix4 &other) const |
|
float | determinant () const |
|
Matrix4 | inverse () const |
|
Matrix4 | adjoint () const |
|
Matrix4 | cofactor () const |
|
void | serialize (class BinaryOutput &b) const |
|
void | deserialize (class BinaryInput &b) |
|
std::string | toString () const |
|
|
static Matrix4 | diagonal (float e00, float e11, float e22, float e33) |
|
static const Matrix4 & | identity () |
|
static const Matrix4 & | zero () |
|
static Matrix4 | orthogonalProjection (float left, float right, float bottom, float top, float nearval, float farval, float upDirection=-1.0f) |
|
static Matrix4 | orthogonalProjection (const class Rect2D &rect, float nearval, float farval, float upDirection=-1.0f) |
|
static Matrix4 | perspectiveProjection (double left, double right, double bottom, double top, double nearval, double farval, float upDirection=-1.0f) |
|
static Matrix4 | scale (const Vector3 &v) |
|
static Matrix4 | scale (float x, float y, float z) |
|
static Matrix4 | scale (float s) |
|
static Matrix4 | translation (const Vector3 &v) |
|
static Matrix4 | translation (float x, float y, float z) |
|
static Matrix4 | yawDegrees (float deg) |
|
static Matrix4 | pitchDegrees (float deg) |
|
static Matrix4 | rollDegrees (float deg) |
|
A 4x4 matrix. Do not subclass. Data is initialized to 0 when default constructed.
- See also
- G3D::CoordinateFrame, G3D::Matrix3, G3D::Quat
G3D::Matrix4::Matrix4 |
( |
const Any & |
any | ) |
|
|
explicit |
Must be in one of the following forms:
27 any.verifyNameBeginsWith(
"Matrix4",
"CFrame",
"CoordinateFrame");
30 const std::string& name =
any.name();
31 if (name ==
"Matrix4") {
34 for (
int r = 0; r < 4; ++r) {
35 for (
int c = 0; c < 4; ++c) {
36 elt[r][c] =
any[r * 4 + c];
39 }
else if (name ==
"Matrix4::scale") {
40 if (
any.size() == 1) {
42 }
else if (
any.size() == 3) {
45 any.verify(
false,
"Matrix4::scale() takes either 1 or 3 arguments");
47 }
else if (name ==
"Matrix4::rollDegrees") {
50 }
else if (name ==
"Matrix4::yawDegrees") {
53 }
else if (name ==
"Matrix4::pitchDegrees") {
56 }
else if (name ==
"Matrix4::translation") {
57 if (
any.size() == 3) {
60 any.verify(
false,
"Matrix4::translation() requires 3 arguments");
62 }
else if (name ==
"Matrix4::diagonal") {
65 }
else if (name ==
"Matrix4::identity") {
70 any.verify(
false,
"Expected Matrix4 constructor");
bool beginsWith(const std::string &test, const std::string &pattern)
Returns true if the test string begins with the pattern string.
Definition: stringutils.cpp:81
static Matrix4 diagonal(float e00, float e11, float e22, float e33)
Definition: Matrix4.h:92
static Matrix4 scale(const Vector3 &v)
Definition: Matrix4.h:239
static Matrix4 translation(const Vector3 &v)
Definition: Matrix4.h:257
class CoordinateFrame CFrame
Definition: Box2D.h:22
bool any(float x)
Definition: g3dmath.h:424
static Matrix4 rollDegrees(float deg)
Definition: Matrix4.h:274
static Matrix4 yawDegrees(float deg)
Definition: Matrix4.h:266
static const Matrix4 & identity()
Definition: Matrix4.cpp:87
float elt[4][4]
Definition: Matrix4.h:39
static Matrix4 pitchDegrees(float deg)
Definition: Matrix4.h:270
G3D::Matrix4::Matrix4 |
( |
float |
r1c1, |
|
|
float |
r1c2, |
|
|
float |
r1c3, |
|
|
float |
r1c4, |
|
|
float |
r2c1, |
|
|
float |
r2c2, |
|
|
float |
r2c3, |
|
|
float |
r2c4, |
|
|
float |
r3c1, |
|
|
float |
r3c2, |
|
|
float |
r3c3, |
|
|
float |
r3c4, |
|
|
float |
r4c1, |
|
|
float |
r4c2, |
|
|
float |
r4c3, |
|
|
float |
r4c4 |
|
) |
| |
278 elt[0][0] = r1c1;
elt[0][1] = r1c2;
elt[0][2] = r1c3;
elt[0][3] = r1c4;
279 elt[1][0] = r2c1;
elt[1][1] = r2c2;
elt[1][2] = r2c3;
elt[1][3] = r2c4;
280 elt[2][0] = r3c1;
elt[2][1] = r3c2;
elt[2][2] = r3c3;
elt[2][3] = r3c4;
281 elt[3][0] = r4c1;
elt[3][1] = r4c2;
elt[3][2] = r4c3;
elt[3][3] = r4c4;
float elt[4][4]
Definition: Matrix4.h:39
G3D::Matrix4::Matrix4 |
( |
const float * |
init | ) |
|
init should be row major.
288 for (
int r = 0; r < 4; ++r) {
289 for (
int c = 0; c < 4; ++c) {
290 elt[r][c] = init[r * 4 + c];
float elt[4][4]
Definition: Matrix4.h:39
a is the upper left 3x3 submatrix and b is the upper right 3x1 submatrix. The last row of the created matrix is (0,0,0,1).
108 for (
int r = 0; r < 3; ++r) {
109 for (
int c = 0; c < 3; ++c) {
110 elt[r][c] = cframe.rotation[r][c];
112 elt[r][3] = cframe.translation[r];
float elt[4][4]
Definition: Matrix4.h:39
G3D::Matrix4::Matrix4 |
( |
const double * |
init | ) |
|
297 for (
int r = 0; r < 4; ++r) {
298 for (
int c = 0; c < 4; ++c) {
299 elt[r][c] = (float)init[r * 4 + c];
float elt[4][4]
Definition: Matrix4.h:39
G3D::Matrix4::Matrix4 |
( |
| ) |
|
Matrix4::zero()
306 for (
int r = 0; r < 4; ++r) {
307 for (
int c = 0; c < 4; ++c) {
float elt[4][4]
Definition: Matrix4.h:39
Matrix4 G3D::Matrix4::adjoint |
( |
| ) |
const |
Transpose of the cofactor matrix (used in computing the inverse). Note: This is in fact only one type of adjoint. More generally, an adjoint of a matrix is any mapping of a matrix which possesses certain properties. This returns the so-called adjugate or classical adjoint.
Matrix4 transpose() const
Definition: Matrix4.cpp:386
Matrix4 cofactor() const
Definition: Matrix4.cpp:449
Produces an RT transformation that nearly matches this Matrix4. Because a Matrix4 may not be precisely a rotation and translation, this may introduce error.
508 CoordinateFrame cframe;
510 for (
int r = 0; r < 3; ++r) {
511 for (
int c = 0; c < 3; ++c) {
512 cframe.rotation[r][c] =
elt[r][c];
514 cframe.translation[r] =
elt[r][3];
518 cframe.rotation.orthonormalize();
float elt[4][4]
Definition: Matrix4.h:39
Matrix4 G3D::Matrix4::cofactor |
( |
| ) |
const |
455 for (
int r = 0; r < 4; ++r) {
456 for (
int c = 0; c < 4; ++c) {
459 out.elt[r][c] = i * det;
float subDeterminant(int excludeRow, int excludeCol) const
Definition: Matrix4.cpp:469
Matrix4()
Definition: Matrix4.cpp:305
Vector4 G3D::Matrix4::column |
( |
int |
c | ) |
const |
335 for (
int r = 0; r < 4; ++r) {
float elt[4][4]
Definition: Matrix4.h:39
void G3D::Matrix4::deserialize |
( |
class BinaryInput & |
b | ) |
|
534 for (
int r = 0; r < 4; ++r) {
535 for (
int c = 0; c < 4; ++c) {
536 elt[r][c] = b.readFloat32();
float elt[4][4]
Definition: Matrix4.h:39
float G3D::Matrix4::determinant |
( |
| ) |
const |
Matrix4 cofactor() const
Definition: Matrix4.cpp:449
const Vector4 & row(int r) const
Definition: Matrix4.cpp:328
float dot(const Vector4 &rkVector) const
Definition: Vector4.h:659
static Matrix4 G3D::Matrix4::diagonal |
( |
float |
e00, |
|
|
float |
e11, |
|
|
float |
e22, |
|
|
float |
e33 |
|
) |
| |
|
inlinestatic |
Matrix4()
Definition: Matrix4.cpp:305
void G3D::Matrix4::getPerspectiveProjectionParameters |
( |
double & |
left, |
|
|
double & |
right, |
|
|
double & |
bottom, |
|
|
double & |
top, |
|
|
double & |
nearval, |
|
|
double & |
farval, |
|
|
float |
updirection = -1.0f |
|
) |
| const |
If this is a perspective projection matrix created by Matrix4::perspectiveProjection, extract its parameters.
Uses double precision because the operations involved in projection involve divisions that can significantly impact precision.
235 debugAssertM(
abs(upDirection) == 1.0f,
"upDirection must be -1 or +1");
237 double x =
elt[0][0];
238 double y =
elt[1][1] * upDirection;
239 double a =
elt[0][2];
240 double b =
elt[1][2] * upDirection;
241 double c =
elt[2][2];
242 double d =
elt[2][3];
260 nearval = d * ((c - 1.0) / (c + 1.0) - 1.0) / (-2.0 * (c - 1.0) / (c + 1.0));
261 farval = nearval * ((c - 1.0) / (c + 1.0));
265 left = (a - 1.0) * nearval /
x;
266 right = 2.0 * nearval /
x +
left;
268 bottom = (b - 1.0) * nearval /
y;
269 top = 2.0 * nearval /
y + bottom;
float finf()
Definition: g3dmath.cpp:71
double abs(double fValue)
Definition: g3dmath.h:617
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
G3D::int16 y
Definition: Vector2int16.h:38
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
float elt[4][4]
Definition: Matrix4.h:39
G3D::int16 x
Definition: Vector2int16.h:37
Homogeneous multiplication. Let k = M * [v w]^T. result = k.xyz() / k.w
369 Vector4 r = (*this) * Vector4(v, w);
370 return r.xyz() * (1.0f / r.w);
Matrix4()
Definition: Matrix4.cpp:305
Matrix4 G3D::Matrix4::inverse |
( |
| ) |
const |
443 float det = A.column(0).dot(
row(0));
445 return A * (1.0f / det);
const Vector4 & row(int r) const
Definition: Matrix4.cpp:328
Matrix4()
Definition: Matrix4.cpp:305
Matrix4 adjoint() const
Definition: Matrix4.cpp:431
G3D::Matrix4::operator const float * |
( |
| ) |
const |
|
inline |
143 return (
const float*)&
elt[0][0];
float elt[4][4]
Definition: Matrix4.h:39
G3D::Matrix4::operator float * |
( |
| ) |
|
|
inline |
Returns a row-major pointer.
139 return (
float*)&
elt[0][0];
float elt[4][4]
Definition: Matrix4.h:39
399 return ! (*
this == other);
344 for (
int r = 0; r < 4; ++r) {
345 for (
int c = 0; c < 4; ++c) {
346 for (
int i = 0; i < 4; ++i) {
347 result.elt[r][c] +=
elt[r][i] * other.elt[i][c];
Matrix4()
Definition: Matrix4.cpp:305
float elt[4][4]
Definition: Matrix4.h:39
358 for (
int r = 0; r < 4; ++r) {
359 for (
int c = 0; c < 4; ++c) {
360 result.elt[r][c] =
elt[r][c] * s;
Matrix4()
Definition: Matrix4.cpp:305
float elt[4][4]
Definition: Matrix4.h:39
375 Vector4 result(0,0,0,0);
376 for (
int r = 0; r < 4; ++r) {
377 for (
int c = 0; c < 4; ++c) {
378 result[r] +=
elt[r][c] * vector[c];
float elt[4][4]
Definition: Matrix4.h:39
149 for (
int r = 0; r < 4; ++r) {
150 for (
int c = 0; c < 4; ++c) {
151 result.elt[r][c] =
elt[r][c] + other.elt[r][c];
Matrix4()
Definition: Matrix4.cpp:305
float elt[4][4]
Definition: Matrix4.h:39
408 if (memcmp(
this, &other,
sizeof(
Matrix4)) == 0) {
412 for (
int r = 0; r < 4; ++r) {
413 for (
int c = 0; c < 4; ++c) {
414 if (
elt[r][c] != other.elt[r][c]) {
Matrix4()
Definition: Matrix4.cpp:305
float elt[4][4]
Definition: Matrix4.h:39
float* G3D::Matrix4::operator[] |
( |
int |
r | ) |
|
|
inline |
128 return (
float*)&
elt[r];
#define debugAssert(exp)
Definition: debugAssert.h:160
float elt[4][4]
Definition: Matrix4.h:39
const float* G3D::Matrix4::operator[] |
( |
int |
r | ) |
const |
|
inline |
134 return (
const float*)&
elt[r];
#define debugAssert(exp)
Definition: debugAssert.h:160
float elt[4][4]
Definition: Matrix4.h:39
Matrix4 G3D::Matrix4::orthogonalProjection |
( |
float |
left, |
|
|
float |
right, |
|
|
float |
bottom, |
|
|
float |
top, |
|
|
float |
nearval, |
|
|
float |
farval, |
|
|
float |
upDirection = -1.0f |
|
) |
| |
|
static |
Constructs an orthogonal projection matrix from the given parameters. Near and far are the NEGATIVE of the near and far plane Z values (to follow OpenGL conventions).
- Parameters
-
upDirection | Use -1.0 for 2D Y increasing downwards (the G3D 8.x default convention), 1.0 for 2D Y increasing upwards (the G3D 7.x default and OpenGL convention) |
171 x = 2.0f / (right-
left);
172 y = 2.0f / (top-bottom);
173 z = -2.0f / (farval-nearval);
175 ty = -(top+bottom) / (top-bottom);
176 tz = -(farval+nearval) / (farval-nearval);
185 0.0f, 0.0f, 0.0f, 1.0f);
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
Matrix4()
Definition: Matrix4.cpp:305
G3D::int16 x
Definition: Vector2int16.h:37
Matrix4 G3D::Matrix4::orthogonalProjection |
( |
const class Rect2D & |
rect, |
|
|
float |
nearval, |
|
|
float |
farval, |
|
|
float |
upDirection = -1.0f |
|
) |
| |
|
static |
- Parameters
-
upDirection | Use -1.0 for 2D Y increasing downwards (the G3D 8.x default convention), 1.0 for 2D Y increasing upwards (the G3D 7.x default and OpenGL convention) |
static Matrix4 orthogonalProjection(float left, float right, float bottom, float top, float nearval, float farval, float upDirection=-1.0f)
Definition: Matrix4.cpp:156
Matrix4 G3D::Matrix4::perspectiveProjection |
( |
double |
left, |
|
|
double |
right, |
|
|
double |
bottom, |
|
|
double |
top, |
|
|
double |
nearval, |
|
|
double |
farval, |
|
|
float |
upDirection = -1.0f |
|
) |
| |
|
static |
- Parameters
-
upDirection | Use -1.0 for 2D Y increasing downwards (the G3D 8.x default convention), 1.0 for 2D Y increasing upwards (the G3D 7.x default and OpenGL convention) Uses double precision because the operations involved in
projection involve divisions that can significantly impact
precision. |
198 double x,
y, a, b, c, d;
200 x = (2.0*nearval) / (right-
left);
201 y = (2.0*nearval) / (top-bottom);
203 b = (top+bottom) / (top-bottom);
205 if (farval >=
inf()) {
210 c = -(farval+nearval) / (farval-nearval);
211 d = -(2.0*farval*nearval) / (farval-nearval);
219 (
float)x, 0, (
float)a, 0,
220 0, (
float)y, (
float)b, 0,
221 0, 0, (
float)c, (
float)d,
double abs(double fValue)
Definition: g3dmath.h:617
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
double inf()
Definition: g3dmath.cpp:40
G3D::int16 y
Definition: Vector2int16.h:38
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
Matrix4()
Definition: Matrix4.cpp:305
G3D::int16 x
Definition: Vector2int16.h:37
static Matrix4 G3D::Matrix4::pitchDegrees |
( |
float |
deg | ) |
|
|
inlinestatic |
static Matrix3 fromAxisAngle(const Vector3 &rkAxis, float fRadians)
Definition: Matrix3.cpp:1346
static const Vector3 & unitX()
Definition: Vector3.cpp:121
double toRadians(double deg)
Definition: g3dmath.h:798
Matrix4()
Definition: Matrix4.cpp:305
static Matrix4 G3D::Matrix4::rollDegrees |
( |
float |
deg | ) |
|
|
inlinestatic |
static Matrix3 fromAxisAngle(const Vector3 &rkAxis, float fRadians)
Definition: Matrix3.cpp:1346
double toRadians(double deg)
Definition: g3dmath.h:798
static const Vector3 & unitZ()
Definition: Vector3.cpp:123
Matrix4()
Definition: Matrix4.cpp:305
329 return reinterpret_cast<const Vector4*
>(
elt[r])[0];
float elt[4][4]
Definition: Matrix4.h:39
3D scale matrix
Matrix4()
Definition: Matrix4.cpp:305
static Matrix4 G3D::Matrix4::scale |
( |
float |
x, |
|
|
float |
y, |
|
|
float |
z |
|
) |
| |
|
inlinestatic |
3D scale matrix
static Matrix4 scale(const Vector3 &v)
Definition: Matrix4.h:239
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
static Matrix4 G3D::Matrix4::scale |
( |
float |
s | ) |
|
|
inlinestatic |
3D scale matrix
static Matrix4 scale(const Vector3 &v)
Definition: Matrix4.h:239
void G3D::Matrix4::serialize |
( |
class BinaryOutput & |
b | ) |
const |
Serializes row-major
525 for (
int r = 0; r < 4; ++r) {
526 for (
int c = 0; c < 4; ++c) {
527 b.writeFloat32(
elt[r][c]);
float elt[4][4]
Definition: Matrix4.h:39
322 for (
int r = 0; r < 4; ++r) {
float elt[4][4]
Definition: Matrix4.h:39
void G3D::Matrix4::setRow |
( |
int |
r, |
|
|
const class Vector4 & |
v |
|
) |
| |
315 for (
int c = 0; c < 4; ++c) {
float elt[4][4]
Definition: Matrix4.h:39
float G3D::Matrix4::subDeterminant |
( |
int |
excludeRow, |
|
|
int |
excludeCol |
|
) |
| const |
|
private |
Computes the determinant of the 3x3 matrix that lacks excludeRow and excludeCol.
474 for (
int i = 0; i < 3; ++i) {
478 if (i >= excludeRow) {
481 if (i >= excludeCol) {
488 elt[row[1]][col[1]] *
elt[row[2]][col[2]] -
489 elt[row[1]][col[2]] *
elt[row[2]][col[1]];
492 elt[row[1]][col[2]] *
elt[row[2]][col[0]] -
493 elt[row[1]][col[0]] *
elt[row[2]][col[2]];
496 elt[row[1]][col[0]] *
elt[row[2]][col[1]] -
497 elt[row[1]][col[1]] *
elt[row[2]][col[0]];
501 elt[row[0]][col[0]] * cofactor00 +
502 elt[row[0]][col[1]] * cofactor10 +
503 elt[row[0]][col[2]] * cofactor20;
const Vector4 & row(int r) const
Definition: Matrix4.cpp:328
float elt[4][4]
Definition: Matrix4.h:39
Any G3D::Matrix4::toAny |
( |
| ) |
const |
78 for (
int r = 0; r < 4; ++r) {
79 for (
int c = 0; c < 4; ++c) {
80 any[r * 4 + c] =
elt[r][c];
bool any(float x)
Definition: g3dmath.h:424
float elt[4][4]
Definition: Matrix4.h:39
std::string G3D::Matrix4::toString |
( |
| ) |
const |
542 return G3D::format(
"[%g, %g, %g, %g; %g, %g, %g, %g; %g, %g, %g, %g; %g, %g, %g, %g]",
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
float elt[4][4]
Definition: Matrix4.h:39
3D translation matrix
Matrix4()
Definition: Matrix4.cpp:305
static const Matrix3 & identity()
Definition: Matrix3.cpp:70
static Matrix4 G3D::Matrix4::translation |
( |
float |
x, |
|
|
float |
y, |
|
|
float |
z |
|
) |
| |
|
inlinestatic |
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
Matrix4()
Definition: Matrix4.cpp:305
G3D::int16 x
Definition: Vector2int16.h:37
static const Matrix3 & identity()
Definition: Matrix3.cpp:70
Matrix4 G3D::Matrix4::transpose |
( |
| ) |
const |
388 for (
int r = 0; r < 4; ++r) {
389 for (
int c = 0; c < 4; ++c) {
390 result.elt[c][r] =
elt[r][c];
Matrix4()
Definition: Matrix4.cpp:305
float elt[4][4]
Definition: Matrix4.h:39
Matrix2 G3D::Matrix4::upper2x2 |
( |
| ) |
const |
142 return Matrix2(
elt[0][0],
elt[0][1],
float elt[4][4]
Definition: Matrix4.h:39
Matrix3 G3D::Matrix4::upper3x3 |
( |
| ) |
const |
135 return Matrix3(
elt[0][0],
elt[0][1],
elt[0][2],
float elt[4][4]
Definition: Matrix4.h:39
static Matrix4 G3D::Matrix4::yawDegrees |
( |
float |
deg | ) |
|
|
inlinestatic |
Create a rotation matrix that rotates deg degrees around the Y axis
static Matrix3 fromAxisAngle(const Vector3 &rkAxis, float fRadians)
Definition: Matrix3.cpp:1346
double toRadians(double deg)
Definition: g3dmath.h:798
static const Vector3 & unitY()
Definition: Vector3.cpp:122
Matrix4()
Definition: Matrix4.cpp:305
Matrix4()
Definition: Matrix4.cpp:305
float G3D::Matrix4::elt[4][4] |
|
private |
The documentation for this class was generated from the following files: