This repository has been archived by the owner on Dec 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightSources.js
179 lines (133 loc) · 3.62 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//////////////////////////////////////////////////////////////////////////////
//
// A class for instantiating light sources.
//
// J. Madeira - Oct. 2015 + November 2017
//
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
//
// Constructor
//
function LightSource( ) {
// A new light source is always on
this.isOn = true;
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;
// Rotation speed factor - Allow different speeds
this. rotationSpeed = 1.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;
}
LightSource.prototype.isRotXXOn = function() {
return this.rotXXOn;
}
LightSource.prototype.switchRotXXOn = function() {
this.rotXXOn = true;
}
LightSource.prototype.switchRotXXOff = function() {
this.rotXXOn = false;
}
LightSource.prototype.getRotAngleXX = function() {
return this.rotAngleXX;
}
LightSource.prototype.setRotAngleXX = function( angle ) {
this.rotAngleXX = angle;
}
LightSource.prototype.isRotZZOn = function() {
return this.rotZZOn;
}
LightSource.prototype.switchRotZZOn = function() {
this.rotZZOn = true;
}
LightSource.prototype.switchRotZZOff = function() {
this.rotZZOn = false;
}
LightSource.prototype.getRotAngleZZ = function() {
return this.rotAngleZZ;
}
LightSource.prototype.setRotAngleZZ = function( angle ) {
this.rotAngleZZ = angle;
}
LightSource.prototype.getRotationSpeed = function() {
return this.rotationSpeed;
}
LightSource.prototype.setRotationSpeed = function( s ) {
this.rotationSpeed = s;
}
//----------------------------------------------------------------------------
//
// Instantiating light sources
//
var lightSources = [];
// Light on top right position
lightSources.push( new LightSource() );
lightSources[0].setPosition( -1.0, 1.0, 2.5, 0.0 );
// Light on top left position
lightSources.push( new LightSource() );
lightSources[0].setPosition( 1.0, 1.0, 2.5, 0.0 );