-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLight.cpp
More file actions
67 lines (59 loc) · 1.27 KB
/
Light.cpp
File metadata and controls
67 lines (59 loc) · 1.27 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 <windows.h>
#include <fstream>
#include "Light.h"
CLight::~CLight(void)
{
}
// Êîíñòðóêòîðû ñî ñïèñêîì ïàðàìåòðîâ
CLight::CLight(bool enabled, vec3 position)
{
this->isSpotLight = false;
this->enabled = enabled;
this->position[0] = position.x;
this->position[1] = position.y;
this->position[2] = position.z;
this->position[3] = 1;
this->color[0] = 0;
this->color[1] = 0;
this->color[2] = 0;
this->color[3] = 1;
this->CalculateDirectColor();
}
void CLight::CalculateDirectColor()
{
if (isSpotLight)
{
for (int i = 0; i < 3; i++)
this->directColor[i] = this->color[i]*2.5;
}
else
{
for (int i = 0; i < 3; i++)
this->directColor[i] = this->color[i];
}
this->directColor[3] = 1;
}
// Óñòàíîâêà íàïðàâëåíèÿ
void CLight::SetTarget(vec3 target)
{
this->isSpotLight = true;
this->target = target;
this->CalculateDirectColor();
}
// Óñòàíîâêà öâåòà
void CLight::SetColor(vec3 color)
{
this->color[0] = color.r;
this->color[1] = color.g;
this->color[2] = color.b;
this->color[3] = 1;
this->CalculateDirectColor();
}
// Ïðèìåíåíèå èñòî÷íèêà ñâåòà
void CLight::ApplyLight(void)
{
glLightfv(GL_LIGHT0,GL_AMBIENT, color);
glLightfv(GL_LIGHT0,GL_DIFFUSE, directColor);
glLightfv(GL_LIGHT0,GL_SPECULAR, directColor);
glLightfv(GL_LIGHT0,GL_POSITION, position);
}