Don't remember, must sleep.
authorEugen Sawin <sawine@me73.com>
Sat, 02 Apr 2011 01:42:19 +0200
changeset 8287fcb0e8f60
parent 7 12bb629d22b3
child 9 610eb11054aa
Don't remember, must sleep.
scripts/machine.js
     1.1 --- a/scripts/machine.js	Sat Apr 02 00:31:54 2011 +0200
     1.2 +++ b/scripts/machine.js	Sat Apr 02 01:42:19 2011 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  var machine;
     1.5 -var render;
     1.6 +var renderer;
     1.7  
     1.8  function main()
     1.9  {
    1.10 @@ -13,7 +13,7 @@
    1.11      gl.clearColor(0.0, 0.0, 0.0, 1.0);
    1.12      gl.enable(gl.DEPTH_TEST);
    1.13      machine = new Machine(object);
    1.14 -    render = new Render(context);    
    1.15 +    renderer = new Renderer(context);    
    1.16      update();
    1.17  }
    1.18  
    1.19 @@ -21,7 +21,8 @@
    1.20  {    
    1.21      requestAnimFrame(update);
    1.22      //machine.scene.rotation *= 1.003;
    1.23 -    render.draw(machine.scene);
    1.24 +    machine.update(new Date().getTime());
    1.25 +    renderer.update(machine.scene);
    1.26  }
    1.27  
    1.28  function resize()
    1.29 @@ -40,13 +41,13 @@
    1.30      context.viewport.height = height;
    1.31  }
    1.32  
    1.33 -function Render(context)
    1.34 +function Renderer(context)
    1.35  {
    1.36      this.context = context;
    1.37      this.gl = context.gl;
    1.38      this.matrixStack = [];
    1.39  }
    1.40 -Render.prototype.draw = function(scene)
    1.41 +Renderer.prototype.update = function(scene)
    1.42  { 
    1.43      var gl = this.context.gl;
    1.44      var viewport = this.context.viewport;
    1.45 @@ -79,13 +80,13 @@
    1.46  
    1.47      if (this.next) this.next.draw(scene);
    1.48  }
    1.49 -Render.prototype.pushMatrix = function(matrix)
    1.50 +Renderer.prototype.pushMatrix = function(matrix)
    1.51  {
    1.52      var copy = mat4.create();
    1.53      mat4.set(matrix, copy);
    1.54      this.matrixStack.push(copy);
    1.55  }
    1.56 -Render.prototype.popMatrix = function()    
    1.57 +Renderer.prototype.popMatrix = function()    
    1.58  {
    1.59      if (this.matrixStack.length > 0) return this.matrixStack.pop();
    1.60  }
    1.61 @@ -93,10 +94,16 @@
    1.62  function Machine(scene)
    1.63  {
    1.64      this.scene = scene;
    1.65 +    this.lastUpdate = 0;
    1.66  }
    1.67 -Machine.prototype.draw = function(render)
    1.68 +Machine.prototype.update = function(time)
    1.69  {
    1.70 -    render.draw(this.scene);
    1.71 +    if (this.lastUpdate != 0)
    1.72 +    {
    1.73 +	var diff = time - lastUpdate;
    1.74 +	
    1.75 +    }
    1.76 +    this.lastUpdate = time;
    1.77  }
    1.78  
    1.79  function Context(canvas)