|
4 | 4 | #include "omath/3d_primitives/box.hpp"
|
5 | 5 |
|
6 | 6 |
|
7 |
| - |
8 | 7 | namespace omath::primitives
|
9 | 8 | {
|
10 |
| - |
11 |
| - std::array<Triangle<Vector3<float>>, 8> CreateBox(const Vector3<float>& top, const Vector3<float>& bottom, |
12 |
| - const Vector3<float>& dirForward, |
13 |
| - const Vector3<float>& dirRight, |
14 |
| - const float ratio) |
| 9 | + std::array<Triangle<Vector3<float>>, 12> CreateBox(const Vector3<float>& top, const Vector3<float>& bottom, |
| 10 | + const Vector3<float>& dirForward, |
| 11 | + const Vector3<float>& dirRight, |
| 12 | + const float ratio) |
15 | 13 | {
|
16 | 14 | const auto height = top.DistTo(bottom);
|
17 | 15 | const auto sideSize = height / ratio;
|
18 | 16 |
|
19 |
| - std::array<Vector3<float>, 8> points; |
| 17 | + // corner layout (0‑3 bottom, 4‑7 top) |
| 18 | + std::array<Vector3<float>, 8> p; |
| 19 | + p[0] = bottom + (dirForward + dirRight) * sideSize; // front‑right‑bottom |
| 20 | + p[1] = bottom + (dirForward - dirRight) * sideSize; // front‑left‑bottom |
| 21 | + p[2] = bottom + (-dirForward + dirRight) * sideSize; // back‑right‑bottom |
| 22 | + p[3] = bottom + (-dirForward - dirRight) * sideSize; // back‑left‑bottom |
| 23 | + p[4] = top + (dirForward + dirRight) * sideSize; // front‑right‑top |
| 24 | + p[5] = top + (dirForward - dirRight) * sideSize; // front‑left‑top |
| 25 | + p[6] = top + (-dirForward + dirRight) * sideSize; // back‑right‑top |
| 26 | + p[7] = top + (-dirForward - dirRight) * sideSize; // back‑left‑top |
| 27 | + |
| 28 | + std::array<Triangle<Vector3<float>>, 12> poly; |
20 | 29 |
|
21 |
| - points[0] = bottom + (dirForward + dirRight) * sideSize; |
22 |
| - points[1] = bottom + (dirForward - dirRight) * sideSize; |
| 30 | + // bottom face (+Y up ⇒ wind CW when viewed from above) |
| 31 | + poly[0] = {p[0], p[2], p[3]}; |
| 32 | + poly[1] = {p[0], p[3], p[1]}; |
23 | 33 |
|
24 |
| - points[2] = bottom + (-dirForward + dirRight) * sideSize; |
25 |
| - points[3] = bottom + (-dirForward - dirRight) * sideSize; |
| 34 | + // top face |
| 35 | + poly[2] = {p[4], p[7], p[6]}; |
| 36 | + poly[3] = {p[4], p[5], p[7]}; |
26 | 37 |
|
27 |
| - points[4] = top + (dirForward + dirRight) * sideSize; |
28 |
| - points[5] = top + (dirForward - dirRight) * sideSize; |
| 38 | + // front face |
| 39 | + poly[4] = {p[0], p[5], p[1]}; |
| 40 | + poly[5] = {p[0], p[4], p[5]}; |
29 | 41 |
|
30 |
| - points[6] = top + (-dirForward + dirRight) * sideSize; |
31 |
| - points[7] = top + (-dirForward - dirRight) * sideSize; |
| 42 | + // right face |
| 43 | + poly[6] = {p[0], p[6], p[2]}; |
| 44 | + poly[7] = {p[0], p[4], p[6]}; |
32 | 45 |
|
| 46 | + // back face |
| 47 | + poly[8] = {p[2], p[7], p[3]}; |
| 48 | + poly[9] = {p[2], p[6], p[7]}; |
33 | 49 |
|
34 |
| - std::array<Triangle<Vector3<float>>, 8> polygons; |
| 50 | + // left face |
| 51 | + poly[10] = {p[1], p[7], p[5]}; |
| 52 | + poly[11] = {p[1], p[3], p[7]}; |
35 | 53 |
|
36 |
| - polygons[0] = {points[0], points[2], points[3]}; |
37 |
| - return polygons; |
| 54 | + return poly; |
38 | 55 | }
|
39 | 56 | }
|
0 commit comments