| 359 | std::array<Vec2<float>, 4> vertices; |
| 360 | std::array<Vec2<float>, 4> texcoords; |
| 361 | Quad(const Rect<float> &position, const Rect<float> texCoords = {{0, 0}, {1, 1}}, |
| 362 | const Vec2<float> &rotationCenter = {0.0f, 0.0f}, float rotationAngleRadians = 0.0f) |
| 363 | { |
| 364 | texcoords = {{ |
| 365 | Vec2<float>{texCoords.p0}, |
| 366 | Vec2<float>{texCoords.p1.x, texCoords.p0.y}, |
| 367 | Vec2<float>{texCoords.p0.x, texCoords.p1.y}, |
| 368 | Vec2<float>{texCoords.p1}, |
| 369 | }}; |
| 370 | |
| 371 | if (rotationAngleRadians != 0.0f) |
| 372 | { |
| 373 | auto rotMatrix = glm::rotate(rotationAngleRadians, Vec3<float>{0.0f, 0.0f, 1.0f}); |
| 374 | Vec2<float> size = position.p1 - position.p0; |
| 375 | vertices = {{ |
| 376 | Vec2<float>{0.0f, 0.0f}, |
| 377 | Vec2<float>{size.x, 0.0f}, |
| 378 | Vec2<float>{0.0f, size.y}, |
| 379 | Vec2<float>{size}, |
| 380 | }}; |
| 381 | for (auto &p : vertices) |
| 382 | { |
| 383 | p -= rotationCenter; |
| 384 | glm::vec4 transformed = rotMatrix * glm::vec4{p.x, p.y, 0.0f, 1.0f}; |
| 385 | p.x = transformed.x; |
| 386 | p.y = transformed.y; |
| 387 | p += rotationCenter; |
| 388 | p += position.p0; |
| 389 | } |
| 390 | } |
| 391 | else |
| 392 | { |
| 393 | vertices = {{ |
| 394 | Vec2<float>{position.p0}, |
| 395 | Vec2<float>{position.p1.x, position.p0.y}, |
| 396 | Vec2<float>{position.p0.x, position.p1.y}, |
| 397 | Vec2<float>{position.p1}, |
| 398 | }}; |
| 399 | } |
| 400 | } |
| 401 | void draw(GLuint vertexAttribPos, GLuint texcoordAttribPos) |
| 402 | { |
| 403 | gl20::EnableVertexAttribArray(vertexAttribPos); |