Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 72 lines (63 sloc) 1.723 kb
e98d9b5 @emoller Version one of the tutorials, this is what was used when recording the v...
authored
1 <!DOCTYPE html>
2 <html>
3 <canvas id='c' width='900' height='900'></canvas>
4 <script src='webgl-utils.js'></script>
5 <script src='mesh.js'></script>
6 <script src='vector-math.js'></script>
7 <script>
8 var c = document.getElementById('c');
9 var gl = c.getContext('experimental-webgl');
10 gl.enable(gl.DEPTH_TEST);
11 gl.clearColor(0,0,0,1);
12
13 function DAGNode(ch) {
14 this.local = new Matrix4x3();
15 this.children = ch ? ch : [];
16 }
17
18 DAGNode.prototype = {
19 draw : function() {
20 pushModelMatrix().multiply(this.local);
21 for (var c in this.children) {
22 this.children[c].draw();
23 }
24 popModelMatrix();
25 }
26 };
27
28 function Geometry(mesh) {
29 this.mesh = mesh;
30 }
31
32 Geometry.prototype = {
33 draw : function() {
34 this.mesh.draw();
35 }
36 };
37
38 Geometry.prototype.prototype = DAGNode.prototype;
39
40 var mesh = new Mesh();
41 var z = 0;
42 var rot = new Matrix4x3();
43 var camera = new Matrix4x3();
44
45 var spinNode = new DAGNode([new Geometry(mesh)]);
46 var children = [];
47 for (var x = -2; x <= 2; x += 2) {
48 for (var y = -2; y <= 2; y += 2) {
49 var newNode = new DAGNode([spinNode]);
50 newNode.local.d[12] = x;
51 newNode.local.d[13] = y;
52 children[children.length] = newNode;
53 }
54 }
55 var scene = new DAGNode(children);
56
57 function draw() {
58 requestAnimationFrame(draw, c);
59 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
60 spinNode.local.makeRotate(z,1,0,0);
61 spinNode.local.multiply(rot.makeRotate(z,0,1,0));
62 spinNode.local.multiply(rot.makeRotate(z,0,0,1));
63 scene.local.makeRotate(z,0,1,0);
64 camera.d[14] = 8 + Math.sin(z);
65 viewMatrix().makeInverseRigidBody(camera);
66 scene.draw();
67 z += 0.01;
68 }
69
70 mesh.load('meshes/marine.json', draw);
71 </script>
72 </html>
Something went wrong with that request. Please try again.