-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathescena_iluminada.cc
206 lines (169 loc) · 5.29 KB
/
escena_iluminada.cc
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*******************************************************************/
// David Vargas Carrillo
// Informatica Grafica - Practica 4
// Diciembre 2017
//
// Fichero: escena_iluminada.cc
// Declaraciones de los metodos de la clase EscenaIluminada
/*******************************************************************/
#include "escena_iluminada.h"
/*******************************************************************/
//
/*******************************************************************/
EscenaIluminada::EscenaIluminada() {
pos_x_actual = -15.0;
dir_x_actual = 1.0;
dir_z_actual = 0.0;
pos_adelante = true;
dir_adelante = true;
// Construccion de objetos
beethoven.LeerFigura("./read_ply/beethoven.ply");
beethoven.CalcularNormales();
// Construccion de la luz
// Luz 1 posicional
luz1.SetNumeroLuz(1);
luz1.SetPosicion(pos_x_actual, 20.0, 25.0);
luz1.SetColorAmbiente(0.2, 0.2, 0.2);
luz1.SetColorDifuso(0.2, 0.8, 1.0);
luz1.SetColorEspecular(1.0, 1.0, 1.0);
// Luz 2 direccional
luz2.SetNumeroLuz(2);
luz2.SetDireccion(dir_x_actual, 0.0, dir_x_actual);
luz2.SetColorAmbiente(0.2, 0.2, 0.2);
luz2.SetColorDifuso(1.0, 0.0, 1.0);
luz2.SetColorEspecular(1.0, 1.0, 1.0);
// Construccion de los materiales
material1 = new Material();
material2 = new Material();
material3 = new Material();
// Configuracion de cada uno de ellos
// La activacion de Emision y Ambiente impide que la figura
// refleje el color de la luz
material1->SetEmision(0.0, 0.0, 0.0);
material1->SetAmbiente(0.0, 0.0, 0.0);
material1->SetEspecular(0.8, 0.8, 0.8);
material1->SetBrillo(20);
material2->SetEmision(0.5, 0.5, 0.0);
material2->SetAmbiente(0.0, 0.0, 0.0);
material2->SetEspecular(0.5, 0.5, 0.5);
material2->SetBrillo(20);
material3->SetEmision(0.8, 0.8, 0.8);
material3->SetAmbiente(0.0, 0.0, 0.0);
material3->SetEspecular(0.5, 0.5, 0.5);
material3->SetBrillo(30);
// No se asigna ningun material por defecro
mat_seleccionado = 0;
estado = 1;
}
/*******************************************************************/
//
/*******************************************************************/
EscenaIluminada::~EscenaIluminada() {
if (material1 != NULL) delete[] material1;
if (material2 != NULL) delete[] material2;
if (material3 != NULL) delete[] material3;
material1 = NULL;
material2 = NULL;
material3 = NULL;
}
/*******************************************************************/
//
/*******************************************************************/
void EscenaIluminada::SetModoDibujado(char modo) {
beethoven.SetModoDibujado(modo);
}
/*******************************************************************/
//
/*******************************************************************/
void EscenaIluminada::DibujarEscena() {
glEnable(GL_NORMALIZE);
//glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
// glClearColor (0.0, 0.0, 0.0, 0.0);
// Activacion de las luces
if (estado == 1) {
luz1.Enable();
// luz1.DibujaPosicion();
luz2.Enable();
}
// Activacion del material
if (mat_seleccionado != 0)
beethoven.EnableMaterial();
// Dibujado de los objetos presentes en la escena
beethoven.Dibujar();
// Desactivacion de las luces
if (estado == 1) {
luz1.Disable();
luz2.Disable();
}
}
/*******************************************************************/
//
/*******************************************************************/
void EscenaIluminada::MoverLuz1() {
if (pos_adelante)
pos_x_actual += 1.0;
else
pos_x_actual -= 1.0;
if (pos_x_actual >= LIM_MIN_POSICION_LUZ)
pos_adelante = false;
else if (pos_x_actual <= LIM_MAX_POSICION_LUZ)
pos_adelante = true;
std::cout << "Posicion luz 1: " << pos_x_actual << std::endl;
luz1.SetPosicion(pos_x_actual, 20.0, 25.0);
}
/*******************************************************************/
//
/*******************************************************************/
void EscenaIluminada::MoverLuz2() {
if (dir_adelante) {
dir_x_actual -= 0.1;
dir_z_actual += 0.1;
} else {
dir_x_actual += 0.1;
dir_z_actual -= 0.1;
}
if (dir_x_actual <= LIM_MIN_DIRECCION_LUZ)
dir_adelante = false;
else if (dir_x_actual >= LIM_MAX_DIRECCION_LUZ)
dir_adelante = true;
std::cout << "Posicion luz 2: " << dir_x_actual;
std::cout << " " << dir_z_actual << std::endl;
luz2.SetDireccion(dir_x_actual, 0.0, dir_z_actual);
}
/*******************************************************************/
//
/*******************************************************************/
void EscenaIluminada::SetMaterial(int num) {
switch (num) {
case 0:
mat_seleccionado = 0;
break;
case 1:
mat_seleccionado = 1;
beethoven.SetMaterial(material1);
break;
case 2:
mat_seleccionado = 2;
beethoven.SetMaterial(material2);
break;
case 3:
mat_seleccionado = 3;
beethoven.SetMaterial(material3);
break;
default:
std::cout << "ERROR: material seleccionado invalido\n";
}
}
/*******************************************************************/
//
/*******************************************************************/
void EscenaIluminada::InterruptorLuces() {
(estado == 1) ? estado = 0 : estado = 1;
}
/*******************************************************************/
//
/*******************************************************************/
void EscenaIluminada::InterruptorSombreado() {
luz1.CambiarModoSombreado();
luz2.CambiarModoSombreado();
}