-
Notifications
You must be signed in to change notification settings - Fork 1
/
lightSources.js
166 lines (96 loc) · 2.68 KB
/
lightSources.js
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
//////////////////////////////////////////////////////////////////////////////
//
// A class for instantiating light sources.
//
// J. Madeira - Oct. 2015
//
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
//
// Constructor
//
function LightSource( ) {
// A new light source is always on
this.isOn = true;
// And is directional
this.position = [ 0.0, 0.0, 1.0, 0.0 ];
// White light
this.intensity = [ 1.0, 1.0, 1.0 ];
// Ambient component
this.ambientIntensity = [ 0.2, 0.2, 0.2 ];
// Animation controls
this.rotXXOn = false;
this.rotYYOn = false;
this.rotZZOn = false;
// Rotation angles
this.rotAngleXX = 0.0;
this.rotAngleYY = 0.0;
this.rotAngleZZ = 0.0;
}
//----------------------------------------------------------------------------
//
// Methods
//
LightSource.prototype.isOff = function() {
return this.isOn == false;
}
LightSource.prototype.switchOn = function() {
this.isOn = true;
}
LightSource.prototype.switchOff = function() {
this.isOn = false;
}
LightSource.prototype.isDirectional = function() {
return this.position[3] == 0.0;
}
LightSource.prototype.getPosition = function() {
return this.position;
}
LightSource.prototype.setPosition = function( x, y, z, w ) {
this.position[0] = x;
this.position[1] = y;
this.position[2] = z;
this.position[3] = w;
}
LightSource.prototype.getIntensity = function() {
return this.intensity;
}
LightSource.prototype.setIntensity = function( r, g, b ) {
this.intensity[0] = r;
this.intensity[1] = g;
this.intensity[2] = b;
}
LightSource.prototype.getAmbIntensity = function() {
return this.ambientIntensity;
}
LightSource.prototype.setAmbIntensity = function( r, g, b ) {
this.ambientIntensity[0] = r;
this.ambientIntensity[1] = g;
this.ambientIntensity[2] = b;
}
LightSource.prototype.isRotYYOn = function() {
return this.rotYYOn;
}
LightSource.prototype.switchRotYYOn = function() {
this.rotYYOn = true;
}
LightSource.prototype.switchRotYYOff = function() {
this.rotYYOn = false;
}
LightSource.prototype.getRotAngleYY = function() {
return this.rotAngleYY;
}
LightSource.prototype.setRotAngleYY = function( angle) {
this.rotAngleYY = angle;
}
// COMPLETE THE MISSING METHODS !!
//----------------------------------------------------------------------------
//
// Instantiating light sources
//
var lightSources = [];
// Light source 0
lightSources.push( new LightSource() );
lightSources[0].setPosition( 0.0, 0.0, 1.0, 0.0 );
lightSources[0].setIntensity( 1.0, 1.0, 1.0 );
lightSources[0].setAmbIntensity( 0.2, 0.2, 0.2 );