t
Loading...
Searching...
No Matches
Box.hpp
1#include "geometries/Geometry.hpp"
2
3#ifndef BOX_HPP
4#define BOX_HPP
5
6namespace t {
7
8// v2-------v3
9// /| /|
10// v1-------v0 | +Y
11// | | | | |
12// |v6------|v7 |---+X
13// |/ |/ /
14// v5-------v4 +Z
15
16#define halfWidth width / 2
17#define halfHeight height / 2
18#define halfDepth depth / 2
19
20// clang-format off
21#define vertexBuffer { \
22 /* v0 */ \
23 halfWidth, halfHeight, halfDepth, /* 0 X face */ \
24 halfWidth, halfHeight, halfDepth, /* 1 Y face */ \
25 halfWidth, halfHeight, halfDepth, /* 2 Z face */ \
26 \
27 /* v1 */ \
28 -halfWidth, halfHeight, halfDepth, /* 3 */ \
29 -halfWidth, halfHeight, halfDepth, /* 4 */ \
30 -halfWidth, halfHeight, halfDepth, /* 5 */ \
31 \
32 /* v2 */ \
33 -halfWidth, halfHeight, -halfDepth, /* 6 */ \
34 -halfWidth, halfHeight, -halfDepth, /* 7 */ \
35 -halfWidth, halfHeight, -halfDepth, /* 8 */ \
36 \
37 /* v3 */ \
38 halfWidth, halfHeight, -halfDepth, /* 9 */ \
39 halfWidth, halfHeight, -halfDepth, /* 10 */ \
40 halfWidth, halfHeight, -halfDepth, /* 11 */ \
41 \
42 /* v4 */ \
43 halfWidth, -halfHeight, halfDepth, /* 12 */ \
44 halfWidth, -halfHeight, halfDepth, /* 13 */ \
45 halfWidth, -halfHeight, halfDepth, /* 14 */ \
46 \
47 /* v5 */ \
48 -halfWidth, -halfHeight, halfDepth, /* 15 */ \
49 -halfWidth, -halfHeight, halfDepth, /* 16 */ \
50 -halfWidth, -halfHeight, halfDepth, /* 17 */ \
51 \
52 /* v6 */ \
53 -halfWidth, -halfHeight, -halfDepth, /* 18 */ \
54 -halfWidth, -halfHeight, -halfDepth, /* 19 */ \
55 -halfWidth, -halfHeight, -halfDepth, /* 20 */ \
56 \
57 /* v7 */ \
58 halfWidth, -halfHeight, -halfDepth, /* 21 */ \
59 halfWidth, -halfHeight, -halfDepth, /* 22 */ \
60 halfWidth, -halfHeight, -halfDepth, /* 23 */ \
61}
62
63#define indexBuffer { \
64 0, 12, 21, 21, 9, 0, /* +X face */ \
65 1, 10, 7, 7, 4, 1, /* +Y face */ \
66 2, 5, 14, 14, 5, 17, /* +Z face */ \
67 3, 6, 18, 18, 15, 3, /* -X face */ \
68 16, 19, 13, 13, 19, 22, /* -Y face */ \
69 8, 11, 20, 20, 11, 23, /* -Z face */ \
70}
71
72#define normalBuffer { \
73 /*X normal| Y normal| Z normal*/ \
74 1, 0, 0, 0, 1, 0, 0, 0, 1, /* v0 */ \
75 -1, 0, 0, 0, 1, 0, 0, 0, 1, /* v1 */ \
76 -1, 0, 0, 0, 1, 0, 0, 0, -1, /* v2 */ \
77 1, 0, 0, 0, 1, 0, 0, 0, -1, /* v3 */ \
78 1, 0, 0, 0, -1, 0, 0, 0, 1, /* v4 */ \
79 -1, 0, 0, 0, -1, 0, 0, 0, 1, /* v5 */ \
80 -1, 0, 0, 0, -1, 0, 0, 0, -1, /* v6 */ \
81 1, 0, 0, 0, -1, 0, 0, 0, -1, /* v7 */ \
82}
83// clang-format on
84
92class Box : public Geometry {
93public:
104 Box(double width, double height, double depth)
105 : Geometry(BufferAttribute<double>(vertexBuffer, 3),
106 BufferAttribute<double>(normalBuffer, 3)) {
107 setIndices(BufferAttribute<int>(indexBuffer, 3));
108 }
109};
110
111#undef vertexBuffer
112#undef indexBuffer
113#undef normalBuffer
114#undef halfWidth
115#undef halfHeight
116#undef halfDepth
117
118} // namespace t
119
120#endif // BOX_HPP
The geometry of a cuboid (box).
Definition Box.hpp:92
Box(double width, double height, double depth)
Creates a new box geometry with the specified width, height, and depth.
Definition Box.hpp:104
A class representing attributes, such as vertex positions, face indices, and vertex normals.
Definition BufferAttribute.hpp:27
The base 3D geometry class.
Definition Geometry.hpp:37
void setIndices(BufferAttribute< int > _faceIndices)
Sets the index buffer of this geometry.
Definition Geometry.hpp:93
The t software 3D graphics library namespace.
Definition algorithms.hpp:12