72 lines
1.4 KiB
C++
72 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "Defines.h"
|
|
#include <memory>
|
|
#include "loader/GLLoader.h"
|
|
#include "render/shaders/WorldShader.h"
|
|
#include "render/shaders/EntityShader.h"
|
|
|
|
namespace td {
|
|
namespace render {
|
|
|
|
struct Camera {
|
|
Mat4f viewMatrix;
|
|
Mat4f projectionMatrix;
|
|
Mat4f InvViewMatrix;
|
|
Mat4f InvProjectionMatrix;
|
|
|
|
Vec3f CamPos {0, 25, 0};
|
|
|
|
Vec2f CamLook {};
|
|
|
|
Vec3f m_Front {0, -1, 0};
|
|
|
|
float m_Yaw = -3.141592653f / 2.0f;
|
|
float m_Pitch = -3.141592653f / 2.0f - 0.0000001f;
|
|
};
|
|
|
|
class Renderer {
|
|
public:
|
|
static constexpr float m_AnimationSpeed = 2.0f;
|
|
|
|
struct Model {
|
|
GL::VertexArray* vao;
|
|
Vec3f positon;
|
|
Vec3f color = { 1, 1, 1 };
|
|
};
|
|
private:
|
|
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
|
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
|
|
|
Vec2i m_WindowSize;
|
|
|
|
Vec3f m_BackgroundColor;
|
|
|
|
Camera m_Camera {};
|
|
public:
|
|
Renderer();
|
|
~Renderer();
|
|
|
|
bool Init();
|
|
|
|
void Prepare();
|
|
void Resize(const int width, const int height);
|
|
|
|
void RenderVAO(const GL::VertexArray& vao);
|
|
void RenderModel(const Model& model);
|
|
|
|
void SetZoom(float zoom);
|
|
void SetCamMovement(const Vec2f& mov);
|
|
void SetCamLook(const Vec2f& worldPos);
|
|
|
|
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
|
|
|
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float windowWidth, float windowHeight);
|
|
private:
|
|
void InitShaders();
|
|
void SetCamPos(const Vec3f& newPos);
|
|
};
|
|
|
|
} // namespace render
|
|
} // namespace td
|