Wildvine Engine
Referencia Doxygen del codigo propio de Wildvine Engine.
Cargando...
Buscando...
Nada coincide
Matrix2x2.h
Ir a la documentación de este archivo.
1
6/*
7 * MIT License
8 *
9 * Copyright (c) 2024 Roberto Charreton
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in all
19 * copies or substantial portions of the Software.
20 *
21 * In addition, any project or software that uses this library or class must include
22 * the following acknowledgment in the credits:
23 *
24 * "This project uses software developed by Roberto Charreton and Attribute Overload."
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33*/
34#pragma once
35namespace EU {
42 class Matrix2x2 {
43 public:
44 float m[2][2];
52 m[0][0] = 1; m[0][1] = 0;
53 m[1][0] = 0; m[1][1] = 1;
54 }
55
66 Matrix2x2(float a11, float a12, float a21, float a22) {
67 m[0][0] = a11; m[0][1] = a12;
68 m[1][0] = a21; m[1][1] = a22;
69 }
70
77 Matrix2x2 operator+(const Matrix2x2& other) const {
78 return Matrix2x2(
79 m[0][0] + other.m[0][0], m[0][1] + other.m[0][1],
80 m[1][0] + other.m[1][0], m[1][1] + other.m[1][1]
81 );
82 }
83
90 Matrix2x2 operator-(const Matrix2x2& other) const {
91 return Matrix2x2(
92 m[0][0] - other.m[0][0], m[0][1] - other.m[0][1],
93 m[1][0] - other.m[1][0], m[1][1] - other.m[1][1]
94 );
95 }
96
103 Matrix2x2 operator*(const Matrix2x2& other) const {
104 return Matrix2x2(
105 m[0][0] * other.m[0][0] + m[0][1] * other.m[1][0], m[0][0] * other.m[0][1] + m[0][1] * other.m[1][1],
106 m[1][0] * other.m[0][0] + m[1][1] * other.m[1][0], m[1][0] * other.m[0][1] + m[1][1] * other.m[1][1]
107 );
108 }
109
116 Matrix2x2 operator*(float scalar) const {
117 return Matrix2x2(
118 m[0][0] * scalar, m[0][1] * scalar,
119 m[1][0] * scalar, m[1][1] * scalar
120 );
121 }
122
128 float determinant() const {
129 return m[0][0] * m[1][1] - m[0][1] * m[1][0];
130 }
131
138 float det = determinant();
139 if (det == 0) {
140 // Handle non-invertible matrix gracefully.
141 return Matrix2x2();
142 }
143 float invDet = 1.0f / det;
144 return Matrix2x2(
145 m[1][1] * invDet, -m[0][1] * invDet,
146 -m[1][0] * invDet, m[0][0] * invDet
147 );
148 }
149 };
150}
151
152
A 2x2 matrix class.
Definition Matrix2x2.h:42
float determinant() const
Calculates the determinant of the matrix.
Definition Matrix2x2.h:128
Matrix2x2 operator*(const Matrix2x2 &other) const
Multiplies this matrix by another matrix.
Definition Matrix2x2.h:103
Matrix2x2 inverse() const
Calculates the inverse of the matrix.
Definition Matrix2x2.h:137
Matrix2x2 operator+(const Matrix2x2 &other) const
Adds another matrix to this matrix.
Definition Matrix2x2.h:77
Matrix2x2()
Default constructor.
Definition Matrix2x2.h:51
Matrix2x2 operator-(const Matrix2x2 &other) const
Subtracts another matrix from this matrix.
Definition Matrix2x2.h:90
Matrix2x2 operator*(float scalar) const
Multiplies this matrix by a scalar.
Definition Matrix2x2.h:116
float m[2][2]
The elements of the matrix.
Definition Matrix2x2.h:44
Matrix2x2(float a11, float a12, float a21, float a22)
Parameterized constructor.
Definition Matrix2x2.h:66
Definition Matrix2x2.h:35