Camera almost fine.
1.1 --- a/scripts/machine.js Thu Apr 21 13:59:39 2011 +0200
1.2 +++ b/scripts/machine.js Fri Apr 22 02:04:04 2011 +0200
1.3 @@ -21,7 +21,7 @@
1.4 gl.clearColor(0.0, 0.0, 0.0, 1.0);
1.5 gl.enable(gl.DEPTH_TEST);
1.6 machine = new Machine(object);
1.7 - camera = new Camera(cameraSpeed);
1.8 + camera = new Camera(cameraSpeed, [0, 5, 20]);
1.9 renderer = new Renderer(camera, context);
1.10 controller = new Controller(keyActionMap, mouseActionMap, camera, machine, renderer);
1.11 update();
1.12 @@ -55,13 +55,19 @@
1.13 return (min + Math.random() * (max - min));
1.14 }
1.15
1.16 -function Camera(speed)
1.17 +function normalize(vectors)
1.18 +{
1.19 + for (var v in vectors) vec3.normalize(v);
1.20 +}
1.21 +
1.22 +function Camera(speed, pos, up, right, target)
1.23 {
1.24 this.speed = speed;
1.25 - this.pos = vec3.create([0, 0, 7]);
1.26 - this.up = vec3.create([0, 1, 0]);
1.27 - this.right = vec3.create([1, 0, 0]);
1.28 - this.target = vec3.create([0, 0, -1]);
1.29 + this.pos = vec3.create(pos || [0, 0, 7]);
1.30 + this.up = vec3.create(up || [0, 1, 0]);
1.31 + this.right = vec3.create(right || [1, 0, 0]);
1.32 + this.target = vec3.create(target || [0, 0, -1]);
1.33 + normalize([this.up, this.right, this.target]);
1.34 this.matrix = mat4.create();
1.35 }
1.36 Camera.prototype.moveLeft = function()
1.37 @@ -103,7 +109,6 @@
1.38 vec3.normalize(this.target);
1.39 vec3.cross(this.target, this.right, this.up);
1.40 vec3.scale(this.up, -1);
1.41 - vec3.normalize(this.up);
1.42 }
1.43 Camera.prototype.yaw = function(delta)
1.44 {
1.45 @@ -114,7 +119,6 @@
1.46 vec3.normalize(this.right);
1.47 vec3.cross(this.right, this.up, this.target);
1.48 vec3.scale(this.target, -1);
1.49 - vec3.normalize(this.target);
1.50 }
1.51 Camera.prototype.roll = function(delta)
1.52 {
1.53 @@ -128,13 +132,7 @@
1.54 this.matrix = mat4.create([this.right[0], this.up[0], -this.target[0], 0,
1.55 this.right[1], this.up[1], -this.target[1], 0,
1.56 this.right[2], this.up[2], -this.target[2], 0,
1.57 - -x, -y, z, 1]);
1.58 -
1.59 -}
1.60 -Camera.prototype.clear = function()
1.61 -{
1.62 - //this.x = this.y = this.z = 0;
1.63 - //this.pitch = this.yaw = 0;
1.64 + -x, -y, z, 1]);
1.65 }
1.66
1.67 function Controller(keyActionMap, mouseActionMap, camera, machine, renderer)