# HG changeset patch # User Eugen Sawin # Date 1302989671 -7200 # Node ID 98191d5d5af6223a38ae409f15a1503864327080 # Parent cf2ca81264fb8080181dbd2c76c14dedd4c44e54 Bugged camera. diff -r cf2ca81264fb -r 98191d5d5af6 scripts/machine.js --- a/scripts/machine.js Sat Apr 16 22:04:51 2011 +0200 +++ b/scripts/machine.js Sat Apr 16 23:34:31 2011 +0200 @@ -63,6 +63,10 @@ this.pitch = 0.0; this.yaw = 0.0; this.speed = speed; + this.rotMatrix = mat4.create(); + this.transMatrix = mat4.create(); + mat4.identity(this.rotMatrix); + mat4.identity(this.transMatrix); } Camera.prototype.moveLeft = function() { @@ -92,6 +96,21 @@ { this.yaw += this.speed.yaw * delta; } +Camera.prototype.update = function() +{ + mat4.rotate(this.rotMatrix, -this.pitch, [1, 0, 0]); + mat4.rotate(this.rotMatrix, -this.yaw, [0, 1, 0]); + mat4.translate(this.transMatrix, [-this.x, -this.y, -this.z]); + //mat4.multiply(this.matrix, newMatrix); + this.clear(); + //mat4.rotate(mvMatrix, -camera.pitch, [1, 0, 0]); + //mat4.rotate(mvMatrix, -camera.yaw, [0, 1, 0]); + //mat4.translate(mvMatrix, [-camera.x, -camera.y, -camera.z]); +} +Camera.prototype.clear = function() +{ + this.pitch = this.yaw = this.x = this.y = this.z = 0; +} function Controller(keyActionMap, mouseActionMap, camera, machine, renderer) { @@ -218,15 +237,16 @@ var mvMatrix = this.context.mvMatrix; var pMatrix = this.context.pMatrix; var camera = this.camera; + camera.update(); gl.viewport(0, 0, viewport.width, viewport.height); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); mat4.perspective(45, viewport.width / viewport.height, 0.1, 100.0, pMatrix); mat4.identity(mvMatrix); - mat4.rotate(mvMatrix, -camera.pitch, [1, 0, 0]); - mat4.rotate(mvMatrix, -camera.yaw, [0, 1, 0]); - mat4.translate(mvMatrix, [-camera.x, -camera.y, -camera.z]); + mat4.multiply(mvMatrix, camera.transMatrix); + mat4.multiply(mvMatrix, camera.rotMatrix); + this.pushMatrix(mvMatrix);