moved Mat4 definition

This commit is contained in:
2023-06-03 19:40:50 +02:00
parent f2fcc348d7
commit 0365902971
9 changed files with 44 additions and 43 deletions

View File

@@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
namespace td {
template<typename T>
@@ -95,4 +97,34 @@ using Vec4d = Vec4<double>;
using Color = Vec3<unsigned char>;
template<typename T>
struct Mat4 {
static const std::size_t MATRIX_SIZE = 4;
T x0, x1, x2, x3;
T y0, y1, y2, y3;
T z0, z1, z2, z3;
T w0, w1, w2, w3;
T operator[] (std::size_t offset) const {
return reinterpret_cast<const T*>(this)[offset];
}
T& operator[] (std::size_t offset) {
return reinterpret_cast<T*>(this)[offset];
}
T at(std::size_t row, std::size_t column) const {
return operator[](row * MATRIX_SIZE + column);
}
T& at(std::size_t row, std::size_t column) {
return operator[](row * MATRIX_SIZE + column);
}
};
typedef Mat4<float> Mat4f;
typedef Mat4<int> Mat4i;
typedef Mat4<double> Mat4d;
} // namespace td

View File

@@ -55,36 +55,6 @@ T Dot(const Vec4<T>& vect, const Vec4<T>& other) {
// Matricies //
//////////////////////////////////////////////////////////////////
template<typename T>
struct Mat4 {
static const std::size_t MATRIX_SIZE = 4;
T x0, x1, x2, x3;
T y0, y1, y2, y3;
T z0, z1, z2, z3;
T w0, w1, w2, w3;
T operator[] (std::size_t offset) const {
return reinterpret_cast<const T*>(this)[offset];
}
T& operator[] (std::size_t offset) {
return reinterpret_cast<T*>(this)[offset];
}
T at(std::size_t row, std::size_t column) const {
return operator[](row * MATRIX_SIZE + column);
}
T& at(std::size_t row, std::size_t column) {
return operator[](row * MATRIX_SIZE + column);
}
};
typedef Mat4<float> Mat4f;
typedef Mat4<int> Mat4i;
typedef Mat4<double> Mat4d;
template<typename T>
Vec4<T> Dot(const Mat4<T>& mat, const Vec4<T>& vect) {
return {

View File

@@ -19,8 +19,8 @@ public:
void LoadShader();
void SetColorEffect(const Vec3f& color);
void SetProjectionMatrix(const maths::Mat4f& proj) const;
void SetViewMatrix(const maths::Mat4f& view) const;
void SetProjectionMatrix(const Mat4f& proj) const;
void SetViewMatrix(const Mat4f& view) const;
void SetModelPos(const Vec3f& pos) const;
};

View File

@@ -3,7 +3,6 @@
#include <string>
#include "Defines.h"
#include "render/GL.h"
#include "misc/Maths.h"
namespace td {
namespace shader {
@@ -28,7 +27,7 @@ protected:
void LoadVector(unsigned int location, const Vec2f& vector) const;
void LoadVector(unsigned int location, const Vec3f& vector) const;
void LoadBoolean(unsigned int location, bool value) const;
void LoadMat4(unsigned int location, const maths::Mat4f& mat) const;
void LoadMat4(unsigned int location, const Mat4f& mat) const;
void CleanUp() const;
private:

View File

@@ -14,8 +14,8 @@ public:
WorldShader();
void LoadShader();
void SetProjectionMatrix(const maths::Mat4f& proj) const;
void SetViewMatrix(const maths::Mat4f& view) const;
void SetProjectionMatrix(const Mat4f& proj) const;
void SetViewMatrix(const Mat4f& view) const;
};
} // namespace shader