35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#include "shape.hpp"
|
|
|
|
namespace gz::vk {
|
|
Rectangle::Rectangle(float top, float left, uint32_t width, uint32_t height, glm::vec3 color)
|
|
: top(top), left(left), width(width), height(height), color(color) {
|
|
generateVertices();
|
|
|
|
}
|
|
|
|
|
|
void Rectangle::generateVertices() {
|
|
vertices.clear();
|
|
vertices.emplace_back(Vertex2D{glm::vec2(top, left), color, glm::vec2(0, 0)});
|
|
vertices.emplace_back(Vertex2D{glm::vec2(top, left + width), color, glm::vec2(1, 0)});
|
|
vertices.emplace_back(Vertex2D{glm::vec2(top + height, left + width), color, glm::vec2(1, 1)});
|
|
vertices.emplace_back(Vertex2D{glm::vec2(top + height, left), color, glm::vec2(0, 1)});
|
|
indices = { 0, 1, 2, 2, 3, 0 };
|
|
/* indices = { 2, 1, 0, 2, 3, 0 }; */
|
|
}
|
|
|
|
void Shape::setIndexOffset(uint32_t offset) {
|
|
for (size_t i = 0; i < indices.size(); i++) {
|
|
indices[i] += offset;
|
|
}
|
|
|
|
}
|
|
|
|
void Shape::setNormalize(float width, float height) {
|
|
for (size_t i = 0; i < vertices.size(); i++) {
|
|
vertices[i].pos.x /= width;
|
|
vertices[i].pos.y /= height;
|
|
}
|
|
}
|
|
} // namespaec gz::vk
|