Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     /**
  3.      * creates a new reflection matrix about this plane.
  4.      */
  5.     export function createReflectionMatrix(plane: THREE.Plane) : THREE.Matrix4 {
  6.         var n = plane.normalize()
  7.         var m = new THREE.Matrix4()
  8.         return m.set(
  9.             -1.0 - 2.0 * n.normal.x * n.normal.x, // negated?
  10.             -2.0 * n.normal.x * n.normal.y,
  11.             -2.0 * n.normal.x * n.normal.z,
  12.              0.0,
  13.             -2.0 * n.normal.x * n.normal.y,
  14.              1.0 - 2.0 * n.normal.y * n.normal.y,
  15.             -2.0 * n.normal.y * n.normal.z,
  16.              0.0,
  17.             -2.0 * n.normal.z * n.normal.x,
  18.             -2.0 * n.normal.z * n.normal.y,
  19.              1.0 - 2.0 * n.normal.z * n.normal.z,
  20.              0.0,
  21.             -2.0 * n.constant * n.normal.x,
  22.             -2.0 * n.constant * n.normal.y,
  23.             -2.0 * n.constant * n.normal.z,
  24.              1.0); 
  25.     }
  26.  
  27.  
  28.     /**
  29.      * mirrors this camera about a plane.
  30.      * @param camera {THREE.Camera} the camera to mirror
  31.      * @param plane {THREE.Plane} the plane to mirror against.
  32.      * @returns {THREE.Camera} a new camera mirrored against this plane.
  33.      */
  34.     export function reflect(camera: THREE.PerspectiveCamera, plane: THREE.Plane) : THREE.Camera {
  35.         var reflect = camera.clone()
  36.         plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0)
  37.         reflect.matrixAutoUpdate = false;
  38.         reflect.matrix.identity()
  39.         reflect.matrix.multiply(acid.graphics.math.createReflectionMatrix(plane))
  40.         reflect.matrix.multiply(camera.matrix)
  41.         reflect.updateProjectionMatrix();
  42.         reflect.updateMatrixWorld(true);
  43.         return reflect;
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement