forked from yiming-cai/OursCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinate.cpp
More file actions
67 lines (58 loc) · 1.61 KB
/
Copy pathCoordinate.cpp
File metadata and controls
67 lines (58 loc) · 1.61 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
#include "Coordinate.h"
Coordinate::Coordinate(int id, int size)
{
this->id = id;
this->size = size;
this->shader = Shader_Coordinate;
this->toWorld = glm::mat4(1.0f);
len = (2 * size + 1) * 2 * 3 * 2;
lineV = new GLfloat[len];
int pos = 0;
for (int i = -size; i <= size; ++i) {
lineV[pos++] = i;
lineV[pos++] = GROUND_LEVEL;
lineV[pos++] = size;
lineV[pos++] = i;
lineV[pos++] = GROUND_LEVEL;
lineV[pos++] = -size;
}
for (int i = -size; i <= size; ++i) {
lineV[pos++] = -size;
lineV[pos++] = GROUND_LEVEL;
lineV[pos++] = i;
lineV[pos++] = size;
lineV[pos++] = GROUND_LEVEL;
lineV[pos++] = i;
}
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, len * sizeof(GLfloat), lineV, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glBindVertexArray(0);
printf("Coordinate Load!\n");
}
Coordinate::~Coordinate()
{
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
}
void Coordinate::draw(glm::mat4 C)
{
//printf("Coordinate draw!\n");
glUseProgram(shader);
glm::mat4 modelview = V * C * toWorld;
glm::vec3 temp = glm::vec3(lineV[3], lineV[4], lineV[5]);
uProjection = glGetUniformLocation(shader, "projection");
uModelview = glGetUniformLocation(shader, "modelview");
glUniformMatrix4fv(uProjection, 1, GL_FALSE, &P[0][0]);
glUniformMatrix4fv(uModelview, 1, GL_FALSE, &modelview[0][0]);
glBindVertexArray(VAO);
glDrawArrays(GL_LINES, 0, (2 * size + 1) * 4);
glBindVertexArray(0);
}
void Coordinate::update()
{
}