-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.cpp
More file actions
172 lines (146 loc) · 5.77 KB
/
Copy pathObject.cpp
File metadata and controls
172 lines (146 loc) · 5.77 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "Object.h"
#include <iostream>
using namespace std;
Object::Object(vec3 scal, vec3 rotat, vec3 pos, FigureType type) {
scale = scal;
rotation = rotat;
position = pos;
model = glm::mat4(1.0);
}
void Object::Initiate() {
//Cubo sin textura
/*GLfloat VertexBufferObject[] = {
//front
1.0f , 1.0f, -1.0f, 0.0f, 0.0f, -1.0f,
1.0f , -1.0f, -1.0f, 0.0f, 0.0f, -1.0f,
-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f,
-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f,
-1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f,
1.0f , 1.0f, -1.0f, 0.0f, 0.0f, -1.0f,
//back
-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f , -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f , 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f , 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
//left
-1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f,
//right
1.0f , -1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f , 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f , 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f , 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f , -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f , -1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
//down
-1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f,
1.0f , -1.0f, -1.0f, 0.0f, -1.0f, 0.0f,
1.0f , -1.0f, 1.0f, 0.0f, -1.0f, 0.0f,
1.0f , -1.0f, 1.0f, 0.0f, -1.0f, 0.0f,
-1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f,
//up
1.0f , 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
1.0f , 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
1.0f , 1.0f, 1.0f, 0.0f, 1.0f, 0.0f
};
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBindVertexArray(VAO);
//glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); //vao per pintar el plà i tot lo altre
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexBufferObject), VertexBufferObject, GL_STATIC_DRAW); // vao per pintar el cub
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GL_FLOAT), (GLvoid*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GL_FLOAT), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);*/
//Cubo con textura
GLfloat vertices[] = {
// Positions // Normals // Texture Coords
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1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First, set the container's VAO (and VBO)
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindVertexArray(VAO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
glEnableVertexAttribArray(2);
glBindVertexArray(0);
}
Object::~Object(){}
void Object::Draw() {
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
}
void Object::Move(vec3 translation) {
model = glm::translate(model, translation);
}
void Object::Rotate(vec3 rota) {
model = glm::rotate(model, glm::radians(rota.y), glm::vec3(0.0f, 1.f, 0.0f)); // matriu que controla rotació en Y
model = glm::rotate(model, glm::radians(rota.x), glm::vec3(1.0f, 0.f, 0.0f)); // matriu qu controla rotació en X
rot = rot1*rot2;
}
void Object::Scale(vec3 scal){
model = glm::scale(model, scal);
}
mat4 Object::GetModelMatrix() {
return model;
}
vec3 Object::GetPosition() {
return position;
}
void Object::Delete() {
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
}