-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCuboid.cpp
More file actions
81 lines (68 loc) · 3.5 KB
/
Copy pathCuboid.cpp
File metadata and controls
81 lines (68 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <cpp3ds/Graphics/Cuboid.hpp>
namespace cpp3ds
{
////////////////////////////////////////////////////////////
Cuboid::Cuboid(const Vector3f& size)
{
setSize(size);
}
////////////////////////////////////////////////////////////
void Cuboid::setSize(const Vector3f& size)
{
m_size = size;
update();
generateNormals();
}
////////////////////////////////////////////////////////////
const Vector3f& Cuboid::getSize() const
{
return m_size;
}
////////////////////////////////////////////////////////////
unsigned int Cuboid::getFaceCount() const
{
return 12;
}
////////////////////////////////////////////////////////////
Polyhedron::Face Cuboid::getFace(unsigned int index) const
{
float left = m_size.x / -2.f;
float top = m_size.y / 2.f;
float front = m_size.z / 2.f;
float right = m_size.x / 2.f;
float bottom = m_size.y / -2.f;
float back = m_size.z / -2.f;
const Color& color = getColor();
switch (index)
{
default:
// Front 1
case 0: { Face face = {Vertex(Vector3f(left, top, front), color), Vertex(Vector3f(left, bottom, front), color), Vertex(Vector3f(right, bottom, front), color)}; return face; }
// Front 2
case 1: { Face face = {Vertex(Vector3f(left, top, front), color), Vertex(Vector3f(right, bottom, front), color), Vertex(Vector3f(right, top, front), color)}; return face; }
// Right 1
case 2: { Face face = {Vertex(Vector3f(right, top, front), color), Vertex(Vector3f(right, bottom, front), color), Vertex(Vector3f(right, bottom, back), color)}; return face; }
// Right 2
case 3: { Face face = {Vertex(Vector3f(right, top, front), color), Vertex(Vector3f(right, bottom, back), color), Vertex(Vector3f(right, top, back), color)}; return face; }
// Back 1
case 4: { Face face = {Vertex(Vector3f(right, top, back), color), Vertex(Vector3f(right, bottom, back), color), Vertex(Vector3f(left, bottom, back), color)}; return face; }
// Back 2
case 5: { Face face = {Vertex(Vector3f(right, top, back), color), Vertex(Vector3f(left, bottom, back), color), Vertex(Vector3f(left, top, back), color)}; return face; }
// Left 1
case 6: { Face face = {Vertex(Vector3f(left, top, back), color), Vertex(Vector3f(left, bottom, back), color), Vertex(Vector3f(left, bottom, front), color)}; return face; }
// Left 2
case 7: { Face face = {Vertex(Vector3f(left, top, back), color), Vertex(Vector3f(left, bottom, front), color), Vertex(Vector3f(left, top, front), color)}; return face; }
// Top 1
case 8: { Face face = {Vertex(Vector3f(left, top, back), color), Vertex(Vector3f(left, top, front), color), Vertex(Vector3f(right, top, front), color)}; return face; }
// Top 2
case 9: { Face face = {Vertex(Vector3f(left, top, back), color), Vertex(Vector3f(right, top, front), color), Vertex(Vector3f(right, top, back), color)}; return face; }
// Bottom 1
case 10: { Face face = {Vertex(Vector3f(left, bottom, front), color), Vertex(Vector3f(left, bottom, back), color), Vertex(Vector3f(right, bottom, back), color)}; return face; }
// Bottom 2
case 11: { Face face = {Vertex(Vector3f(left, bottom, front), color), Vertex(Vector3f(right, bottom, back), color), Vertex(Vector3f(right, bottom, front), color)}; return face; }
}
}
} // namespace cpp3ds