#pragma once #include "Defines.h" #include #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; float CamDistance = 25.0f; Vec3f CamPos{ 0, CamDistance, 0 }; Vec2f CamLook{}; float m_Yaw = -PI / 2.0f; float m_Pitch = -PI / 2.0f + 0.0000001f; }; struct Model { std::unique_ptr vao; Vec3f positon; Vec3f color = { 1, 1, 1 }; }; class TexturedModel { private: std::unique_ptr m_Vao; std::unique_ptr m_Texture; Vec3f m_Positon; Vec3f m_Color = { 1, 1, 1 }; public: REMOVE_COPY(TexturedModel); TexturedModel(GL::VertexArray&& vao, GL::Texture&& texture); TexturedModel(TexturedModel&& other); ~TexturedModel() {} const GL::VertexArray& GetVao() const { return *m_Vao; } const GL::Texture& GetTexture() const { return *m_Texture; } Vec3f GetPosition() const { return m_Positon; } Vec3f GetColor() const { return m_Color; } void SetPosition(Vec3f newPos) { m_Positon = newPos; } void SetColor(Vec3f newColor) { m_Color = newColor; } }; class Renderer { public: static constexpr float m_AnimationSpeed = 2.0f; static constexpr float m_MouseSensitivity = 200.0f; private: std::unique_ptr m_WorldShader; std::unique_ptr 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 RenderModel(const TexturedModel& model); void AddZoom(float zoom); void SetCamAngularMovement(const Vec2f& mov); void SetCamMovement(const Vec2f& lastCursorPos, const Vec2f& currentCursorPos); 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