diff --git a/include/DrawOverlays.hpp b/include/DrawOverlays.hpp new file mode 100644 index 00000000..fcd8cfad --- /dev/null +++ b/include/DrawOverlays.hpp @@ -0,0 +1,96 @@ +// +// Created by 盧威任 on 3/8/24. +// + +#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_DRAWOVERLAYS_HPP +#define PRACTICALTOOLSFORSIMPLEDESIGN_DRAWOVERLAYS_HPP +#include "Core/Drawable.hpp" +#include "pch.hpp" +class DrawOverlays : public Core::Drawable { + + /* boxes:draw box on cell + *cross:draw cross on cell + * selected: defines bottom left & top right, show selected "corner" on + *given cell range circle: defines only the center(cell coord) & the + *radius(cell) circle-dash: defines only the center(cell coord) & the + *radius(cell) + */ + enum class OverlayShapes { BOXES, CROSS, SELECTED, CIRCLE }; + +public: + DrawOverlays(){}; + ~DrawOverlays(){}; + void Start(std::vector cellcoords, OverlayShapes shapes) {} + + void InitVertexAndColor() { + /* + std::vector vertex = {}; + std::vector color = {}; + std::vector index = {}; + for (auto line : m_lineVector) { + vertex.push_back(line.getlineFrom().x); + vertex.push_back(line.getlineFrom().y); + color.push_back(line.getColor().x); + color.push_back(line.getColor().y); + color.push_back(line.getColor().z); + + vertex.push_back(line.getlineTo().x); + vertex.push_back(line.getlineTo().y); + color.push_back(line.getColor().x); + color.push_back(line.getColor().y); + color.push_back(line.getColor().z); + } + m_VertexArray->AddVertexBuffer( + std::make_unique(vertex, 2)); + m_VertexArray->AddVertexBuffer( + std::make_unique(color, 3)); + */ + } + + void Draw(const Util::Transform &trans, const float zindex) override {} + + void DrawUsingCamera(const Util::Transform &trans, + const float zindex) override { + /* + if (m_Activate == false) { + return; + } + glLineWidth(m_shapelineWidth); + + m_Program.Bind(); + m_Program.Validate(); + m_VertexArray->Bind(); + + auto cp = CameraClass::getProjectionMatrix(); + auto cv = CameraClass::getViewMatrix(); + + constexpr glm::mat4 eye(1.F); + + glm::vec2 size = {1.F, 1.F}; + + auto data = Util::ConvertToUniformBufferDataUsingCameraMatrix( + transform, size, zIndex); + + m_Matrices->SetData(0, data); + m_VertexArray->Bind(); + + m_VertexArray->DrawLines(m_lineVector.size() * 5 * 2); + */ + } + +private: + Core::Program m_Program = Core::Program("../assets/shaders/DrawLines.vert", + "../assets/shaders/DrawLines.frag"); + + std::unique_ptr> m_Matrices = + std::make_unique>(m_Program, "Grid", + 0); + + float m_shapelineWidth = 1.0F; + glm::vec2 shapelinecolor; + + std::unique_ptr m_VertexArray = + std::make_unique(); +}; + +#endif // PRACTICALTOOLSFORSIMPLEDESIGN_DRAWOVERLAYS_HPP diff --git a/include/Map.hpp b/include/Map.hpp index 639f2a96..a3fda367 100644 --- a/include/Map.hpp +++ b/include/Map.hpp @@ -16,7 +16,7 @@ class MapClass : public Core::Drawable { public: MapClass() {} - void Init(std::vector> map, + void Init(std::vector>> map, std::shared_ptr spritesheet, CELL width, CELL height) { m_Map = map; @@ -71,6 +71,15 @@ class MapClass : public Core::Drawable { int(cellCoord[1] * CELL_SIZE.y) + 0.5 * CELL_SIZE.y); } + std::shared_ptr getTileByCellPosition(glm::vec2 position) { + if (position.x > m_MapWdith - 1 || position.y > m_MapHeight - 1 || + position.x < 0 || position.y < 0) { + LOG_DEBUG("False Position Getting"); + return nullptr; + } + return m_Map[position.x][position.y]; + } + // weird static std::vector> readMapAndTileSet(std::vector map, std::map tileset) { @@ -105,7 +114,7 @@ class MapClass : public Core::Drawable { CELL m_MapWdith; CELL m_MapHeight; glm::vec2 m_MapPosition = {0, 0}; - std::vector> m_Map; + std::vector>> m_Map; std::shared_ptr m_SpriteSheet; int m_ZIndex = 0; Grid m_Grid; diff --git a/include/Rectangle.hpp b/include/Rectangle.hpp deleted file mode 100644 index e39fe650..00000000 --- a/include/Rectangle.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RECTANGLE_HPP -#define RECTANGLE_HPP - -// IWYU pragma: export - -#include "Core/Program.hpp" -#include "Core/UniformBuffer.hpp" -#include "Core/VertexArray.hpp" - -struct Matrix { - glm::mat2 m_Porj; - glm::mat2 m_Model; -}; - -class Rectangle { -public: - Rectangle(); - - ~Rectangle() = default; - - void Update(); - -private: - Core::Program m_Program = Core::Program("../assets/shaders/Triangle.vert", - "../assets/shaders/Triangle.frag"); - std::unique_ptr m_VertexArray = - std::make_unique(); - std::unique_ptr> m_Matrices = - std::make_unique>(m_Program, "Rectangle", - 0); -}; - -#endif diff --git a/src/Grid.cpp b/src/Grid.cpp index b1466502..52f36f38 100644 --- a/src/Grid.cpp +++ b/src/Grid.cpp @@ -21,9 +21,8 @@ void Grid::Draw(const Util::Transform &transform, const float zindex) { void Grid::DrawUsingCamera(const Util::Transform &transform, const float zIndex) { - // TODO:awaiting to be debugged if (m_Activate == false) { - // return; + return; } glLineWidth(m_lineWidth);