IceMatrix4x4.cpp
Go to the documentation of this file.
1 
8 
11 
35 
38 // Precompiled Header
39 #include "Stdafx.h"
40 
41 using namespace IceMaths;
42 
44 
55 {
56  dest.m[0][0] = src.m[0][0];
57  dest.m[1][0] = src.m[0][1];
58  dest.m[2][0] = src.m[0][2];
59  dest.m[3][0] = -(src.m[3][0]*src.m[0][0] + src.m[3][1]*src.m[0][1] + src.m[3][2]*src.m[0][2]);
60 
61  dest.m[0][1] = src.m[1][0];
62  dest.m[1][1] = src.m[1][1];
63  dest.m[2][1] = src.m[1][2];
64  dest.m[3][1] = -(src.m[3][0]*src.m[1][0] + src.m[3][1]*src.m[1][1] + src.m[3][2]*src.m[1][2]);
65 
66  dest.m[0][2] = src.m[2][0];
67  dest.m[1][2] = src.m[2][1];
68  dest.m[2][2] = src.m[2][2];
69  dest.m[3][2] = -(src.m[3][0]*src.m[2][0] + src.m[3][1]*src.m[2][1] + src.m[3][2]*src.m[2][2]);
70 
71  dest.m[0][3] = 0.0f;
72  dest.m[1][3] = 0.0f;
73  dest.m[2][3] = 0.0f;
74  dest.m[3][3] = 1.0f;
75 }
76 
78 // Compute the cofactor of the Matrix at a specified location
81 {
82  return (( m[(row+1)&3][(col+1)&3]*m[(row+2)&3][(col+2)&3]*m[(row+3)&3][(col+3)&3] +
83  m[(row+1)&3][(col+2)&3]*m[(row+2)&3][(col+3)&3]*m[(row+3)&3][(col+1)&3] +
84  m[(row+1)&3][(col+3)&3]*m[(row+2)&3][(col+1)&3]*m[(row+3)&3][(col+2)&3])
85  - (m[(row+3)&3][(col+1)&3]*m[(row+2)&3][(col+2)&3]*m[(row+1)&3][(col+3)&3] +
86  m[(row+3)&3][(col+2)&3]*m[(row+2)&3][(col+3)&3]*m[(row+1)&3][(col+1)&3] +
87  m[(row+3)&3][(col+3)&3]*m[(row+2)&3][(col+1)&3]*m[(row+1)&3][(col+2)&3])) * ((row + col) & 1 ? -1.0f : +1.0f);
88 }
89 
91 // Compute the determinant of the Matrix
94 {
95  return m[0][0] * CoFactor(0, 0) +
96  m[0][1] * CoFactor(0, 1) +
97  m[0][2] * CoFactor(0, 2) +
98  m[0][3] * CoFactor(0, 3);
99 }
100 
102 // Compute the inverse of the matrix
105 {
106  float Det = Determinant();
107  Matrix4x4 Temp;
108 
109  if(fabsf(Det) < MATRIX4X4_EPSILON)
110  return *this; // The matrix is not invertible! Singular case!
111 
112  float IDet = 1.0f / Det;
113 
114  Temp.m[0][0] = CoFactor(0,0) * IDet;
115  Temp.m[1][0] = CoFactor(0,1) * IDet;
116  Temp.m[2][0] = CoFactor(0,2) * IDet;
117  Temp.m[3][0] = CoFactor(0,3) * IDet;
118  Temp.m[0][1] = CoFactor(1,0) * IDet;
119  Temp.m[1][1] = CoFactor(1,1) * IDet;
120  Temp.m[2][1] = CoFactor(1,2) * IDet;
121  Temp.m[3][1] = CoFactor(1,3) * IDet;
122  Temp.m[0][2] = CoFactor(2,0) * IDet;
123  Temp.m[1][2] = CoFactor(2,1) * IDet;
124  Temp.m[2][2] = CoFactor(2,2) * IDet;
125  Temp.m[3][2] = CoFactor(2,3) * IDet;
126  Temp.m[0][3] = CoFactor(3,0) * IDet;
127  Temp.m[1][3] = CoFactor(3,1) * IDet;
128  Temp.m[2][3] = CoFactor(3,2) * IDet;
129  Temp.m[3][3] = CoFactor(3,3) * IDet;
130 
131  *this = Temp;
132 
133  return *this;
134 }
135 
Matrix4x4 & Invert()
Inverts the matrix. Determinant must be different from zero, else matrix can&#39;t be inverted...
#define ICEMATHS_API
Definition: OPC_IceHook.h:51
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
#define MATRIX4X4_EPSILON
Definition: OPC_IceHook.h:20
png_bytepp row
Definition: png.h:1759
ICEMATHS_API void InvertPRMatrix(Matrix4x4 &dest, const Matrix4x4 &src)
float CoFactor(udword row, udword col) const
Computes a cofactor. Used for matrix inversion.
float Determinant() const
Computes the determinant of the matrix.


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:38