Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfMatrix4.h
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20#ifndef _SOURCE_TYPES_TFMATRIX4_H_
21#define _SOURCE_TYPES_TFMATRIX4_H_
22
23#include "tfMatrix3.h"
24#include "tfVector4.h"
25
26#include <Magnum/Math/Matrix4.h>
27
28
29namespace TissueForge::types {
30
31
32 template<class T> using Matrix4Base = Magnum::Math::Matrix4<T>;
33
34 template<class T>
35 class TMatrix4 : public Matrix4Base<T> {
36 public:
38 constexpr static TMatrix4<T> translation(const TVector3<T>& vector) {
39 return Matrix4Base<T>::translation(vector);
40 }
41
43 constexpr static TMatrix4<T> scaling(const TVector3<T>& vector) {
44 return Matrix4Base<T>::scaling(vector);
45 }
46
48 static TMatrix4<T> rotation(T angle, const TVector3<T>& normalizedAxis) {
49 return Matrix4Base<T>::rotation(Magnum::Math::Rad<T>(angle), normalizedAxis);
50 }
51
53 static TMatrix4<T> rotationX(T angle) {
54 return Matrix4Base<T>::rotationX(Magnum::Math::Rad<T>(angle));
55 }
56
58 static TMatrix4<T> rotationY(T angle) {
59 return Matrix4Base<T>::rotationY(Magnum::Math::Rad<T>(angle));
60 }
61
63 static TMatrix4<T> rotationZ(T angle) {
64 return Matrix4Base<T>::rotationZ(Magnum::Math::Rad<T>(angle));
65 }
66
68 static TMatrix4<T> reflection(const TVector3<T>& normal) {
69 return Matrix4Base<T>::reflection(normal);
70 }
71
73 constexpr static TMatrix4<T> shearingXY(T amountX, T amountY) {
74 return Matrix4Base<T>::shearingXY(amountX, amountY);
75 }
76
78 constexpr static TMatrix4<T> shearingXZ(T amountX, T amountZ) {
79 return Matrix4Base<T>::shearingXZ(amountX, amountZ);
80 }
81
83 constexpr static TMatrix4<T> shearingYZ(T amountY, T amountZ) {
84 return Matrix4Base<T>::shearingYZ(amountY, amountZ);
85 }
86
94 static TMatrix4<T> orthographicProjection(const TVector2<T>& size, T near, T far) {
95 return Matrix4Base<T>::orthographicProjection(size, near, far);
96 }
97
105 static TMatrix4<T> perspectiveProjection(const TVector2<T>& size, T near, T far) {
106 return Matrix4Base<T>::perspectiveProjection(size, near, far);
107 }
108
117 static TMatrix4<T> perspectiveProjection(T fov, T aspectRatio, T near, T far) {
118 return Matrix4Base<T>::perspectiveProjection(Magnum::Math::Rad<T>(fov), aspectRatio, near, far);
119 }
120
129 static TMatrix4<T> perspectiveProjection(const TVector2<T>& bottomLeft, const TVector2<T>& topRight, T near, T far) {
130 return Matrix4Base<T>::perspectiveProjection(bottomLeft, topRight, near, far);
131 }
132
140 static TMatrix4<T> lookAt(const TVector3<T>& eye, const TVector3<T>& target, const TVector3<T>& up) {
141 return Matrix4Base<T>::lookAt(eye, target, up);
142 }
143
146 return Matrix4Base<T>::from((const Magnum::Math::Matrix3<T>&)rotationScaling, translation);
147 }
148
149 constexpr TMatrix4() noexcept: Matrix4Base<T>() {}
150 constexpr TMatrix4(const TVector4<T>& first, const TVector4<T>& second, const TVector4<T>& third, const TVector4<T>& fourth) noexcept:
151 Matrix4Base<T>(first, second, third, fourth) {}
152 constexpr explicit TMatrix4(T value) noexcept: Matrix4Base<T>{value} {}
153 template<std::size_t otherSize> constexpr explicit TMatrix4(const TMatrixS<otherSize, T>& other) noexcept: Matrix4Base<T>{other} {}
154 constexpr TMatrix4(const TMatrix4<T>& other) noexcept: Matrix4Base<T>(other) {}
155
157 bool isRigidTransformation() const { return Matrix4Base<T>::isRigidTransformation(); }
158
160 constexpr TMatrix3<T> rotationScaling() const { return Matrix4Base<T>::rotationScaling(); }
161
163 TMatrix3<T> rotationShear() const { return Matrix4Base<T>::rotationShear(); }
164
166 TMatrix3<T> rotation() const { return Matrix4Base<T>::rotation(); }
167
169 TMatrix3<T> rotationNormalized() const { return Matrix4Base<T>::rotationNormalized(); }
170
172 TVector3<T> scalingSquared() const { return Matrix4Base<T>::scalingSquared(); }
173
175 TVector3<T> scaling() const { return Matrix4Base<T>::scaling(); }
176
178 T uniformScalingSquared() const { return Matrix4Base<T>::uniformScalingSquared(); }
179
181 T uniformScaling() const { return Matrix4Base<T>::uniformScaling(); }
182
184 TMatrix3<T> normalMatrix() const { return Matrix4Base<T>::normalMatrix(); }
185
187 TVector3<T>& right() { return (TVector3<T>&)Matrix4Base<T>::right(); }
188
190 constexpr TVector3<T> right() const { return Matrix4Base<T>::right(); }
191
193 TVector3<T>& up() { return (TVector3<T>&)Matrix4Base<T>::up(); }
194
196 constexpr TVector3<T> up() const { return Matrix4Base<T>::up(); }
197
199 TVector3<T>& backward() { return (TVector3<T>&)Matrix4Base<T>::backward(); }
200
202 constexpr TVector3<T> backward() const { return Matrix4Base<T>::backward(); }
203
205 TVector3<T>& translation() { return (TVector3<T>&)Matrix4Base<T>::translation(); }
206
208 constexpr TVector3<T> translation() const { return Matrix4Base<T>::translation(); }
209
211 TMatrix4<T> invertedRigid() const { return Matrix4Base<T>::invertedRigid(); }
212
214 TVector3<T> transformVector(const TVector3<T>& vector) const { return Matrix4Base<T>::transformVector(vector); }
215
217 TVector3<T> transformPoint(const TVector3<T>& vector) const { return Matrix4Base<T>::transformPoint(vector); }
218
219 MAGNUM_BASE_MATRIX_CAST_METHODS(4, TMatrix4, Matrix4Base)
220
221 REVISED_MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(4, TMatrix4, Matrix4Base, TVector4)
222
223 #ifdef SWIGPYTHON
224 SWIGPYTHON_MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(4, TMatrix4, TVector4)
225 #endif
226
227 };
228
229}
230
231TF_MATRIX_IMPL_OSTREAM(TissueForge::types::TMatrix4)
232
233#endif // _SOURCE_TYPES_TFMATRIX4_H_
Definition tfMatrix3.h:35
Definition tfMatrix4.h:35
static constexpr TMatrix4< T > from(const TMatrix3< T > &rotationScaling, const TVector3< T > &translation)
Definition tfMatrix4.h:145
static TMatrix4< T > rotationZ(T angle)
Definition tfMatrix4.h:63
static constexpr TMatrix4< T > shearingYZ(T amountY, T amountZ)
Definition tfMatrix4.h:83
TMatrix3< T > rotation() const
Definition tfMatrix4.h:166
T uniformScaling() const
Definition tfMatrix4.h:181
TVector3< T > scalingSquared() const
Definition tfMatrix4.h:172
TVector3< T > & backward()
Definition tfMatrix4.h:199
static constexpr TMatrix4< T > translation(const TVector3< T > &vector)
Definition tfMatrix4.h:38
TVector3< T > & right()
Definition tfMatrix4.h:187
TVector3< T > transformVector(const TVector3< T > &vector) const
Definition tfMatrix4.h:214
constexpr TVector3< T > up() const
Definition tfMatrix4.h:196
T uniformScalingSquared() const
Definition tfMatrix4.h:178
TMatrix3< T > normalMatrix() const
Definition tfMatrix4.h:184
static TMatrix4< T > perspectiveProjection(const TVector2< T > &bottomLeft, const TVector2< T > &topRight, T near, T far)
Initialize a perspective projection matrix.
Definition tfMatrix4.h:129
TVector3< T > & translation()
Definition tfMatrix4.h:205
TMatrix3< T > rotationNormalized() const
Definition tfMatrix4.h:169
static TMatrix4< T > rotation(T angle, const TVector3< T > &normalizedAxis)
Definition tfMatrix4.h:48
TMatrix3< T > rotationShear() const
Definition tfMatrix4.h:163
static constexpr TMatrix4< T > shearingXY(T amountX, T amountY)
Definition tfMatrix4.h:73
static TMatrix4< T > reflection(const TVector3< T > &normal)
Definition tfMatrix4.h:68
constexpr TVector3< T > backward() const
Definition tfMatrix4.h:202
static constexpr TMatrix4< T > shearingXZ(T amountX, T amountZ)
Definition tfMatrix4.h:78
TMatrix4< T > invertedRigid() const
Definition tfMatrix4.h:211
static TMatrix4< T > perspectiveProjection(T fov, T aspectRatio, T near, T far)
Initialize a perspective projection matrix.
Definition tfMatrix4.h:117
static TMatrix4< T > perspectiveProjection(const TVector2< T > &size, T near, T far)
Initialize an perspective projection matrix.
Definition tfMatrix4.h:105
static TMatrix4< T > rotationY(T angle)
Definition tfMatrix4.h:58
TVector3< T > transformPoint(const TVector3< T > &vector) const
Definition tfMatrix4.h:217
constexpr TMatrix3< T > rotationScaling() const
Definition tfMatrix4.h:160
static TMatrix4< T > rotationX(T angle)
Definition tfMatrix4.h:53
TVector3< T > scaling() const
Definition tfMatrix4.h:175
constexpr TVector3< T > translation() const
Definition tfMatrix4.h:208
static constexpr TMatrix4< T > scaling(const TVector3< T > &vector)
Definition tfMatrix4.h:43
bool isRigidTransformation() const
Definition tfMatrix4.h:157
static TMatrix4< T > lookAt(const TVector3< T > &eye, const TVector3< T > &target, const TVector3< T > &up)
Initialize a matrix oriented towards a point.
Definition tfMatrix4.h:140
constexpr TVector3< T > right() const
Definition tfMatrix4.h:190
static TMatrix4< T > orthographicProjection(const TVector2< T > &size, T near, T far)
Initialize an orthographic projection matrix.
Definition tfMatrix4.h:94
TVector3< T > & up()
Definition tfMatrix4.h:193
Definition tfVector2.h:35
Definition tfVector3.h:35
Definition tfVector4.h:33
Native Tissue Forge type definitions.
Definition tfMatrix.h:33