|
|
@ -38,10 +38,15 @@
|
|
38
|
38
|
</script>
|
|
39
|
39
|
<script type="gl/fragment-shader">
|
|
40
|
40
|
precision mediump float;
|
|
|
41
|
uniform vec4 color;
|
|
41
|
42
|
varying vec3 world_pos;
|
|
42
|
43
|
|
|
43
|
44
|
void main() {
|
|
44
|
|
gl_FragColor = vec4(world_pos.x, world_pos.y, world_pos.z, 1);
|
|
|
45
|
if (color.x >= 0.0 && color.x <= 1.0) {
|
|
|
46
|
gl_FragColor = color;
|
|
|
47
|
} else {
|
|
|
48
|
gl_FragColor = vec4(world_pos.x, world_pos.y, world_pos.z, 1);
|
|
|
49
|
}
|
|
45
|
50
|
}
|
|
46
|
51
|
</script>
|
|
47
|
52
|
<script>
|
|
|
@ -242,7 +247,7 @@
|
|
242
|
247
|
return s;
|
|
243
|
248
|
}
|
|
244
|
249
|
|
|
245
|
|
trixl.debug.innerHTML = coord_html(pos[0]) + ", " + coord_html(pos[1]) + ", " + coord_html(pos[2]);
|
|
|
250
|
return coord_html(pos[0]) + ", " + coord_html(pos[1]) + ", " + coord_html(pos[2]);
|
|
246
|
251
|
}
|
|
247
|
252
|
var gl = trixl.gl = trixl.stage.getContext("webgl");
|
|
248
|
253
|
//gl.enable(gl.CULL_FACE);
|
|
|
@ -261,25 +266,45 @@
|
|
261
|
266
|
gl.enableVertexAttribArray(program.vertexPosAttrib);
|
|
262
|
267
|
gl.vertexAttribPointer(program.vertexPosBuffer, 3, gl.FLOAT, false, 0, 0);
|
|
263
|
268
|
|
|
|
269
|
program.color = gl.getUniformLocation(program, 'color');
|
|
|
270
|
gl.uniform4f(program.color, -1, -1, -1, -1);
|
|
|
271
|
|
|
264
|
272
|
var angle = {x: 0, y: 0, z: 0};
|
|
|
273
|
var offset = {x: 0, y: 0, z: 0};
|
|
265
|
274
|
program.transform = gl.getUniformLocation(program, 'transform');
|
|
266
|
275
|
trixl.redraw = function() {
|
|
267
|
|
var transform = matrix.multiplyMany4x4(
|
|
268
|
|
//matrix.identity(4), matrix.identity(4) /*
|
|
269
|
|
matrix.translate(-0.5, -0.5, -0.0),
|
|
270
|
|
matrix.scale(0.5, 0.5, 0.5),
|
|
271
|
|
matrix.rotateZ(angle.z / 4),
|
|
272
|
|
//matrix.rotateY(angle.y / 10),
|
|
273
|
|
matrix.rotateX(angle.x / 4),
|
|
274
|
|
//matrix.translate(-0.5, -0.5, 0),
|
|
275
|
|
//matrix.translate(-0.5, -0.5, -0.5),
|
|
276
|
|
matrix.translate(-0.0, -0.0, -0.1)
|
|
277
|
|
//matrix.perspective(Math.PI / 3, trixl.window.w / trixl.window.h, 0, 2000) //*/
|
|
278
|
|
);
|
|
279
|
|
trixl.debug_pos(matrix.multiply([1,1,1,1], [1, 4], transform, [4, 4]));
|
|
280
|
|
gl.uniformMatrix4fv(program.transform, false, transform);
|
|
|
276
|
var aspect = trixl.window.w / trixl.window.h;
|
|
|
277
|
var transform = function(pos) {
|
|
|
278
|
return matrix.multiplyMany4x4(
|
|
|
279
|
//matrix.scale(0.6, 0.6, 0.6),
|
|
|
280
|
matrix.translate(-0.5, -0.5, -0.5),
|
|
|
281
|
matrix.rotateZ(angle.z / 10),
|
|
|
282
|
//matrix.rotateY(angle.y / 10),
|
|
|
283
|
matrix.rotateX(angle.x / 10),
|
|
|
284
|
matrix.translate(pos[0] + offset.x, pos[1] + offset.y, pos[2] + offset.z),
|
|
|
285
|
[1, 0, 0, 0,
|
|
|
286
|
0, 1, 0, 0,
|
|
|
287
|
0, 0, 1, 1,
|
|
|
288
|
0, 0, 0, 1],
|
|
|
289
|
[Math.PI / 3 / aspect, 0, 0, 0,
|
|
|
290
|
0, Math.PI / 3, 0, 0,
|
|
|
291
|
0, 0, 1, 0,
|
|
|
292
|
0, 0, 0, 1]
|
|
|
293
|
);
|
|
|
294
|
}
|
|
|
295
|
var t = transform([0.0, 0.0, 2]);
|
|
|
296
|
trixl.debug.innerHTML = "";
|
|
|
297
|
[[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0],
|
|
|
298
|
[0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 1]].forEach(function(el) {
|
|
|
299
|
trixl.debug.innerHTML +=
|
|
|
300
|
trixl.debug_pos(matrix.multiply([el[0], el[1], el[2], 1], [1, 4], t, [4, 4]));
|
|
|
301
|
trixl.debug.innerHTML += "<br />";
|
|
|
302
|
});
|
|
281
|
303
|
|
|
282
|
304
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
|
305
|
|
|
|
306
|
gl.uniform4f(program.color, (Math.sin(angle.x) + 1.0) * 0.5, 0, 0, 1.0);
|
|
|
307
|
gl.uniformMatrix4fv(program.transform, false, t);
|
|
283
|
308
|
gl.drawArrays(gl.TRIANGLES, 0, 6 * 6);
|
|
284
|
309
|
|
|
285
|
310
|
angle.x += Math.PI / 10;
|