-
Notifications
You must be signed in to change notification settings - Fork 1
/
gears3d.js
66 lines (59 loc) · 1.39 KB
/
gears3d.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
/* Jordan Justen : gears3d is public domain */
var gl;
function init_webgl()
{
var canvas = document.getElementById("gears3d");
try {
gl = canvas.getContext("webgl");
} catch (e) {
try {
gl = canvas.getContext("experimental-webgl");
} catch (e) {
}
}
if (gl) {
gl.canvas_width = canvas.width;
gl.canvas_height = canvas.height;
} else {
alert("No WebGL!");
}
}
var drawer = webgl10;
var angle_per_dt = 70.0 / 180.0 * Math.PI / 1000.0;
var angle = 0.0;
var t0 = -1.0;
var frame_count = 0;
function draw_gears()
{
requestAnimFrame(draw_gears);
var t = Date.now();
if (t0 < 0.0)
t0 = t;
var dt = t - t0;
t0 = t;
angle += angle_per_dt * dt;
if (angle > 2 * Math.PI) {
angle -= 2 * Math.PI; /* prevents eventual overflow */
}
drawer.update_angle(angle);
drawer.draw();
if (frame_count % 3600 == 0) {
console.log("drew gears " + frame_count + " times!");
if (gl.getError() != gl.NO_ERROR) {
console.log("There was a WebGL error!");
}
}
frame_count += 1;
}
function gears3d_start()
{
init_webgl();
if (gl) {
drawer.set_global_state();
if (gl.getError() != gl.NO_ERROR) {
console.log("There was a WebGL error!");
}
start_time = Date.now();
draw_gears();
}
}