var sg = sg || {};

sg.Scene = function(context, heightmap) {
  this.context = context;
  this.gl = this.context.gl;

  this.camera = new sg.cameras.Rotating(this.context, vec3.fromValues(0, -30, 0), 55);
  this.terrain = new sg.objects.Terrain(this.context, heightmap);
  this.train = new sg.objects.Train(this.context);
  this.track = new sg.objects.Track(this.context);

  this.gl.enable(this.gl.DEPTH_TEST);
};

sg.Scene.prototype.draw = function() {
  this.context.setGLViewport();
  this.gl.clearColor(0.7, 0.7, 1.0, 1.0);
  this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);

  this.context.shaders.basic.use();
  this.context.shaders.basic.setProjectionMatrix(this.camera.getProjection());
  this.context.shaders.basic.setViewMatrix(this.camera.getView());

  var modelMatrix = mat4.create();
  this.terrain.draw(modelMatrix);

  var trackMatrix = mat4.clone(modelMatrix);
  mat4.translate(trackMatrix, trackMatrix, vec3.fromValues(0, 0, -12));
  this.track.draw(trackMatrix);

  // var trainMatrix = mat4.clone(modelMatrix);
  // mat4.translate(trainMatrix, trainMatrix, vec3.fromValues(0, 0, -9));
  // mat4.rotateZ(trainMatrix, trainMatrix, Math.PI / 2);
  // mat4.scale(trainMatrix, trainMatrix, vec3.fromValues(0.2, 0.2, 0.2));
  // this.train.draw(trainMatrix);
};

sg.Scene.prototype.tick = function(delta) {
  this.camera.tick(delta);
};

sg.Scene.prototype.onMouseMovement = function(event) {
  this.camera.onMouseInput(event.movementX, event.movementY);
};


@@ -188,10 +188,8 @@
 (0, 
--3
 0, 0
@@ -995,19 +995,16 @@
 rix);%0A%0A 
- //
  var tra
@@ -1045,50 +1045,101 @@
 ;%0A  
-// mat4.translate(trainMatrix, trainMatrix
+var trainPosition = this.track.path.evaluate(0);%0A  vec3.subtract(trainPosition, trainPosition
 , ve
@@ -1162,18 +1162,75 @@
  0, 
--
 9
+.4
 ));%0A  
-//
+mat4.translate(trainMatrix, trainMatrix, trainPosition);%0A 
  mat
@@ -1280,19 +1280,16 @@
  / 2);%0A 
- //
  mat4.sc
@@ -1356,11 +1356,8 @@
 );%0A 
- //
  thi

Add proper train position