-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcube.cpp
125 lines (101 loc) · 3.82 KB
/
cube.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <algorithm>
#include <iostream>
#include "cube.hpp"
using namespace std;
Cube::Cube(float x, float y, float z, int colour):x(x), y(y), z(z), colour(colour){
/* Cube sides are labelled in the default view. Triangles are
* named with respect to the position of their right angle in the
* face of the cube
*/
//Floor upper-left
vertices[0] = vec3(x + -0.5f/scale, y + -0.5f/scale, z + -0.5f/scale);
vertices[1] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + -0.5f/scale);
vertices[2] = vec3(x + -0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
//Floor bottom-right
vertices[3] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
vertices[4] = vec3(x + -0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
vertices[5] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + -0.5f/scale);
//Back bottom-left
vertices[6] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
vertices[7] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + -0.5f/scale);
vertices[8] = vec3(x + -0.5f/scale, y + -0.5f/scale, z + -0.5f/scale);
//Back upper-right
vertices[9] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + -0.5f/scale);
vertices[10] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
vertices[11] = vec3(x + 0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
//Left-side bottom-right
vertices[12] = vec3(x + -0.5f/scale, y + -0.5f/scale, z + -0.5f/scale);
vertices[13] = vec3(x + -0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
vertices[14] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
//Left-side upper-left
vertices[15] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
vertices[16] = vec3(x + -0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
vertices[17] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + 0.5f/scale);
//Right-side bottom-right
vertices[18] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + -0.5f/scale);
vertices[19] = vec3(x + 0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
vertices[20] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
//Right-side upper-left
vertices[21] = vec3(x + 0.5f/scale, y + 0.5f/scale, z + 0.5f/scale);
vertices[22] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
vertices[23] = vec3(x + 0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
//Front-side bottom-left
vertices[24] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
vertices[25] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + 0.5f/scale);
vertices[26] = vec3(x + -0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
//Front-side upper-right
vertices[27] = vec3(x + 0.5f/scale, y + 0.5f/scale, z + 0.5f/scale);
vertices[28] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + 0.5f/scale);
vertices[29] = vec3(x + 0.5f/scale, y + -0.5f/scale, z + 0.5f/scale);
//Top-side upper-left
vertices[30] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
vertices[31] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + 0.5f/scale);
vertices[32] = vec3(x + 0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
//Top-side bottom-right
vertices[33] = vec3(x + 0.5f/scale, y + 0.5f/scale, z + 0.5f/scale);
vertices[34] = vec3(x + 0.5f/scale, y + 0.5f/scale, z + -0.5f/scale);
vertices[35] = vec3(x + -0.5f/scale, y + 0.5f/scale, z + 0.5f/scale);
}
Cube::Cube(float x, float y, float z): Cube(x, y, z, default_colour)
{
}
vec3* Cube::get_vertices()
{
return vertices;
}
bool Cube::draw()
{
return draw_cube;
}
void Cube::print_properties(){
cout << x << y << z << endl;
}
bool Cube::operator==(const Cube& test_cube){
if (x == test_cube.get_x()
&& y == test_cube.get_y()
&& z == test_cube.get_z())
return true;
}
/*
* Use a pointer to allow for easier modification of colours for
* groups of cubes.
*/
void Cube::set_colour(int new_colour){
colour = new_colour;
}
int Cube::get_colour(){
return colour;
}
int Cube::get_x() const{
return x;
}
int Cube::get_y() const{
return y;
}
int Cube::get_z() const{
return z;
}
Cube::Cube(){}
Cube::~Cube()
{
}