Repository navigation
Expand file tree
/
Copy pathColoredMultiObject.js
More file actions
524 lines (437 loc) · 18.3 KB
/
Copy pathColoredMultiObject.js
File metadata and controls
524 lines (437 loc) · 18.3 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_
// (JT: why the numbers? counts columns, helps me keep 80-char-wide listings)
//
// Chapter 5: ColoredTriangle.js (c) 2012 matsuda AND
// Chapter 4: RotatingTriangle_withButtons.js (c) 2012 matsuda
// became:
//
// ColoredMultiObject.js MODIFIED for EECS 351-1,
// Northwestern Univ. Jack Tumblin
// --converted from 2D to 4D (x,y,z,w) vertices
// --demonstrate how to keep & use MULTIPLE colored shapes in just one
// Vertex Buffer Object(VBO).
// --demonstrate 'nodes' vs. 'vertices'; geometric corner locations where
// OpenGL/WebGL requires multiple co-located vertices to implement the
// meeting point of multiple diverse faces.
//
// Vertex shader program----------------------------------
var VSHADER_SOURCE =
'uniform mat4 u_ModelMatrix;\n' +
'attribute vec4 a_Position;\n' +
'attribute vec4 a_Color;\n' +
'varying vec4 v_Color;\n' +
'void main() {\n' +
' gl_Position = u_ModelMatrix * a_Position;\n' +
' gl_PointSize = 1.0;\n' +
' v_Color = a_Color;\n' +
'}\n';
// Fragment shader program----------------------------------
var FSHADER_SOURCE =
'#ifdef GL_ES\n' +
'precision mediump float;\n' +
'#endif GL_ES\n' +
'varying vec4 v_Color;\n' +
'void main() {\n' +
' gl_FragColor = v_Color;\n' +
'}\n';
// Global Variable -- Rotation angle rate (degrees/second)
var ANGLE_STEP = 45.0;
var FizzyText = function()
{
this.message = "Twisted Snake";
this.twist = 90;
this.stop = false;
this.SpinUp = spinUp;
this.SpinDown = spinDown;
}
function main() {
//============================================================================
// Retrieve <canvas> element
var text = new FizzyText();
var gui = new dat.GUI({autoPlace:true});
gui.add(text,"message");
var twist_controller = gui.add(text,"twist",0,180);
var stop_control = gui.add(text,"stop");
gui.add(text,"SpinUp");
gui.add(text,"SpinDown");
var twist_angle = text.twist;
twist_controller.onChange(function(value)
{
twist_angle = value;
document.getElementById("Info").innerHTML = "Twist Angle = "+value;
})
stop_control.onChange(function(value)
{
if(value)
{
myTmp = ANGLE_STEP;
ANGLE_STEP = 0;
}
else
{
ANGLE_STEP = myTmp;
}
}
);
document.getElementById("Info").innerHTML = "Twist Angle = 90";
var canvas = document.getElementById('webgl');
// Get the rendering context for WebGL
var gl = getWebGLContext(canvas);
if (!gl) {
console.log('Failed to get the rendering context for WebGL');
return;
}
// Initialize shaders
if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {
console.log('Failed to intialize shaders.');
return;
}
//
var n = initVertexBuffer(gl);
if (n < 0) {
console.log('Failed to set the vertex information');
return;
}
// Specify the color for clearing <canvas>
gl.clearColor(0.0, 0.0, 0.0, 1.0);
// NEW!! Enable 3D depth-test when drawing: don't over-draw at any pixel
// unless the new Z value is closer to the eye than the old one..
// gl.depthFunc(gl.LESS);
gl.enable(gl.DEPTH_TEST);
// Get handle to graphics system's storage location of u_ModelMatrix
var u_ModelMatrix = gl.getUniformLocation(gl.program, 'u_ModelMatrix');
if (!u_ModelMatrix) {
console.log('Failed to get the storage location of u_ModelMatrix');
return;
}
// Create a local version of our model matrix in JavaScript
var modelMatrix = new Matrix4();
// Create, init current rotation angle value in JavaScript
var currentAngle = 0.0;
//-----------------
//Start drawing: create 'tick' variable whose value is this function:
var tick = function() {
currentAngle = animate(currentAngle); // Update the rotation angle
draw(gl, n, currentAngle, modelMatrix, u_ModelMatrix,twist_angle); // Draw shapes
requestAnimationFrame(tick, canvas);
// Request that the browser re-draw the webpage
};
tick(); // start (and continue) animation: draw current image
//draw(gl, n, currentAngle, modelMatrix, u_ModelMatrix);
}
function initVertexBuffer(gl) {
//==============================================================================
var c30 = Math.sqrt(0.75); // == cos(30deg) == sqrt(3) / 2
var sq2 = Math.sqrt(2.0);
var s60 = Math.sin(Math.PI/3);
var len = 0.2;//0.6*s60;
var z = 0.05;
//console.log(len);
var colorShapes = new Float32Array(
[
-len,0, z,1.0, 1.0,1.0,1.0, //Node 0
len,0, z, 1.0, 1.0,0.0,0.0, //Node 1
0,len, z,1.0, 0.0,1.0,1.0, //Node 2
//
0,len, z,1.0, 0.0,1.0,1.0, //Node 2
0.2,0.0, z, 1.0, 1.0,0.0,0.0, //Node 1
0.2,0.0, -z, 1.0, 1.0,0.0,0.0, //Node 4
//0.0,len, -0.3,1.0, 0.0,0.1,1.0,// Node 5
//
0.2,0.0, -z, 1.0, 1.0,0.0,0.0, //Node 4
0.0,len, -z,1.0, 0.0,0.1,1.0,// Node 5
0,len, z,1.0, 0.0,1.0,1.0, //Node 2
//
//
-0.2,0.0, -z, 1.0, 1.0,1.0,1.0, //Node 3
0.0,len, -z,1.0, 0.0,0.1,1.0,// Node 5
0.2,0.0, -z, 1.0, 1.0,0.0,0.0, //Node 4
//0.3,0.3, -0.3, 1.0, 1.0,0.0,0.0, //Node 4
//
-0.2,0.0, -z, 1.0, 1.0,1.0,1.0, //Node 3
0,len, z,1.0, 0.0,1.0,1.0, //Node 2
0.0,len, -z,1.0, 0.0,0.1,1.0,// Node 5
//
//
-0.2,0.0, z,1.0, 1.0,1.0,1.0, //Node 0
0,len, z,1.0, 0.0,1.0,1.0, //Node 2
-0.2,0.0, -z, 1.0, 1.0,1.0,1.0, //Node 3
//-0.3,0.3, -0.3, 1.0, 1.0,1.0,1.0,
//0.3,0.3, -0.3, 1.0, 1.0,0.0,0.0,
//0.0,len, -0.3,1.0, 0.0,0.1,1.0,
//
//0.3,-0.3, 0.0, 1.0, 0.5,0.2,0.3,
//0.3,0.3, 0.0,1.0, 1.0,0.0,0.0,
//len, 0.0,0.0,1.0, 0,0.0,1.0,1.0,
//
//
//
//
//
//0.3,-0.3, -0.3, 1.0, 0.5,0.2,0.3,
//0.3,0.3, -0.3,1.0, 1.0,0.0,0.0,
//len, 0.0,-0.3,1.0, 0,0.0,1.0,1.0,
]
);
var nn = 18;
// var colorShapes = new Float32Array([
// // Vertex coordinates(x,y,z,w) and color (R,G,B) for a color tetrahedron:
// // Apex on +z axis; equilateral triangle base at z=0
///* Nodes:
// 0.0, 0.0, sq2, 1.0, 1.0, 1.0, 1.0, // Node 0 (apex, +z axis; white)
// c30, -0.5, 0.0, 1.0, 0.0, 0.0, 1.0, // Node 1 (base: lower rt; red)
// 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, // Node 2 (base: +y axis; grn)
// -c30, -0.5, 0.0, 1.0, 0.0, 1.0, 0.0, // Node 3 (base:lower lft; blue)
//
//*/
// // Face 0: (left side)
// 0.0, 0.0, sq2, 1.0, 1.0, 1.0, 1.0, // Node 0
// c30, -0.5, 0.0, 1.0, 0.0, 0.0, 1.0, // Node 1
// 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, // Node 2
// // Face 1: (right side)
// 0.0, 0.0, sq2, 1.0, 1.0, 1.0, 1.0, // Node 0
// 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, // Node 2
// -c30, -0.5, 0.0, 1.0, 0.0, 1.0, 0.0, // Node 3
// // Face 2: (lower side)
// 0.0, 0.0, sq2, 1.0, 1.0, 1.0, 1.0, // Node 0
// -c30, -0.5, 0.0, 1.0, 0.0, 1.0, 0.0, // Node 3
// c30, -0.5, 0.0, 1.0, 0.0, 0.0, 1.0, // Node 1
// // Face 3: (base side)
// -c30, -0.5, -0.2, 1.0, 0.0, 1.0, 0.0, // Node 3
// 0.0, 1.0, -0.2, 1.0, 1.0, 0.0, 0.0, // Node 2
// c30, -0.5, -0.2, 1.0, 0.0, 0.0, 1.0, // Node 1
//
///* // Cube Nodes
// -1.0, -1.0, -1.0, 1.0 // Node 0
// -1.0, 1.0, -1.0, 1.0 // Node 1
// 1.0, 1.0, -1.0, 1.0 // Node 2
// 1.0, -1.0, -1.0, 1.0 // Node 3
//
// 1.0, 1.0, 1.0, 1.0 // Node 4
// -1.0, 1.0, 1.0, 1.0 // Node 5
// -1.0, -1.0, 1.0, 1.0 // Node 6
// 1.0, -1.0, 1.0, 1.0 // Node 7
//*/
// // +x face: RED
// 1.0, -1.0, -1.0, 1.0, 1.0, 0.0, 0.0, // Node 3
// 1.0, 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, // Node 2
// 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, // Node 4
//
// 1.0, 1.0, 1.0, 1.0, 1.0, 0.1, 0.1, // Node 4
// 1.0, -1.0, 1.0, 1.0, 1.0, 0.1, 0.1, // Node 7
// 1.0, -1.0, -1.0, 1.0, 1.0, 0.1, 0.1, // Node 3
//
// // +y face: GREEN
// -1.0, 1.0, -1.0, 1.0, 0.0, 1.0, 0.0, // Node 1
// -1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, // Node 5
// 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, // Node 4
//
// 1.0, 1.0, 1.0, 1.0, 0.1, 1.0, 0.1, // Node 4
// 1.0, 1.0, -1.0, 1.0, 0.1, 1.0, 0.1, // Node 2
// -1.0, 1.0, -1.0, 1.0, 0.1, 1.0, 0.1, // Node 1
//
// // +z face: BLUE
// -1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, // Node 5
// -1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, // Node 6
// 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, // Node 7
//
// 1.0, -1.0, 1.0, 1.0, 0.1, 0.1, 1.0, // Node 7
// 1.0, 1.0, 1.0, 1.0, 0.1, 0.1, 1.0, // Node 4
// -1.0, 1.0, 1.0, 1.0, 0.1, 0.1, 1.0, // Node 5
//
// // -x face: CYAN
// -1.0, -1.0, 1.0, 1.0, 0.0, 1.0, 1.0, // Node 6
// -1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, // Node 5
// -1.0, 1.0, -1.0, 1.0, 0.0, 1.0, 1.0, // Node 1
//
// -1.0, 1.0, -1.0, 1.0, 0.1, 1.0, 1.0, // Node 1
// -1.0, -1.0, -1.0, 1.0, 0.1, 1.0, 1.0, // Node 0
// -1.0, -1.0, 1.0, 1.0, 0.1, 1.0, 1.0, // Node 6
//
// // -y face: MAGENTA
// 1.0, -1.0, -1.0, 1.0, 1.0, 0.0, 1.0, // Node 3
// 1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 1.0, // Node 7
// -1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 1.0, // Node 6
//
// -1.0, -1.0, 1.0, 1.0, 1.0, 0.1, 1.0, // Node 6
// -1.0, -1.0, -1.0, 1.0, 1.0, 0.1, 1.0, // Node 0
// 1.0, -1.0, -1.0, 1.0, 1.0, 0.1, 1.0, // Node 3
//
// // -z face: YELLOW
// 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 0.0, // Node 2
// 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 0.0, // Node 3
// -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 0.0, // Node 0
//
// -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 0.1, // Node 0
// -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 0.1, // Node 1
// 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 0.1, // Node 2
//
// ]);
// var nn = 48; // 12 tetrahedron vertices; 36 cube verts (6 per side*6 sides)
// Create a buffer object
var shapeBufferHandle = gl.createBuffer();
if (!shapeBufferHandle) {
console.log('Failed to create the shape buffer object');
return false;
}
// Bind the the buffer object to target:
gl.bindBuffer(gl.ARRAY_BUFFER, shapeBufferHandle);
// Transfer data from Javascript array colorShapes to Graphics system VBO
// (Use sparingly--may be slow if you transfer large shapes stored in files)
gl.bufferData(gl.ARRAY_BUFFER, colorShapes, gl.STATIC_DRAW);
var FSIZE = colorShapes.BYTES_PER_ELEMENT; // how many bytes per stored value?
//Get graphics system's handle for our Vertex Shader's position-input variable:
var a_Position = gl.getAttribLocation(gl.program, 'a_Position');
if (a_Position < 0) {
console.log('Failed to get the storage location of a_Position');
return -1;
}
// Use handle to specify how to retrieve position data from our VBO:
gl.vertexAttribPointer(
a_Position, // choose Vertex Shader attribute to fill with data
4, // how many values? 1,2,3 or 4. (we're using x,y,z,w)
gl.FLOAT, // data type for each value: usually gl.FLOAT
false, // did we supply fixed-point data AND it needs normalizing?
FSIZE * 7, // Stride -- how many bytes used to store each vertex?
// (x,y,z,w, r,g,b) * bytes/value
0); // Offset -- now many bytes from START of buffer to the
// value we will actually use?
gl.enableVertexAttribArray(a_Position);
// Enable assignment of vertex buffer object's position data
// Get graphics system's handle for our Vertex Shader's color-input variable;
var a_Color = gl.getAttribLocation(gl.program, 'a_Color');
if(a_Color < 0) {
console.log('Failed to get the storage location of a_Color');
return -1;
}
// Use handle to specify how to retrieve color data from our VBO:
gl.vertexAttribPointer(
a_Color, // choose Vertex Shader attribute to fill with data
3, // how many values? 1,2,3 or 4. (we're using R,G,B)
gl.FLOAT, // data type for each value: usually gl.FLOAT
false, // did we supply fixed-point data AND it needs normalizing?
FSIZE * 7, // Stride -- how many bytes used to store each vertex?
// (x,y,z,w, r,g,b) * bytes/value
FSIZE * 4); // Offset -- how many bytes from START of buffer to the
// value we will actually use? Need to skip over x,y,z,w
gl.enableVertexAttribArray(a_Color);
// Enable assignment of vertex buffer object's position data
//--------------------------------DONE!
// Unbind the buffer object
gl.bindBuffer(gl.ARRAY_BUFFER, null);
return nn;
}
function draw(gl, n, currentAngle, modelMatrix, u_ModelMatrix, twist_angle) {
//==============================================================================
//var offset = Math.sin(Math.PI/3)*0.6;
var offset = 0.21;
// Clear <canvas> colors AND the depth buffer
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
//-------Draw Spinning Tetrahedron
modelMatrix.setRotate(currentAngle,0,0,1); // 'set' means DISCARD old matrix,
// (drawing axes centered in CVV), and then make new
// drawing axes moved to the lower-left corner of CVV.
//modelMatrix.scale(1,1,-1); // convert to left-handed coord sys
// to match WebGL display canvas.
//modelMatrix.scale(0.5, 0.5, 0.5);
// if you DON'T scale, tetra goes outside the CVV; clipped!
//modelMatrix.rotate(currentAngle, 1, 0, 0); // Make new drawing axes that
//modelMatrix.rotate(-currentAngle,1,0,0);
//modelMatrix.setIdentity();
modelMatrix.rotate(currentAngle+twist_angle, 1, 0, 0); // Make new drawing axes that
modelMatrix.translate(0.0,offset, 0.0); // 'set' means DISCARD old matrix,
//modelMatrix.rotate(currentAngle,0,0 ,1);
//modelMatrix.rotate(20.0, 0,1,0);
// that spin around y axis (0,1,0) of the previous
// drawing axes, using the same origin.
// DRAW TETRA: Use this matrix to transform & draw
// the first set of vertices stored in our VBO:
// Pass our current matrix to the vertex shaders:
gl.uniformMatrix4fv(u_ModelMatrix, false, modelMatrix.elements);
// Draw just the first set of vertices: start at vertex 0...
gl.drawArrays(gl.TRIANGLES, 0, n);
//modelMatrix.rotate(90,0,0,1);
//modelMatrix.setIdentity();
//return;
modelMatrix.rotate(currentAngle+twist_angle, 1, 0, 0); // Make new drawing axes that
modelMatrix.translate(offset,-offset,0);
modelMatrix.rotate(-90,0,0,1);
//modelMatrix.translate(0.0,offset,0.0)
//modelMatrix.scale(0.5, 0.5, 0.5);
//modelMatrix.rotate(currentAngle, 1, 0, 0); // Make new drawing axes that
//modelMatrix.rotate(currentAngle-90, 1, 0, 1); // Make new drawing axes that
//modelMatrix.translate(-offset,0, 0.0); // 'set' means DISCARD old matrix,
//modelMatrix.rotate(90-currentAngle,0,0 ,1);
gl.uniformMatrix4fv(u_ModelMatrix, false, modelMatrix.elements);
gl.drawArrays(gl.TRIANGLES, 0, n);
//modelMatrix.setTranslate(0,0,0);
//modelMatrix.setRotate(-180,0,0,1);
modelMatrix.rotate(currentAngle+twist_angle, 1, 0, 0); // Make new drawing axes that
modelMatrix.translate(offset,-offset,0);
//modelMatrix.rotate(currentAngle, 1, 0, 0); // Make new drawing axes that
//modelMatrix.translate(0.0,0.0, 0.0); // 'set' means DISCARD old matrix,
modelMatrix.rotate(-90, 0, 0, 1); // Make new drawing axes that
//modelMatrix.rotate(-currentAngle,0,0 ,1);
gl.uniformMatrix4fv(u_ModelMatrix, false, modelMatrix.elements);
gl.drawArrays(gl.TRIANGLES, 0, n);
//return;
//modelMatrix.setTranslate(0,0,0);
//modelMatrix.setRotate(90,0,0,1);
modelMatrix.rotate(currentAngle+twist_angle, 1, 0, 0); // Make new drawing axes that
modelMatrix.translate(offset,-offset,0);
modelMatrix.rotate(-90,0,0,1);
//modelMatrix.rotate(currentAngle, 1, 0, 0); // Make new drawing axes that
//modelMatrix.translate(0.0,0.0, 0.0); // 'set' means DISCARD old matrix,
//modelMatrix.rotate(currentAngle, 0, 0, 1); // Make new drawing axes that
//modelMatrix.rotate(currentAngle, 1, 0, 1); // Make new drawing axes that
//modelMatrix.rotate(90+currentAngle,0,0 ,1);
gl.uniformMatrix4fv(u_ModelMatrix, false, modelMatrix.elements);
gl.drawArrays(gl.TRIANGLES, 0, n);
//gl.drawArrays(gl.TRIANGLES, 3, 3);
//gl.drawArrays(gl.TRIANGLES, 6, 3);
// NEXT, create different drawing axes, and...
//modelMatrix.setTranslate(0.4, 0.4, 0.0); // 'set' means DISCARD old matrix,
//// (drawing axes centered in CVV), and then make new
//// drawing axes moved to the lower-left corner of CVV.
//modelMatrix.scale(1,1,-1); // convert to left-handed coord sys
//// to match WebGL display canvas.
//modelMatrix.scale(0.3, 0.3, 0.3);
//// Make it smaller:
//modelMatrix.rotate(currentAngle, 1, 1, 0); // Spin on XY diagonal axis
//// DRAW CUBE: Use ths matrix to transform & draw
//// the second set of vertices stored in our VBO:
//gl.uniformMatrix4fv(u_ModelMatrix, false, modelMatrix.elements);
//// Draw just the first set of vertices: start at vertex SHAPE_0_SIZE
//gl.drawArrays(gl.TRIANGLES, 12,36);
}
// Last time that this function was called: (used for animation timing)
var g_last = Date.now();
function animate(angle) {
//==============================================================================
// Calculate the elapsed time
var now = Date.now();
var elapsed = now - g_last;
g_last = now;
// Update the current rotation angle (adjusted by the elapsed time)
// limit the angle to move smoothly between +20 and -85 degrees:
// if(angle > 120.0 && ANGLE_STEP > 0) ANGLE_STEP = -ANGLE_STEP;
// if(angle < -120.0 && ANGLE_STEP < 0) ANGLE_STEP = -ANGLE_STEP;
var newAngle = angle + (ANGLE_STEP * elapsed) / 1000.0;
return newAngle %= 360;
}
//==================HTML Button Callbacks
function spinUp() {
ANGLE_STEP += 25;
}
function spinDown() {
ANGLE_STEP -= 25;
}
function runStop() {
if(ANGLE_STEP*ANGLE_STEP > 1) {
myTmp = ANGLE_STEP;
ANGLE_STEP = 0;
}
else {
ANGLE_STEP = myTmp;
}
}