-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpotLight.h
More file actions
102 lines (92 loc) · 3.05 KB
/
Copy pathSpotLight.h
File metadata and controls
102 lines (92 loc) · 3.05 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
#ifndef spotLight_h
#define spotLight_h
#include <glad/glad.h>
#include <glm/glm.hpp>
#include "shader.h"
#include <iostream>
#include <string>
using namespace std;
class SpotLight {
public:
glm::vec3 position;
glm::vec3 ambient;
glm::vec3 diffuse;
glm::vec3 specular;
glm::vec3 direction;
float k_c;
float k_l;
float k_q;
float inner_circle;
float outer_circle;
int Number;
SpotLight(float posX, float posY, float posZ, float ambR, float ambG, float ambB, float diffR, float diffG, float diffB, float specR, float specG, float specB, float constant, float linear, float quadratic, int num, float in_circle, float out_circle, float dirX, float dirY, float dirZ) {
position = glm::vec3(posX, posY, posZ);
ambient = glm::vec3(ambR, ambG, ambB);
diffuse = glm::vec3(diffR, diffG, diffB);
specular = glm::vec3(specR, specG, specB);
k_c = constant;
k_l = linear;
k_q = quadratic;
inner_circle = in_circle;
outer_circle = out_circle;
direction = glm::vec3(dirX, dirY, dirZ);
Number = num - 1;
}
SpotLight() {
position = glm::vec3(0, 0, 0);
ambient = glm::vec3(1.0f, 1.0f, 1.0f);
diffuse = glm::vec3(1.0f, 1.0f, 1.0f);
specular = glm::vec3(1.0f, 1.0f, 1.0f);
k_c = 1.0f;
k_l = 0.09f;
k_q = 0.032f;
inner_circle = glm::cos(glm::radians(12.5f));
outer_circle = glm::cos(glm::radians(25.0f));
direction = glm::vec3(0, -1, 0);
Number = 1;
}
void setUpspotLight(Shader& lightingShader)
{
lightingShader.use();
string lightNumber = to_string(Number);
lightingShader.setVec3("spotLights[" + lightNumber + "].position", position);
lightingShader.setVec3("spotLights[" + lightNumber + "].ambient", ambient * ambientOn);
lightingShader.setVec3("spotLights[" + lightNumber + "].diffuse", diffuse * diffuseOn);
lightingShader.setVec3("spotLights[" + lightNumber + "].specular", specular * specularOn);
lightingShader.setFloat("spotLights[" + lightNumber + "].k_c", k_c);
lightingShader.setFloat("spotLights[" + lightNumber + "].k_l", k_l);
lightingShader.setFloat("spotLights[" + lightNumber + "].k_q", k_q);
lightingShader.setFloat("spotLights[" + lightNumber + "].inner_circle", inner_circle);
lightingShader.setFloat("spotLights[" + lightNumber + "].outer_circle", outer_circle);
lightingShader.setVec3("spotLights[" + lightNumber + "].direction", direction);
}
void turnOff()
{
ambientOn = 0.0;
diffuseOn = 0.0;
specularOn = 0.0;
}
void turnOn()
{
ambientOn = 1.0;
diffuseOn = 1.0;
specularOn = 1.0;
}
void turnAmbientOn()
{
ambientOn = 1.0;
}
void turnDiffuseOn()
{
diffuseOn = 1.0;
}
void turnSpecularOn()
{
specularOn = 1.0;
}
private:
float ambientOn = 1.0;
float diffuseOn = 1.0;
float specularOn = 1.0;
};
#endif /* spotLight_h */