forked from amundhov/legendary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcube.cpp
122 lines (107 loc) · 3.55 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
#include "cube.h"
#include "msg.h"
#include "rawtexture.h"
Cube::Cube() : VboObject() {
if (reference_count == 1) {
genBO();
m_material = new RawTexture("legendary.raw");
//mat = new CRenderToTextureMaterial;
LOG("Cube VBO generated\n");
}
}
Cube::~Cube() {
delete m_material;
}
void Cube::draw() {
m_material->Bind();
VboObject::draw();
}
vec3* Cube::getVertices() {
vec3 vcube[] =
{ { -1.0, -1.0, 1.0, }, // 4 Front 0
{ 1.0, 1.0, 1.0, }, // 1
{ -1.0, 1.0, 1.0, }, // 0 2
{ 1.0, -1.0, 1.0, }, // 5
{ 1.0, -1.0, 1.0, }, // 5 Right 4
{ 1.0, -1.0, -1.0, }, // 7
{ 1.0, 1.0, -1.0, }, // 3 6
{ 1.0, 1.0, 1.0, }, // 1
{ -1.0, -1.0, -1.0, }, // 6 Bottom 8
{ 1.0, -1.0, -1.0, }, // 7
{ 1.0, -1.0, 1.0, }, // 5 10
{ -1.0, -1.0, 1.0, }, // 4
{ -1.0, -1.0, -1.0, }, // 6 Left 12
{ -1.0, -1.0, 1.0, }, // 4
{ -1.0, 1.0, 1.0, }, // 0 14
{ -1.0, 1.0, -1.0, }, // 2
{ 1.0, -1.0, -1.0, }, // 7 Back 16
{ -1.0, -1.0, -1.0, }, // 6
{ 1.0, 1.0, -1.0, }, // 3 18
{ -1.0, 1.0, -1.0, }, // 2
{ -1.0, 1.0, 1.0, }, // 0 Top 20
{ 1.0, 1.0, 1.0, }, // 1
{ 1.0, 1.0, -1.0, }, // 3 22
{ -1.0, 1.0, -1.0 } // 2
};
int vertices = 6*4;
VBO_size_vertices = vertices*sizeof(vec3);
vec3 *ret = new vec3[vertices];
for ( int i=0; i < vertices; i++ ) {
ret[i] = vcube[i];
}
return ret;
}
unsigned short int* Cube::getIndices() {
unsigned short int icube[] = {
0, 1, 2, 1, 0, 3,
4, 5, 6, 4, 6, 7,
8, 9, 10, 8, 10, 11,
12, 13, 14, 12, 14, 15,
16, 17, 18, 18, 17, 23,
20, 21, 22, 22, 23, 20
};
IBO_size_indices = sizeof(icube);
IBO_indices = sizeof(icube)/sizeof(unsigned short int);
unsigned short int *ret = new unsigned short int[IBO_indices];
for ( int i=0; i < IBO_indices; i++ ) {
ret[i] = icube[i];
}
return ret;
}
unsigned char* Cube::getColours() {
unsigned char ccube[] = {
200, 000, 000, 055, 255, 000, 255, 255, 255, 050, 000, 050, // Front
000, 000, 100, 100, 000, 000, 000, 200, 000, 255, 255, 255, // Right
000, 100, 000, 100, 000, 200, 200, 000, 000, 100, 000, 200, // Bottom
150, 200, 000, 100, 200, 000, 255, 255, 255, 000, 100, 100, // Left
000, 220, 000, 255, 255, 255, 255, 255, 255, 100, 100, 200, // Back
255, 255, 255, 255, 255, 255, 200, 000, 100, 000, 050, 200 // Top
};// Top
VBO_size_colours = sizeof(ccube);
int colours = sizeof(ccube)/sizeof(unsigned char);
unsigned char *ret = new unsigned char[colours];
for ( int i=0; i < colours; i++ ) {
ret[i] = ccube[i];
}
return ret;
}
float* Cube::getCoords() {
float tcube[] =
{ 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0,
0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0,
0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0
};
VBO_size_coords = sizeof(tcube);
int coords = sizeof(tcube)/sizeof(float);
float *ret = new float[coords];
for ( int i=0; i < coords; i++ ) {
ret[i] = tcube[i];
}
return ret;
}
vec3* Cube::getNormals() {
return NULL;
}