-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock.cpp
146 lines (117 loc) · 3.37 KB
/
rock.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "rock.h"
#include "main.h"
Rock::Rock(float x, float z) {
this->position = glm::vec3(x, -1, z);
this->rotation = 0;
speed = 1;
// Our vertices. Three consecutive floats give a 3D vertex; Three consecutive vertices give a triangle.
// A cube has 6 faces with 2 triangles each, so this makes 6*2=12 triangles, and 12*3 vertices
float a=0,b=0,c=0;
static const GLfloat vertex_buffer_data[] = {
-a,-b,-c, // triangle 1 : begin
-a,-b, c,
-a, b, c, // triangle 1 : end
a, b,-c, // triangle 2 : begin
-a,-b,-c,
-a, b,-c, // triangle 2 : end
a,-b, c,
-a,-b,-c,
a,-b,-c,
a, b,-c,
a,-b,-c,
-a,-b,-c,
-a,-b,-c,
-a, b, c,
-a, b,-c,
a,-b, c,
-a,-b, c,
-a,-b,-c,
-a, b, c,
-a,-b, c,
a,-b, c,
a, b, c,
a,-b,-c,
a, b,-c,
a,-b,-c,
a, b, c,
a,-b, c,
a, b, c,
a, b,-c,
-a, b,-c,
a, b, c,
-a, b,-c,
-a, b, c,
a, b, c,
-a, b, c,
a,-b, c
};
float len = 0.5;
static const GLfloat vertex_buffer_data1[] = {
-0.25,-0.25,-0.25, // triangle 1 : begin
-0.25,-0.25, 0.25,
-0.125, 0.25, 0.125, // triangle 1 : end
0.125, 0.25,-0.125, // triangle 2 : begin
-0.25,-0.25,-0.25,
-0.125, 0.25,-0.125, // triangle 2 : end
0.25,-0.25, 0.25,
-0.25,-0.25,-0.25,
0.25,-0.25,-0.25,
0.125, 0.25,-0.125,
0.25,-0.25,-0.25,
-0.25,-0.25,-0.25,
-0.25,-0.25,-0.25,
-0.125, 0.25, 0.125,
-0.125, 0.25,-0.125,
0.25,-0.25, 0.25,
-0.25,-0.25, 0.25,
-0.25,-0.25,-0.25,
-0.125, 0.25, 0.125,
-0.25,-0.25, 0.25,
0.25,-0.25, 0.25,
0.125, 0.25, 0.125,
0.25,-0.25,-0.25,
0.125, 0.25,-0.125,
0.25,-0.25,-0.25,
0.125, 0.25, 0.125,
0.25,-0.25, 0.25,
0.125, 0.25, 0.125,
0.125, 0.25,-0.125,
-0.125, 0.25,-0.125,
0.125, 0.25, 0.125,
-0.125, 0.25,-0.125,
-0.125, 0.25, 0.125,
0.125, 0.25, 0.125,
-0.125, 0.25, 0.125,
0.25,-0.25, 0.25
};
this->object = create3DObject(GL_TRIANGLES, 12*3, vertex_buffer_data1, COLOR_BLACK, GL_FILL);
}
void Rock::draw(glm::mat4 VP) {
Matrices.model = glm::mat4(1);
glm::mat4 translate = glm::translate (this->position); // glTranslatef
glm::mat4 rotate = glm::rotate((float) (this->rotation * M_PI / 180.0f), glm::vec3(1, 0, 0));
// No need as coords centered at 0, 0, 0 of cube arouund which we waant to rotate
// rotate = rotate * glm::translate(glm::vec3(0, -0.6, 0));
Matrices.model *= (translate * rotate);
glm::mat4 MVP = VP * Matrices.model;
glUniformMatrix4fv(Matrices.MatrixID, 1, GL_FALSE, &MVP[0][0]);
draw3DObject(this->object);
}
void Rock::set_position(float x, float y) {
this->position = glm::vec3(x, y, 0);
}
void Rock::tick(int is_wind, int dir) {
if(is_wind)
{
if(dir)
this->position.x -= 0.002;
else
this->position.x += 0.004;
this->position.z -= 0.002;
}
}
bounding_box_t Rock::bounding_box(){
float x = this->position.x, y = this->position.y , z = this->position.z;
bounding_box_t bbox = { x, y, z};
return bbox;
}