update method

void update(
  1. dynamic camera
)

Implementation

void update(camera) {
  var cache = _cache;

  var needsUpdate = cache["focus"] != camera.focus ||
      cache["fov"] != camera.fov ||
      cache["aspect"] != camera.aspect * aspect ||
      cache["near"] != camera.near ||
      cache["far"] != camera.far ||
      cache["zoom"] != camera.zoom ||
      cache["eyeSep"] != eyeSep;

  if (needsUpdate) {
    cache["focus"] = camera.focus;
    cache["fov"] = camera.fov;
    cache["aspect"] = camera.aspect * aspect;
    cache["near"] = camera.near;
    cache["far"] = camera.far;
    cache["zoom"] = camera.zoom;
    cache["eyeSep"] = eyeSep;

    // Off-axis stereoscopic effect based on
    // http://paulbourke.net/stereographics/stereorender/

    _projectionMatrix.copy(camera.projectionMatrix);
    var eyeSepHalf = cache["eyeSep"] / 2;
    var eyeSepOnProjection = eyeSepHalf * cache["near"] / cache["focus"];
    var ymax = (cache["near"] * Math.tan(MathUtils.deg2rad * cache["fov"] * 0.5)) / cache["zoom"];
    var xmin, xmax;

    // translate xOffset

    _eyeLeft.elements[12] = -eyeSepHalf;
    _eyeRight.elements[12] = eyeSepHalf;

    // for left eye

    xmin = -ymax * cache["aspect"] + eyeSepOnProjection;
    xmax = ymax * cache["aspect"] + eyeSepOnProjection;

    _projectionMatrix.elements[0] = 2 * cache["near"] / (xmax - xmin);
    _projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);

    cameraL.projectionMatrix.copy(_projectionMatrix);

    // for right eye

    xmin = -ymax * cache["aspect"] - eyeSepOnProjection;
    xmax = ymax * cache["aspect"] - eyeSepOnProjection;

    _projectionMatrix.elements[0] = 2 * cache["near"] / (xmax - xmin);
    _projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);

    cameraR.projectionMatrix.copy(_projectionMatrix);
  }

  cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
}