-
Notifications
You must be signed in to change notification settings - Fork 0
/
Light.cpp
91 lines (69 loc) · 1.32 KB
/
Light.cpp
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
/*
* File: Light.h
* Author: kurtbradd
*
*/
#include "Light.h"
#include <stdio.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#endif
#include "structs.h"
// Constructor
Light::Light(int glLight, Param posIn, Param diffIn , Param specIn, Param ambIn) {
pos = posIn;
dif = diffIn;
spec = specIn;
amb = ambIn;
lightNum = glLight;
}
// Operators
void Light::enable() {
// Enable the light source and set its parameters
switch (lightNum) {
case 1:
glEnable(GL_LIGHT0);
break;
case 2:
glEnable(GL_LIGHT1);
case 3:
glEnable(GL_LIGHT2);
break;
}
glLightfv(lightNum, GL_POSITION, pos.arr);
glLightfv(lightNum, GL_AMBIENT, amb.arr);
glLightfv(lightNum, GL_DIFFUSE, dif.arr);
glLightfv(lightNum, GL_SPECULAR, spec.arr);
}
void Light::redrawLight() {
glLightfv(lightNum, GL_POSITION, pos.arr);
}
void Light::increaseX(int val) {
pos.arr[0] += val;
redrawLight();
}
void Light::decreaseX(int val) {
pos.arr[0] -= val;
redrawLight();
}
void Light::increaseY(int val) {
pos.arr[1] += val;
redrawLight();
}
void Light::decreaseY(int val) {
pos.arr[1] -= val;
redrawLight();
}
void Light::increaseZ(int val) {
pos.arr[2] += val;
redrawLight();
}
void Light::decreaseZ(int val) {
pos.arr[2] -= val;
redrawLight();
}