13using namespace Triton;
17#ifndef TRITON_MATRIX4_H
18#define TRITON_MATRIX4_H
55 Matrix4(
double e11,
double e12,
double e13,
double e14,
56 double e21,
double e22,
double e23,
double e24,
57 double e31,
double e32,
double e33,
double e34,
58 double e41,
double e42,
double e43,
double e44) {
79 for (
int row = 0; row < 4; row++) {
80 for (
int col = 0; col < 4; col++) {
81 elem[row][col] = *m++;
98 for (
int row = 0; row < 4; row++) {
99 for (
int col = 0; col < 4; col++) {
100 val[i++] = (float)
elem[row][col];
120 for (
int row = 0; row < 4; row++) {
121 for (
int col = 0; col < 4; col++) {
144 double det = a0*b5 - a1*b4 + a2*b3 + a3*b2 - a4*b1 + a5*b0;
145 if (fabs(det) > epsilon) {
163 double invDet = ((double)1)/det;
164 inverse.
elem[0][0] *= invDet;
165 inverse.
elem[0][1] *= invDet;
166 inverse.
elem[0][2] *= invDet;
167 inverse.
elem[0][3] *= invDet;
168 inverse.
elem[1][0] *= invDet;
169 inverse.
elem[1][1] *= invDet;
170 inverse.
elem[1][2] *= invDet;
171 inverse.
elem[1][3] *= invDet;
172 inverse.
elem[2][0] *= invDet;
173 inverse.
elem[2][1] *= invDet;
174 inverse.
elem[2][2] *= invDet;
175 inverse.
elem[2][3] *= invDet;
176 inverse.
elem[3][0] *= invDet;
177 inverse.
elem[3][1] *= invDet;
178 inverse.
elem[3][2] *= invDet;
179 inverse.
elem[3][3] *= invDet;
187 double * TRITONAPI
GetRow(
int row)
const {
189 static double sRow[4];
190 sRow[0] =
elem[row][0];
191 sRow[1] =
elem[row][1];
192 sRow[2] =
elem[row][2];
193 sRow[3] =
elem[row][3];
An implementation of a 4x4 matrix and some simple operations on it.
Memory allocation interface for SilverLining.
A simple 4D vector class.
An implementation of a 4x4 matrix and some simple operations on it.
Definition: Matrix4.h:30
Matrix4 TRITONAPI InverseCramers(double epsilon=1E-12) const
Computes the inverse of the matrix using Cramer's rule.
Definition: Matrix4.h:128
double *TRITONAPI GetRow(int row) const
Retrieves a pointer into the requested row of the matrix.
Definition: Matrix4.h:187
Matrix4(const double *m)
Initializes the matrix from an array of 16 double-precision values (row-major).
Definition: Matrix4.h:78
friend Vector4 TRITONAPI operator*(const Vector4 &vec, const Matrix4 &mat)
Multiplies a 1x3 vector by a matrix, yielding a 1x3 vector.
Matrix4(double e11, double e12, double e13, double e14, double e21, double e22, double e23, double e24, double e31, double e32, double e33, double e34, double e41, double e42, double e43, double e44)
This constructor allows you to initialize the matrix as you please.
Definition: Matrix4.h:55
~Matrix4()
Destructor.
Definition: Matrix4.h:87
void TRITONAPI ToFloatArray(float val[16]) const
Populates a static array of 16 floats with the contents of the matrix.
Definition: Matrix4.h:96
double elem[4][4]
Data members are public for convenience.
Definition: Matrix4.h:201
void TRITONAPI Transpose()
Transposes the matrix in-place.
Definition: Matrix4.h:118
double TRITONAPI operator()(int x, int y) const
Retrieve a specific matrix element.
Definition: Matrix4.h:91
Matrix4()
Default constructor; initializes the matrix to an identity transform.
Definition: Matrix4.h:35
This base class for all Triton objects intercepts the new and delete operators, routing them through ...
Definition: MemAlloc.h:71
A 3D double-precision Vector class and its operations.
Definition: Vector3.h:36
A simple double-precision 4D vector class with no operations defined.
Definition: Vector4.h:31