Slightly better zoom.
authorEugen Sawin <sawine@me73.com>
Sun, 17 Apr 2011 14:44:11 +0200
changeset 178b187fa957ad
parent 16 fba447c2485c
child 18 92eb274bc564
Slightly better zoom.
scripts/machine.js
     1.1 --- a/scripts/machine.js	Sun Apr 17 01:27:49 2011 +0200
     1.2 +++ b/scripts/machine.js	Sun Apr 17 14:44:11 2011 +0200
     1.3 @@ -88,7 +88,8 @@
     1.4  }
     1.5  Camera.prototype.zoom = function(delta) 
     1.6  {
     1.7 -    this.z += this.speed.z * delta;
     1.8 +    this.x += this.speed.x * delta * Math.sin(this.yaw);
     1.9 +    this.z += this.speed.z * delta * Math.cos(this.yaw);
    1.10  }
    1.11  Camera.prototype.changePitch = function(delta)
    1.12  {
    1.13 @@ -115,7 +116,7 @@
    1.14  }
    1.15  Camera.prototype.clear = function()
    1.16  {
    1.17 -   this.x = this.y = this.z = 0;
    1.18 +    //this.x = this.y = this.z = 0;
    1.19     //this.pitch = this.yaw = 0;
    1.20  }
    1.21  
    1.22 @@ -248,24 +249,25 @@
    1.23  
    1.24      gl.viewport(0, 0, viewport.width, viewport.height);
    1.25      gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    1.26 -    mat4.perspective(45, viewport.width / viewport.height, 0.1, 100.0, pMatrix);
    1.27 +    mat4.perspective(55, viewport.width / viewport.height, 0.1, 100.0, pMatrix);
    1.28  
    1.29      mat4.identity(mvMatrix);
    1.30      //mat4.multiply(mvMatrix, camera.rotMatrix);
    1.31      //mat4.multiply(mvMatrix, camera.transMatrix);
    1.32      mat4.rotate(mvMatrix, -camera.pitch, [1, 0, 0]);
    1.33      mat4.rotate(mvMatrix, -camera.yaw, [0, 1, 0]);
    1.34 -    mat4.multiply(mvMatrix, camera.matrix);
    1.35 +    mat4.translate(mvMatrix, [-camera.x, -camera.y, -camera.z]);
    1.36 +    //mat4.multiply(mvMatrix, camera.matrix);
    1.37      //mat4.rotate(camera.matrix, -camera.pitch, [1, 0, 0]);
    1.38      //mat4.rotate(camera.matrix, -camera.yaw, [0, 1, 0]);
    1.39      //camera.yaw = camera.pitch = 0;
    1.40     
    1.41      
    1.42 -    this.pushMatrix(mvMatrix);
    1.43 +    //this.pushMatrix(mvMatrix);
    1.44  
    1.45 -    mat4.rotate(mvMatrix, scene.rotation.x, [1, 0, 0]);
    1.46 -    mat4.rotate(mvMatrix, scene.rotation.y, [0, 1, 0]);
    1.47 -    mat4.rotate(mvMatrix, scene.rotation.z, [0, 0, 1]);
    1.48 +    //mat4.rotate(mvMatrix, scene.rotation.x, [1, 0, 0]);
    1.49 +    //mat4.rotate(mvMatrix, scene.rotation.y, [0, 1, 0]);
    1.50 +    //mat4.rotate(mvMatrix, scene.rotation.z, [0, 0, 1]);
    1.51  
    1.52      gl.bindBuffer(gl.ARRAY_BUFFER, scene.positionBuffer);
    1.53      gl.vertexAttribPointer(shader.vertexPosition, scene.positionBuffer.itemSize, gl.FLOAT, false, 0, 0);
    1.54 @@ -274,11 +276,12 @@
    1.55      gl.vertexAttribPointer(shader.vertexColour, scene.colourBuffer.itemSize, gl.FLOAT, false, 0, 0);
    1.56      
    1.57      gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, scene.indexBuffer);
    1.58 +
    1.59      this.context.updateMatrixUniforms();
    1.60      gl.drawElements(gl.TRIANGLES, scene.indexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
    1.61      //gl.drawArrays(gl.TRIANGLE_STRIP, 0, scene.positionBuffer.numItems);
    1.62      
    1.63 -    mvMatrix = this.popMatrix();
    1.64 +    //mvMatrix = this.popMatrix();
    1.65  
    1.66      if (this.next) this.next.draw(scene);
    1.67  }