-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiluminacion.cpp
More file actions
137 lines (123 loc) · 7.64 KB
/
iluminacion.cpp
File metadata and controls
137 lines (123 loc) · 7.64 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
#include "iluminacion.hpp"
using namespace std;
using namespace ed;
namespace ed{
void ListaIluminacion::IniciarIluminacion()
{
unsigned int i;
int j, k;
for(i = 0, j = 0, k = 0; i < _focos.size(); i++, j = j + 3, k = k + 4)
{
_LightPosition[j] = _focos[i].getPosicion().getX(); _LightPosition[j + 1] = _focos[i].getPosicion().getY(); _LightPosition[j + 2] = _focos[i].getPosicion().getZ();
_LightColor[k] = _focos[i].getColor()[0]; _LightColor[k + 1] = _focos[i].getColor()[1]; _LightColor[k + 2] = _focos[i].getColor()[2]; _LightColor[k + 3] = 0;
}
}
void ListaIluminacion::IluminarEscena()
{
GLfloat ambiente[4];
GLfloat difusa[4];
GLfloat especular[4];
GLfloat posicion[4];
if(_focos.size() >= 1)
{
ambiente[0] = _focos[0].getAmbiente().getX(); ambiente[1] = _focos[0].getAmbiente().getY(); ambiente[2] = _focos[0].getAmbiente().getZ(); ambiente[3] = 1;
difusa[0] = _focos[0].getDifusa().getX(); difusa[1] = _focos[0].getDifusa().getY(); difusa[2] = _focos[0].getDifusa().getZ(); difusa[3] = 1;
especular[0] = _focos[0].getEspecular().getX(); especular[1] = _focos[0].getEspecular().getY(); especular[2] = _focos[0].getEspecular().getZ(); especular[3] = 1;
posicion[0] = _focos[0].getPosicion().getX(); posicion[1] = _focos[0].getPosicion().getY(); posicion[2] = _focos[0].getPosicion().getZ(); posicion[3] = 0;
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambiente);
glLightfv(GL_LIGHT0, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT0, GL_SPECULAR, especular);
glLightfv(GL_LIGHT0, GL_POSITION, posicion);
}
if(_focos.size() >= 2)
{
ambiente[0] = _focos[1].getAmbiente().getX(); ambiente[1] = _focos[1].getAmbiente().getY(); ambiente[2] = _focos[1].getAmbiente().getZ(); ambiente[3] = 1;
difusa[0] = _focos[1].getDifusa().getX(); difusa[1] = _focos[1].getDifusa().getY(); difusa[2] = _focos[1].getDifusa().getZ(); difusa[3] = 1;
especular[0] = _focos[1].getEspecular().getX(); especular[1] = _focos[1].getEspecular().getY(); especular[2] = _focos[1].getEspecular().getZ(); especular[3] = 1;
posicion[0] = _focos[1].getPosicion().getX(); posicion[1] = _focos[1].getPosicion().getY(); posicion[2] = _focos[1].getPosicion().getZ(); posicion[3] = 0;
glEnable(GL_LIGHT1);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambiente);
glLightfv(GL_LIGHT1, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT1, GL_SPECULAR, especular);
glLightfv(GL_LIGHT1, GL_POSITION, posicion);
}
if(_focos.size() >= 3)
{
ambiente[0] = _focos[2].getAmbiente().getX(); ambiente[1] = _focos[2].getAmbiente().getY(); ambiente[2] = _focos[2].getAmbiente().getZ(); ambiente[3] = 1;
difusa[0] = _focos[2].getDifusa().getX(); difusa[1] = _focos[2].getDifusa().getY(); difusa[2] = _focos[2].getDifusa().getZ(); difusa[3] = 1;
especular[0] = _focos[2].getEspecular().getX(); especular[1] = _focos[2].getEspecular().getY(); especular[2] = _focos[2].getEspecular().getZ(); especular[3] = 1;
posicion[0] = _focos[2].getPosicion().getX(); posicion[1] = _focos[2].getPosicion().getY(); posicion[2] = _focos[2].getPosicion().getZ(); posicion[3] = 0;
glEnable(GL_LIGHT2);
glLightfv(GL_LIGHT2, GL_AMBIENT, ambiente);
glLightfv(GL_LIGHT2, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT2, GL_SPECULAR, especular);
glLightfv(GL_LIGHT2, GL_POSITION, posicion);
}
if(_focos.size() >= 4)
{
ambiente[0] = _focos[3].getAmbiente().getX(); ambiente[1] = _focos[3].getAmbiente().getY(); ambiente[2] = _focos[3].getAmbiente().getZ(); ambiente[3] = 1;
difusa[0] = _focos[3].getDifusa().getX(); difusa[1] = _focos[3].getDifusa().getY(); difusa[2] = _focos[3].getDifusa().getZ(); difusa[3] = 1;
especular[0] = _focos[3].getEspecular().getX(); especular[1] = _focos[3].getEspecular().getY(); especular[2] = _focos[3].getEspecular().getZ(); especular[3] = 1;
posicion[0] = _focos[3].getPosicion().getX(); posicion[1] = _focos[3].getPosicion().getY(); posicion[2] = _focos[3].getPosicion().getZ(); posicion[3] = 0;
glEnable(GL_LIGHT3);
glLightfv(GL_LIGHT3, GL_AMBIENT, ambiente);
glLightfv(GL_LIGHT3, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT3, GL_SPECULAR, especular);
glLightfv(GL_LIGHT3, GL_POSITION, posicion);
}
if(_focos.size() >= 5)
{
ambiente[0] = _focos[4].getAmbiente().getX(); ambiente[1] = _focos[4].getAmbiente().getY(); ambiente[2] = _focos[4].getAmbiente().getZ(); ambiente[3] = 1;
difusa[0] = _focos[4].getDifusa().getX(); difusa[1] = _focos[4].getDifusa().getY(); difusa[2] = _focos[4].getDifusa().getZ(); difusa[3] = 1;
especular[0] = _focos[4].getEspecular().getX(); especular[1] = _focos[4].getEspecular().getY(); especular[2] = _focos[4].getEspecular().getZ(); especular[3] = 1;
posicion[0] = _focos[4].getPosicion().getX(); posicion[1] = _focos[4].getPosicion().getY(); posicion[2] = _focos[4].getPosicion().getZ(); posicion[3] = 0;
glEnable(GL_LIGHT4);
glLightfv(GL_LIGHT4, GL_AMBIENT, ambiente);
glLightfv(GL_LIGHT4, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT4, GL_SPECULAR, especular);
glLightfv(GL_LIGHT4, GL_POSITION, posicion);
}
if(_focos.size() >= 6)
{
ambiente[0] = _focos[5].getAmbiente().getX(); ambiente[1] = _focos[5].getAmbiente().getY(); ambiente[2] = _focos[5].getAmbiente().getZ(); ambiente[3] = 1;
difusa[0] = _focos[5].getDifusa().getX(); difusa[1] = _focos[5].getDifusa().getY(); difusa[2] = _focos[5].getDifusa().getZ(); difusa[3] = 1;
especular[0] = _focos[5].getEspecular().getX(); especular[1] = _focos[5].getEspecular().getY(); especular[2] = _focos[5].getEspecular().getZ(); especular[3] = 1;
posicion[0] = _focos[5].getPosicion().getX(); posicion[1] = _focos[5].getPosicion().getY(); posicion[2] = _focos[5].getPosicion().getZ(); posicion[3] = 0;
glEnable(GL_LIGHT5);
glLightfv(GL_LIGHT5, GL_AMBIENT, ambiente);
glLightfv(GL_LIGHT5, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT5, GL_SPECULAR, especular);
glLightfv(GL_LIGHT5, GL_POSITION, posicion);
}
if(_focos.size() >= 7)
{
ambiente[0] = _focos[6].getAmbiente().getX(); ambiente[1] = _focos[6].getAmbiente().getY(); ambiente[2] = _focos[6].getAmbiente().getZ(); ambiente[3] = 1;
difusa[0] = _focos[6].getDifusa().getX(); difusa[1] = _focos[6].getDifusa().getY(); difusa[2] = _focos[6].getDifusa().getZ(); difusa[3] = 1;
especular[0] = _focos[6].getEspecular().getX(); especular[1] = _focos[6].getEspecular().getY(); especular[2] = _focos[6].getEspecular().getZ(); especular[3] = 1;
posicion[0] = _focos[6].getPosicion().getX(); posicion[1] = _focos[6].getPosicion().getY(); posicion[2] = _focos[6].getPosicion().getZ(); posicion[3] = 0;
glEnable(GL_LIGHT6);
glLightfv(GL_LIGHT6, GL_AMBIENT, ambiente);
glLightfv(GL_LIGHT6, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT6, GL_SPECULAR, especular);
glLightfv(GL_LIGHT6, GL_POSITION, posicion);
}
if(_focos.size() == 8)
{
ambiente[0] = _focos[7].getAmbiente().getX(); ambiente[1] = _focos[7].getAmbiente().getY(); ambiente[2] = _focos[7].getAmbiente().getZ(); ambiente[3] = 1;
difusa[0] = _focos[7].getDifusa().getX(); difusa[1] = _focos[7].getDifusa().getY(); difusa[2] = _focos[7].getDifusa().getZ(); difusa[3] = 1;
especular[0] = _focos[7].getEspecular().getX(); especular[1] = _focos[7].getEspecular().getY(); especular[2] = _focos[7].getEspecular().getZ(); especular[3] = 1;
posicion[0] = _focos[7].getPosicion().getX(); posicion[1] = _focos[7].getPosicion().getY(); posicion[2] = _focos[7].getPosicion().getZ(); posicion[3] = 0;
glEnable(GL_LIGHT7);
glLightfv(GL_LIGHT7, GL_AMBIENT, ambiente);
glLightfv(GL_LIGHT7, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT7, GL_SPECULAR, especular);
glLightfv(GL_LIGHT7, GL_POSITION, posicion);
}
}
void ListaIluminacion::InsertarFoco(Iluminacion foco)
{
if(_focos.size() <= 7)
_focos.push_back(foco);
}
}