Fixed scene graph positioning bug.
1 function Node(position, rotation, geometry)
5 this.geometry = geometry;
8 Node.prototype.update = function(time)
10 // this.right = [1, 0, 0];
11 // this.up = [0, 1, 0];
12 // this.target = [0, 0, -1];
13 // var x = vec3.dot([1, 0, 0], this.pos);
14 // var y = vec3.dot([0, 1, 0], this.pos);
15 // var z = vec3.dot([0, 0, -1], this.pos);
16 // this.matrix = mat4.create([this.right[0], this.up[0], -this.target[0], 0,
17 // this.right[1], this.up[1], -this.target[1], 0,
18 // this.right[2], this.up[2], -this.target[2], 0,
20 for (var id in this.children) this.children[id].update(time);
24 function Cube(size, context)
27 this.size = size || 1;
28 this.positionBuffer = gl.createBuffer();
29 gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
66 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
67 this.positionBuffer.itemSize = 3;
68 this.positionBuffer.numItems = 24;
70 this.normalBuffer = gl.createBuffer();
71 gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
72 var normals = [// font face
102 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(normals), gl.STATIC_DRAW);
103 this.normalBuffer.itemSize = 3;
104 this.normalBuffer.numItems = 24;
106 this.colourBuffer = gl.createBuffer();
107 gl.bindBuffer(gl.ARRAY_BUFFER, this.colourBuffer);
109 var uni = [1.0, 1.0, 1.0, alpha];
110 var colours = [[0.0, 0.0, 0.0, alpha],
111 [0.0, 0.0, 0.0, alpha],
112 [0.0, 0.0, 0.0, alpha],
113 [0.0, 0.0, 0.0, alpha],
114 [0.0, 0.0, 0.0, alpha],
115 [0.0, 0.0, 0.0, alpha]];
116 var unpackedColours = [];
117 for (var i in colours)
119 var colour = uni;//colours[i];
120 for (var j = 0; j < 4; j++)
122 unpackedColours = unpackedColours.concat(colour);
124 //colours = colours.concat([0.5, 0.5, 1.0, 1.0]);
126 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(unpackedColours), gl.STATIC_DRAW);
127 this.colourBuffer.itemSize = 4;
128 this.colourBuffer.numItems = 24;
130 this.indexBuffer = gl.createBuffer();
131 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
132 var indices = [0, 1, 2, 0, 2, 3,
135 12, 13, 14, 12, 14, 15,
136 16, 17, 18, 16, 18, 19,
137 20, 21, 22, 20, 22, 23];
138 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);
139 this.indexBuffer.itemSize = 1;
140 this.indexBuffer.numItems = 36;