gsvector.cpp (1482B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #include "gsvector.h" 5 6 #include <cmath> 7 8 GSMatrix2x2::GSMatrix2x2(float e00, float e01, float e10, float e11) 9 { 10 E[0][0] = e00; 11 E[0][1] = e01; 12 E[1][0] = e10; 13 E[1][1] = e11; 14 } 15 16 GSMatrix2x2 GSMatrix2x2::operator*(const GSMatrix2x2& m) const 17 { 18 GSMatrix2x2 ret; 19 ret.E[0][0] = E[0][0] * m.E[0][0] + E[0][1] * m.E[1][0]; 20 ret.E[0][1] = E[0][0] * m.E[0][1] + E[0][1] * m.E[1][1]; 21 ret.E[1][0] = E[1][0] * m.E[0][0] + E[1][1] * m.E[1][0]; 22 ret.E[1][1] = E[1][0] * m.E[0][1] + E[1][1] * m.E[1][1]; 23 return ret; 24 } 25 26 GSVector2 GSMatrix2x2::operator*(const GSVector2& v) const 27 { 28 return GSVector2(row(0).dot(v), row(1).dot(v)); 29 } 30 31 GSMatrix2x2 GSMatrix2x2::Identity() 32 { 33 GSMatrix2x2 ret; 34 ret.E[0][0] = 1.0f; 35 ret.E[0][1] = 0.0f; 36 ret.E[1][0] = 0.0f; 37 ret.E[1][1] = 1.0f; 38 return ret; 39 } 40 41 GSMatrix2x2 GSMatrix2x2::Rotation(float angle_in_radians) 42 { 43 const float sin_angle = std::sin(angle_in_radians); 44 const float cos_angle = std::cos(angle_in_radians); 45 46 GSMatrix2x2 ret; 47 ret.E[0][0] = cos_angle; 48 ret.E[0][1] = -sin_angle; 49 ret.E[1][0] = sin_angle; 50 ret.E[1][1] = cos_angle; 51 return ret; 52 } 53 54 GSVector2 GSMatrix2x2::row(size_t i) const 55 { 56 return GSVector2::load(&E[i][0]); 57 } 58 59 GSVector2 GSMatrix2x2::col(size_t i) const 60 { 61 return GSVector2(E[0][i], E[1][i]); 62 } 63 64 void GSMatrix2x2::store(void* m) 65 { 66 std::memcpy(m, E, sizeof(E)); 67 }