Brunot
Loading...
Searching...
No Matches
AffineMatrix.h
Go to the documentation of this file.
1// File: AffineMatrix.h
2// Description: Wrapper class for 2D matrices. Contains basic manipulation necessary for transformations
3// Author(s): Ori Balashov (ori.balashov@digipen.edu) Base Implementation
4// Aidan Hartman (aidan.hartman@digipen.edu) Added additional functionality
5// 2025 / 09 / 17
6// (C) Digipen 2025
7// ____ __ __ __
8// /\__ _\/\ \ /\ \/\ \
9// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
10// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
11// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
12// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
13// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
14#pragma once
15
16#include "Vector4D.h"
17#include "Eigen/Dense"
18
30{
31
32 AffineMatrix() = default;
33 AffineMatrix(const AffineMatrix&) = default;
34 AffineMatrix(const Eigen::Matrix4f&);
35 auto operator=(const AffineMatrix&) -> AffineMatrix& = default;
36 ~AffineMatrix() = default;
37
38 // Sets up the top left square
39 AffineMatrix(float x1, float x2, float y1, float y2);
40 // Sets up the whole thing
41 AffineMatrix(float x1, float x2, float x3, float x4, float y1, float y2, float y3, float y4, float z1, float z2,
42 float z3, float z4, float w1, float w2, float w3, float w4);
43
44 auto operator*=(const AffineMatrix& Other) -> AffineMatrix&;
45 auto operator*(const AffineMatrix& Other) const -> AffineMatrix;
46
53 friend auto operator*(float scalar, const AffineMatrix& matrix) -> AffineMatrix;
54
61 friend auto operator*(const AffineMatrix& matrix, float scalar) -> AffineMatrix;
62
69 friend auto operator*=(AffineMatrix& matrix, float scalar) -> AffineMatrix&;
70
71
78 friend auto operator*(const AffineMatrix& rhs, const Vector4D& lhs) -> Vector4D;
85 friend auto operator*=(Vector4D& rhs, const AffineMatrix& lhs) -> Vector4D&;
86
87
88 // Makes matrices correspond to the related transformations
89 auto identity() -> AffineMatrix&;
90 auto transpose() -> AffineMatrix&;
91
92 auto scale(float s) -> AffineMatrix&;
93 auto scale(float x, float y) -> AffineMatrix&;
94 auto scale(const Vector4D& vector) -> AffineMatrix&;
95
96
97 auto rotate(float angle) -> AffineMatrix&;
98 auto translate(float x, float y) -> AffineMatrix&;
99 auto translate(const Vector4D& vector) -> AffineMatrix&;
100
101 // Operators for RHS and LHS
102 //You can access elements inside of the matrix through calling "[matrix name](x,y)"
103 /*
104 * AffineMatrix myMatrix = new Matrix(1, 0, 0, 1);
105 * myMatrix(0,1) = 3;
106 * int newInt = myMatrix(1,1);
107 */
108 auto operator()(int row, int col) -> float&;
109 auto operator()(int row, int col) const -> float;
110
111 auto get(int row, int col) -> float&;
112 auto get(int row, int col) const -> float;
113
114 auto data() const -> const float*;
115 auto data() -> float*;
116
117private:
118 // 3 Dimensions to support affine
119 Eigen::Matrix4f matrix;
120};
auto transpose() -> AffineMatrix &
Transposes the current matrix.
Definition AffineMatrix.cpp:112
auto rotate(float angle) -> AffineMatrix &
Definition AffineMatrix.cpp:144
AffineMatrix()=default
auto operator()(int row, int col) -> float &
Definition AffineMatrix.cpp:179
auto get(int row, int col) -> float &
Definition AffineMatrix.cpp:189
auto operator*(const AffineMatrix &Other) const -> AffineMatrix
NOTE: THIS MULTIPLIES MATRICES AS THEY ARE WRITTEN (UNLIKE *=) e.g.
Definition AffineMatrix.cpp:90
auto scale(float s) -> AffineMatrix &
Definition AffineMatrix.cpp:118
auto identity() -> AffineMatrix &
Converts the current matrix into the identity matrix.
Definition AffineMatrix.cpp:102
~AffineMatrix()=default
Eigen::Matrix4f matrix
Definition AffineMatrix.h:119
auto translate(float x, float y) -> AffineMatrix &
Definition AffineMatrix.cpp:160
auto operator*=(const AffineMatrix &Other) -> AffineMatrix &
NOTE: THIS FLIPS MULTIPLICATION ORDER SO THE MATRICES PROPERLY MULTIPLY e.g.
Definition AffineMatrix.cpp:76
auto operator=(const AffineMatrix &) -> AffineMatrix &=default
AffineMatrix(const AffineMatrix &)=default
auto data() const -> const float *
Definition AffineMatrix.cpp:199
Definition Vector4D.h:23