Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TMatrix3.ipp
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TMatrix3.h"
4#include "Math/TVector3.h"
5
6#include <Common/assertion.h>
7
8namespace ph::math
9{
10
11template<typename T>
12template<typename U>
14{
15 for(std::size_t ri = 0; ri < 3; ++ri)
16 {
17 for(std::size_t ci = 0; ci < 3; ++ci)
18 {
19 m[ri][ci] = static_cast<T>(other[ri][ci]);
20 }
21 }
22}
23
24template<typename T>
26 const T m00, const T m01, const T m02,
27 const T m10, const T m11, const T m12,
28 const T m20, const T m21, const T m22)
29{
30 m[0][0] = m00; m[0][1] = m01; m[0][2] = m02;
31 m[1][0] = m10; m[1][1] = m11; m[1][2] = m12;
32 m[2][0] = m20; m[2][1] = m21; m[2][2] = m22;
33}
34
35template<typename T>
37{
38 TMatrix3 result;
39
40 result.m[0][0] = (m[2][2] * m[1][1] - m[2][1] * m[1][2]);
41 result.m[0][1] = -(m[2][2] * m[0][1] - m[2][1] * m[0][2]);
42 result.m[0][2] = (m[1][2] * m[0][1] - m[1][1] * m[0][2]);
43
44 result.m[1][0] = -(m[2][2] * m[1][0] - m[2][0] * m[1][2]);
45 result.m[1][1] = (m[2][2] * m[0][0] - m[2][0] * m[0][2]);
46 result.m[1][2] = -(m[1][2] * m[0][0] - m[1][0] * m[0][2]);
47
48 result.m[2][0] = (m[2][1] * m[1][0] - m[2][0] * m[1][1]);
49 result.m[2][1] = -(m[2][1] * m[0][0] - m[2][0] * m[0][1]);
50 result.m[2][2] = (m[1][1] * m[0][0] - m[1][0] * m[0][1]);
51
52 const T det = determinant();
53 PH_ASSERT_NE(det, 0);
54 result.mulLocal(static_cast<T>(1) / det);
55
56 return result;
57}
58
59template<typename T>
61{
62 return m[0][0] * ((m[1][1] * m[2][2]) - (m[2][1] * m[1][2])) -
63 m[0][1] * (m[1][0] * m[2][2] - m[2][0] * m[1][2]) +
64 m[0][2] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]);
65}
66
67template<typename T>
68inline TVector3<T> TMatrix3<T>::mul(const TVector3<T>& rhsColVector) const
69{
70 return TVector3<T>(this->multiplyVector(rhsColVector.toArray()));
71}
72
73template<typename T>
74inline TVector3<T> TMatrix3<T>::operator * (const TVector3<T>& rhsColVector) const
75{
76 return this->mul(rhsColVector);
77}
78
79}// end namespace ph::math
Represents a 3x3 matrix.
Definition TMatrix3.h:16
TVector3< T > operator*(const TVector3< T > &rhsColVector) const
Definition TMatrix3.ipp:74
T determinant() const
Definition TMatrix3.ipp:60
TVector3< T > mul(const TVector3< T > &rhsColVector) const
Definition TMatrix3.ipp:68
TMatrix3 inverse() const
Definition TMatrix3.ipp:36
TRawMatrix< T, M, N > m
Definition TMatrixMxNBase.h:77
Derived & mulLocal(const Derived &rhsMatrix)
Definition TMatrixNBase.ipp:50
Represents a 3-D vector.
Definition TVector3.h:17
std::array< T, N > toArray() const
Definition TArithmeticArrayBase.ipp:855
Math functions and utilities.
Definition TransformInfo.h:10