Esempio n. 1
0
WebGlBaseRenderer.prototype.renderTile = function(tile, texture, layer, layerZ) {

  var gl = this.gl;
  var shaderProgram = this.shaderProgram;
  var constantBuffers = this.constantBuffers;
  var vtMatrix = this.vtMatrix;
  var translateVector = this.translateVector;
  var scaleVector = this.scaleVector;

  translateVector[0] = tile.centerX();
  translateVector[1] = tile.centerY();
  translateVector[2] = -0.5;

  scaleVector[0] = tile.scaleX();
  scaleVector[1] = tile.scaleY();
  scaleVector[2] = 1;

  mat4.copy(vtMatrix, layer.view().projection());
  mat4.rotateX(vtMatrix, vtMatrix, tile.rotX());
  mat4.rotateY(vtMatrix, vtMatrix, tile.rotY());
  mat4.translate(vtMatrix, vtMatrix, translateVector);
  mat4.scale(vtMatrix, vtMatrix, scaleVector);

  gl.uniformMatrix4fv(shaderProgram.vtMatrix, false, vtMatrix);

  setDepth(gl, shaderProgram, layerZ, tile.z);

  setTexture(gl, shaderProgram, texture);

  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, constantBuffers.vertexIndices);
  gl.drawElements(gl.TRIANGLES, vertexIndices.length, gl.UNSIGNED_SHORT, 0);
};
Esempio n. 2
0
RectilinearView.prototype.projection = function() {

  var p = this._projectionMatrix;
  var f = this._viewFrustum;

  if (this._projectionChanged) {

    // Recalculate the projection matrix.

    var width = this._width;
    var height = this._height;

    var vfov = this._fov;
    var hfov = convertFov.vtoh(vfov, width, height);
    var aspect = width / height;

    var projectionCenterX = this._projectionCenterX;
    var projectionCenterY = this._projectionCenterY;

    if (projectionCenterX !== 0 || projectionCenterY !== 0) {
      var offsetAngleX = Math.atan(projectionCenterX * 2 * Math.tan(hfov/2));
      var offsetAngleY = Math.atan(projectionCenterY * 2 * Math.tan(vfov/2));
      var fovs = this._fovs;
      fovs.leftDegrees = (hfov/2 + offsetAngleX) * 180/Math.PI;
      fovs.rightDegrees = (hfov/2 - offsetAngleX) * 180/Math.PI;
      fovs.upDegrees = (vfov/2 + offsetAngleY) * 180/Math.PI;
      fovs.downDegrees = (vfov/2 - offsetAngleY) * 180/Math.PI;
      mat4.perspectiveFromFieldOfView(p, fovs, -1, 1);
    } else {
      mat4.perspective(p, vfov, aspect, -1, 1);
    }

    mat4.rotateZ(p, p, this._roll);
    mat4.rotateX(p, p, this._pitch);
    mat4.rotateY(p, p, this._yaw);

    // Extract frustum planes from projection matrix.
    // http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf

    vec4.set(f[0], p[3] + p[0], p[7] + p[4], p[11] + p[8],  0); // left
    vec4.set(f[1], p[3] - p[0], p[7] - p[4], p[11] - p[8],  0); // right
    vec4.set(f[2], p[3] + p[1], p[7] + p[5], p[11] + p[9],  0); // top
    vec4.set(f[3], p[3] - p[1], p[7] - p[5], p[11] - p[9],  0); // bottom
    vec4.set(f[4], p[3] + p[2], p[7] + p[6], p[11] + p[10], 0); // camera

    this._projectionChanged = false;
  }

  return p;

};
Esempio n. 3
0
// Rotate a vector around the coordinate axes in YXZ order.
function rotateVector(out, vec, y, x, z) {

  mat4.copy(matrix, identity);

  if (y) {
    mat4.rotateY(matrix, matrix, y);
  }

  if (x) {
    mat4.rotateX(matrix, matrix, x);
  }

  if (z) {
    mat4.rotateZ(matrix, matrix, z);
  }

  vec3.transformMat4(out, vec, matrix);

  return out;
}