-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissile.js
228 lines (182 loc) · 5.75 KB
/
missile.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// audio
let rocket_sound = new Audio('audio/RocketSound.mp3');
function changeCameraState(state) {
setIsLookAtCamera(state);
if (state) {
$("#free-view-help").slideUp();
setTimeout(function () {
$("#look-at-help").slideDown();
}, 500);
} else {
setTimeout(function () {
$("#free-view-help").slideDown();
}, 500);
$("#look-at-help").slideUp();
}
}
function changeLightColor() {
lightsColor[getLightType()] = getColorNumber($('#light-color').val())
}
function setAmbientLightColor() {
ambientLightColor = getColorNumber($('#ambient-color').val())
}
function setDiffuseColor() {
diffuseColor = getColorNumber($('#diffuse-color').val())
}
function setSpecularColor() {
specularColor = getColorNumber($('#specular-color').val())
}
function setAmbientMatColor() {
ambientMatColor = getColorNumber($('#ambient-mat-color').val())
}
function setSpecShine() {
SpecShine = $('#specular-shiny').val()
}
function changeLightPositionPoint() {
lightPositionX[getLightType()] = $("#point-light-position-x").val();
lightPositionY[getLightType()] = $("#point-light-position-y").val();
lightPositionZ[getLightType()] = $("#point-light-position-z").val();
}
function changeLightPositionDirect() {
lightDirPhi[getLightType()] = $("#direct-light-position-phi").val();
lightDirTheta[getLightType()] = $("#direct-light-position-theta").val();
}
let lastLightTypeSelected = 0;
function changeToDirectLight() {
$("#point-pane").slideUp();
setTimeout(function () {
$("#direct-pane").slideDown()
}, 500);
lastLightTypeSelected = 0;
if(getLightEnableStatus()) {
lightType[getLightType()] = [1, 0 , 0, 0];
} else {
lightType[getLightType()] = [0, 0 , 0, 0];
}
// lastLightType = [1, 0, 0, 0];
// getLightsArray();
}
function changeToPointLight() {
$("#direct-pane").slideUp();
setTimeout(function () {
$("#point-pane").slideDown()
}, 500);
lastLightTypeSelected = 1;
if(getLightEnableStatus()) {
lightType[getLightType()] = [0, 1 , 0, 0];
} else {
lightType[getLightType()] = [0, 0 , 0, 0];
}
// lastLightType = [0, 1, 0, 0];
// getLightsArray();
}
function changeLightDecay() {
lightDecay[getLightType()] = $("#light-decay").val();
}
function toggleAnimationState() {
if (!should_animate) {
if(animationIndex + 1 === frames.length) {
animationIndex = 0;
rocket_sound.currentTime = 0;
isFromAToB = !isFromAToB;
}
should_animate = true;
playAnimationChange();
} else {
should_animate = false;
pauseAnimationChange();
}
}
function resetAnimationState() {
if (should_animate) {
pauseAnimationChange();
}
should_animate = false;
animationIndex = 0;
rocket_sound.currentTime = 0;
rocket_sound.pause();
}
function playAnimationChange() {
$("#action-btn").removeClass("btn-success");
$("#action-btn").addClass("btn-danger");
$("#action-btn").html("Pause");
rocket_sound.play();
}
function pauseAnimationChange() {
$("#action-btn").removeClass("btn-danger");
$("#action-btn").addClass("btn-success");
$("#action-btn").html("Play");
rocket_sound.pause();
}
function triggerKeyPress(keyVal) {
$.event.trigger({type: 'keypress', key: keyVal});
}
function lightChange() {
// getLightsArray();
restoreLightParameters(getLightType())
}
function getLightType() {
return $("#light-selector").val();
}
function lightEnableChange() {
getLightsArray();
}
function getLightEnableStatus() {
return $("#enable-checkbox").prop("checked")
}
function setLightEnableState(state) {
$("#enable-checkbox").prop("checked", state)
}
function getLightsArray() {
if (getLightEnableStatus()) {
switch (lastLightTypeSelected) {
case 0:
lightType[getLightType()] = [1, 0, 0, 0];
break;
case 1:
lightType[getLightType()] = [0, 1, 0, 0];
break;
}
} else {
lightType[getLightType()] = [0, 0, 0, 0];
}
}
function getColorNumber(color) {
return color.substr(1);
}
function restoreLightParameters(lightNo) {
// restore the light color
$('#light-color').val(`#${lightsColor[lightNo]}`);
// direction of the point light
$("#point-light-position-x").val(lightPositionX[lightNo]);
$("#point-light-position-y").val(lightPositionY[lightNo]);
$("#point-light-position-z").val(lightPositionZ[lightNo]);
// fdecay of point light
$("#light-decay").val(lightDecay[lightNo]);
// direction of the direct light
$("#direct-light-position-phi").val(lightDirPhi[lightNo]);
$("#direct-light-position-theta").val(lightDirTheta[lightNo]);
// restore the enable checkbox and light type
console.log(lightNo, lightType[lightNo]);
if ((lightType[lightNo][0] + lightType[lightNo][1]) === 0) {
setLightEnableState(false);
} else if (lightType[lightNo][0] === 1) {
setLightEnableState(true);
if(lastLightTypeSelected === 1) {
changeToDirectLight();
$("#direct-light").prop("checked", true);
$("#direct-light").parent().addClass("active");
$("#point-light").prop("checked", false);
$("#point-light").parent().removeClass("active");
}
} else if (lightType[lightNo][1] === 1) {
setLightEnableState(true);
$("#direct-light").prop("checked", false);
$("#direct-light").parent().removeClass("active");
$("#point-light").prop("checked", true);
$("#point-light").parent().addClass("active");
if(lastLightTypeSelected === 0) {
changeToPointLight();
}
}
}