Bugged camera.
1.1 --- a/scripts/machine.js Sat Apr 16 22:04:51 2011 +0200
1.2 +++ b/scripts/machine.js Sat Apr 16 23:34:31 2011 +0200
1.3 @@ -63,6 +63,10 @@
1.4 this.pitch = 0.0;
1.5 this.yaw = 0.0;
1.6 this.speed = speed;
1.7 + this.rotMatrix = mat4.create();
1.8 + this.transMatrix = mat4.create();
1.9 + mat4.identity(this.rotMatrix);
1.10 + mat4.identity(this.transMatrix);
1.11 }
1.12 Camera.prototype.moveLeft = function()
1.13 {
1.14 @@ -92,6 +96,21 @@
1.15 {
1.16 this.yaw += this.speed.yaw * delta;
1.17 }
1.18 +Camera.prototype.update = function()
1.19 +{
1.20 + mat4.rotate(this.rotMatrix, -this.pitch, [1, 0, 0]);
1.21 + mat4.rotate(this.rotMatrix, -this.yaw, [0, 1, 0]);
1.22 + mat4.translate(this.transMatrix, [-this.x, -this.y, -this.z]);
1.23 + //mat4.multiply(this.matrix, newMatrix);
1.24 + this.clear();
1.25 + //mat4.rotate(mvMatrix, -camera.pitch, [1, 0, 0]);
1.26 + //mat4.rotate(mvMatrix, -camera.yaw, [0, 1, 0]);
1.27 + //mat4.translate(mvMatrix, [-camera.x, -camera.y, -camera.z]);
1.28 +}
1.29 +Camera.prototype.clear = function()
1.30 +{
1.31 + this.pitch = this.yaw = this.x = this.y = this.z = 0;
1.32 +}
1.33
1.34 function Controller(keyActionMap, mouseActionMap, camera, machine, renderer)
1.35 {
1.36 @@ -218,15 +237,16 @@
1.37 var mvMatrix = this.context.mvMatrix;
1.38 var pMatrix = this.context.pMatrix;
1.39 var camera = this.camera;
1.40 + camera.update();
1.41
1.42 gl.viewport(0, 0, viewport.width, viewport.height);
1.43 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
1.44 mat4.perspective(45, viewport.width / viewport.height, 0.1, 100.0, pMatrix);
1.45
1.46 mat4.identity(mvMatrix);
1.47 - mat4.rotate(mvMatrix, -camera.pitch, [1, 0, 0]);
1.48 - mat4.rotate(mvMatrix, -camera.yaw, [0, 1, 0]);
1.49 - mat4.translate(mvMatrix, [-camera.x, -camera.y, -camera.z]);
1.50 + mat4.multiply(mvMatrix, camera.transMatrix);
1.51 + mat4.multiply(mvMatrix, camera.rotMatrix);
1.52 +
1.53
1.54 this.pushMatrix(mvMatrix);
1.55