moved Mat4 definition
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -98,7 +98,7 @@ void Renderer::Prepare() {
|
||||
}
|
||||
|
||||
void Renderer::Resize(int width, int height) {
|
||||
maths::Mat4f projectionMatrix = maths::Perspective(80.0f / 180.0f * M_PI, static_cast<float>(width) / height, 0.1f, 160.0f);
|
||||
Mat4f projectionMatrix = maths::Perspective(80.0f / 180.0f * M_PI, static_cast<float>(width) / height, 0.1f, 160.0f);
|
||||
m_WorldShader->Start();
|
||||
m_WorldShader->SetProjectionMatrix(projectionMatrix);
|
||||
m_EntityShader->Start();
|
||||
@@ -121,7 +121,7 @@ void Renderer::SetCamMovement(const Vec2f& mov) {
|
||||
|
||||
void Renderer::SetCamPos(const Vec2f& newPos) {
|
||||
m_CamPos = newPos;
|
||||
maths::Mat4f viewMatrix = maths::Look({m_CamPos.x, 50, m_CamPos.y}, {0, -1, -0.0001}, {0, 1, 0});
|
||||
Mat4f viewMatrix = maths::Look({m_CamPos.x, 50, m_CamPos.y}, {0, -1, -0.0001}, {0, 1, 0});
|
||||
m_WorldShader->Start();
|
||||
m_WorldShader->SetViewMatrix(viewMatrix);
|
||||
m_EntityShader->Start();
|
||||
|
||||
@@ -104,11 +104,11 @@ void EntityShader::SetColorEffect(const Vec3f& color) {
|
||||
LoadVector(m_LocationColorEffect, color);
|
||||
}
|
||||
|
||||
void EntityShader::SetProjectionMatrix(const maths::Mat4f& proj) const {
|
||||
void EntityShader::SetProjectionMatrix(const Mat4f& proj) const {
|
||||
LoadMat4(m_LocationProjectionMatrix, proj);
|
||||
}
|
||||
|
||||
void EntityShader::SetViewMatrix(const maths::Mat4f& view) const {
|
||||
void EntityShader::SetViewMatrix(const Mat4f& view) const {
|
||||
LoadMat4(m_LocationViewMatrix, view);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ void ShaderProgram::LoadBoolean(unsigned int location, bool value) const {
|
||||
glUniform1i(static_cast<GLint>(location), value);
|
||||
}
|
||||
|
||||
void ShaderProgram::LoadMat4(unsigned int location, const maths::Mat4f& mat) const {
|
||||
void ShaderProgram::LoadMat4(unsigned int location, const Mat4f& mat) const {
|
||||
glUniformMatrix4fv(static_cast<GLint>(location), 1, false, reinterpret_cast<const float*>(&mat));
|
||||
}
|
||||
|
||||
|
||||
@@ -92,11 +92,11 @@ void WorldShader::GetAllUniformLocation() {
|
||||
m_LocationView = static_cast<unsigned int>(GetUniformLocation("viewMatrix"));
|
||||
}
|
||||
|
||||
void WorldShader::SetProjectionMatrix(const maths::Mat4f& proj) const {
|
||||
void WorldShader::SetProjectionMatrix(const Mat4f& proj) const {
|
||||
LoadMat4(m_LocationProjection, proj);
|
||||
}
|
||||
|
||||
void WorldShader::SetViewMatrix(const maths::Mat4f& view) const {
|
||||
void WorldShader::SetViewMatrix(const Mat4f& view) const {
|
||||
LoadMat4(m_LocationView, view);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user