diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-22 03:56:58 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-22 03:56:58 +0100 |
commit | 9e749583791c9523efab90665ffd8f5c30e4f449 (patch) | |
tree | bcb7fd1774e0b1ca4f69ff19c9c2f9e3c63eac1a /src/quads.cpp | |
parent | 34c451c6b64ba1c11efa9a390c16e2097a25279a (diff) |
a wip
Diffstat (limited to 'src/quads.cpp')
-rw-r--r-- | src/quads.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/quads.cpp b/src/quads.cpp new file mode 100644 index 00000000..a02654b0 --- /dev/null +++ b/src/quads.cpp @@ -0,0 +1,60 @@ +#include "quads.hpp" + +namespace floormat::Quads { + +std::array<UnsignedShort, 6> quad_indexes(size_t N) +{ + using u16 = UnsignedShort; + return { /* 3--1 1 */ + (u16)(0+N*4), (u16)(1+N*4), (u16)(2+N*4), /* | / /| */ + (u16)(2+N*4), (u16)(1+N*4), (u16)(3+N*4), /* |/ / | */ + }; /* 2 2--0 */ +} + +quad floor_quad(const Vector3 center, const Vector2 size) +{ + float x = size[0]*.5f, y = size[1]*.5f; + return {{ + { x + center[0], -y + center[1], center[2]}, + { x + center[0], y + center[1], center[2]}, + {-x + center[0], -y + center[1], center[2]}, + {-x + center[0], y + center[1], center[2]}, + }}; +} + +quad wall_quad_W(const Vector3 center, const Vector3 size) +{ + float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; + return {{ + {-x + center[0], y + center[1], z + center[2] }, + {-x + center[0], y + center[1], center[2] }, + {-x + center[0], -y + center[1], z + center[2] }, + {-x + center[0], -y + center[1], center[2] }, + }}; +} + +quad wall_quad_N(const Vector3 center, const Vector3 size) +{ + float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; + return {{ + { x + center[0], -y + center[1], z + center[2] }, + { x + center[0], -y + center[1], center[2] }, + {-x + center[0], -y + center[1], z + center[2] }, + {-x + center[0], -y + center[1], center[2] }, + }}; +} + +texcoords texcoords_at(Vector2ui pos_, Vector2ui size_, Vector2ui image_size_) +{ + auto pos = Vector2(pos_), size = Vector2(size_), image_size = Vector2(image_size_); + auto offset = pos + Vector2(.5f), end = offset + size - Vector2(1); + auto x0 = offset / image_size, x1 = end / image_size; + return {{ + { x1.x(), 1.f - x1.y() }, // bottom right + { x1.x(), 1.f - x0.y() }, // top right + { x0.x(), 1.f - x1.y() }, // bottom left + { x0.x(), 1.f - x0.y() }, // top left + }}; +} + +} // namespace floormat::Quads |