Browse Source

Core performance improvements through shared props

Old Vector and Matrix constructor functions would create all methods and
make assignments with each call. A lot of speed-ups can be made by using
shared properties through the prototype chain. Since methods and
initialized properties are shared among all instances they're only
created once.

Some tests can be seen at examples/performance-test.html

Some results:

    Chrome

    //6.4 times faster
    performance-test.html:25 Vector2 x 5000000: 213ms
    performance-test.html:30 Vector2Orig x 5000000: 1366ms

    //8.3 times faster
    performance-test.html:37 Vector3 x 5000000: 241ms
    performance-test.html:42 Vector3Orig x 5000000: 2015ms

    //3.8 times faster
    performance-test.html:49 Vector4 x 5000000: 278ms
    performance-test.html:54 Vector4Orig x 5000000: 1059ms

    //7.5 times faster
    performance-test.html:61 Matrix4 x 5000000: 937ms
    performance-test.html:66 Matrix4Orig x 5000000: 7004ms

    Firefox

    //6.8 times faster
    Vector2 x 50000: 45ms
    Vector2Orig x 50000: 307ms

    //11.5 times faster
    Vector3 x 50000: 48ms
    Vector3Orig x 50000: 550ms

    //3.8 times faster
    Vector4 x 50000: 61ms
    Vector4Orig x 50000: 234ms

    //9.4 times faster
    Matrix4 x 50000: 199ms
    Matrix4Orig x 50000: 1878ms

where "Orig" are old versions of the objects.

Running these tests multiple times can yeild different results due to
browser cache. However the results are always kind of similar in terms
of speedup.
philogb 15 years ago
parent
commit
2b0ea54a4c

File diff suppressed because it is too large
+ 0 - 0
build/three.js


+ 72 - 0
examples/performance-test.html

@@ -0,0 +1,72 @@
+<!DOCTYPE HTML>
+<html lang="en">
+  <head>
+    <title>Performance Tests</title>
+    <script type="text/javascript" src="../src/Three.js"></script>
+    <script type="text/javascript" src="../src/core/Vector2.js"></script>
+    <script type="text/javascript" src="../src/core/Vector3.js"></script>
+    <script type="text/javascript" src="../src/core/Vector4.js"></script>
+    <script type="text/javascript" src="../src/core/Matrix3.js"></script>
+    <script type="text/javascript" src="../src/core/Matrix4.js"></script>
+    <script type="text/javascript" src="../src/core/Vector2.old.js"></script>
+    <script type="text/javascript" src="../src/core/Vector3.old.js"></script>
+    <script type="text/javascript" src="../src/core/Vector4.old.js"></script>
+    <script type="text/javascript" src="../src/core/Matrix3.old.js"></script>
+    <script type="text/javascript" src="../src/core/Matrix4.old.js"></script>
+    <script type="text/javascript">
+    function initTest() {
+      alert("hello");
+      var times = 50000;
+      //Vector2
+      console.time("Vector2 x " + times);
+      for( var i = 0; i < times; ++i) {
+        var v = new THREE.Vector2();
+      }
+      console.timeEnd("Vector2 x " + times);
+      console.time("Vector2Orig x " + times);
+      for( var i = 0; i < times; ++i) {
+        var v = new THREE.Vector2Orig();
+      }
+      console.timeEnd("Vector2Orig x " + times);
+
+      //Vector3
+      console.time("Vector3 x " + times);
+      for( var i = 0; i < times; ++i) {
+        var v = new THREE.Vector3();
+      }
+      console.timeEnd("Vector3 x " + times);
+      console.time("Vector3Orig x " + times);
+      for( var i = 0; i < times; ++i) {
+        var v = new THREE.Vector3Orig();
+      }
+      console.timeEnd("Vector3Orig x " + times);
+
+      //Vector4
+      console.time("Vector4 x " + times);
+      for( var i = 0; i < times; ++i) {
+        var v = new THREE.Vector4();
+      }
+      console.timeEnd("Vector4 x " + times);
+      console.time("Vector4Orig x " + times);
+      for( var i = 0; i < times; ++i) {
+        var v = new THREE.Vector4Orig();
+      }
+      console.timeEnd("Vector4Orig x " + times);
+
+      //Matrix4
+      console.time("Matrix4 x " + times);
+      for( var i = 0; i < times; ++i) {
+        var v = new THREE.Matrix4();
+      }
+      console.timeEnd("Matrix4 x " + times);
+      console.time("Matrix4Orig x " + times);
+      for( var i = 0; i < times; ++i) {
+        var v = new THREE.Matrix4Orig();
+      }
+      console.timeEnd("Matrix4Orig x " + times);
+    }
+    </script>
+  </head>
+  <body onload="initTest();">
+  </body>
+</html>

+ 1 - 1
src/core/Matrix3.js

@@ -3,7 +3,7 @@
  * @author supereggbert / http://www.paulbrunt.co.uk/
  */
 
-THREE.Matrix3 = function () {
+THREE.Matrix3Orig = function () {
 
 	this.n11 = 1; this.n12 = 0; this.n13 = 0;
 	this.n21 = 0; this.n22 = 1; this.n23 = 0;

+ 150 - 147
src/core/Matrix4.js

@@ -5,243 +5,246 @@
 
 THREE.Matrix4 = function () {
 
-	var x, y, z;
+  this._x = new THREE.Vector3();
+  this._y = new THREE.Vector3();
+  this._z = new THREE.Vector3();
 
-	x = new THREE.Vector3();
-	y = new THREE.Vector3();
-	z = new THREE.Vector3();
-
-	this.n11 = 1; this.n12 = 0; this.n13 = 0; this.n14 = 0;
-	this.n21 = 0; this.n22 = 1; this.n23 = 0; this.n24 = 0;
-	this.n31 = 0; this.n32 = 0; this.n33 = 1; this.n34 = 0;
-	this.n41 = 0; this.n42 = 0; this.n43 = 0; this.n44 = 1;
-
-	this.identity = function () {
+};
 
-		this.n11 = 1; this.n12 = 0; this.n13 = 0; this.n14 = 0;
-		this.n21 = 0; this.n22 = 1; this.n23 = 0; this.n24 = 0;
-		this.n31 = 0; this.n32 = 0; this.n33 = 1; this.n34 = 0;
-		this.n41 = 0; this.n42 = 0; this.n43 = 0; this.n44 = 1;
-	};
+THREE.Matrix4.prototype = {
+  n11: 1, n12: 0, n13: 0, n14: 0,
+  n21: 0, n22: 1, n23: 0, n24: 0,
+  n31: 0, n32: 0, n33: 1, n34: 0,
+  n41: 0, n42: 0, n43: 0, n44: 1,
+    
+  identity: function () {
 
-	this.lookAt = function ( eye, center, up ) {
+    this.n11 = 1; this.n12 = 0; this.n13 = 0; this.n14 = 0;
+    this.n21 = 0; this.n22 = 1; this.n23 = 0; this.n24 = 0;
+    this.n31 = 0; this.n32 = 0; this.n33 = 1; this.n34 = 0;
+    this.n41 = 0; this.n42 = 0; this.n43 = 0; this.n44 = 1;
+  },
 
-		z.sub( eye, center );
-		z.normalize();
+  lookAt: function ( eye, center, up ) {
 
-		x.cross( up, z );
-		x.normalize();
+    var x = this._x, y = this._y, z = this._z;
+    
+    z.sub( eye, center );
+    z.normalize();
 
-		y.cross( z, x );
-		y.normalize();
+    x.cross( up, z );
+    x.normalize();
 
-		this.n11 = x.x; this.n12 = x.y; this.n13 = x.z; this.n14 = - x.dot( eye );
-		this.n21 = y.x; this.n22 = y.y; this.n23 = y.z; this.n24 = - y.dot( eye );
-		this.n31 = z.x; this.n32 = z.y; this.n33 = z.z; this.n34 = - z.dot( eye );
-	};
+    y.cross( z, x );
+    y.normalize();
 
-	this.transform = function ( v ) {
+    this.n11 = x.x; this.n12 = x.y; this.n13 = x.z; this.n14 = - x.dot( eye );
+    this.n21 = y.x; this.n22 = y.y; this.n23 = y.z; this.n24 = - y.dot( eye );
+    this.n31 = z.x; this.n32 = z.y; this.n33 = z.z; this.n34 = - z.dot( eye );
+  },
 
-		var vx = v.x, vy = v.y, vz = v.z, vw = v.w ? v.w : 1.0;
+  transform: function ( v ) {
 
-		v.x = this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 * vw;
-		v.y = this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 * vw;
-		v.z = this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 * vw;
+    var vx = v.x, vy = v.y, vz = v.z, vw = v.w ? v.w : 1.0;
 
-		vw = this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 * vw;
+    v.x = this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 * vw;
+    v.y = this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 * vw;
+    v.z = this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 * vw;
 
-		if( v.w ) {
+    vw = this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 * vw;
 
-			v.w = vw;
+    if( v.w ) {
 
-		} else {
+      v.w = vw;
 
-			v.x = v.x / vw;
-			v.y = v.y / vw;
-			v.z = v.z / vw;
+    } else {
 
-		}
-	};
+      v.x = v.x / vw;
+      v.y = v.y / vw;
+      v.z = v.z / vw;
 
-	this.crossVector = function ( a ) {
+    }
+  },
 
-		var v = new THREE.Vector4();
+  crossVector: function ( a ) {
 
-		v.x = this.n11 * a.x + this.n12 * a.y + this.n13 * a.z + this.n14 * a.w;
-		v.y = this.n21 * a.x + this.n22 * a.y + this.n23 * a.z + this.n24 * a.w;
-		v.z = this.n31 * a.x + this.n32 * a.y + this.n33 * a.z + this.n34 * a.w;
+    var v = new THREE.Vector4();
 
-		v.w = ( a.w ) ? this.n41 * a.x + this.n42 * a.y + this.n43 * a.z + this.n44 * a.w : 1;
+    v.x = this.n11 * a.x + this.n12 * a.y + this.n13 * a.z + this.n14 * a.w;
+    v.y = this.n21 * a.x + this.n22 * a.y + this.n23 * a.z + this.n24 * a.w;
+    v.z = this.n31 * a.x + this.n32 * a.y + this.n33 * a.z + this.n34 * a.w;
 
-		return v;
+    v.w = ( a.w ) ? this.n41 * a.x + this.n42 * a.y + this.n43 * a.z + this.n44 * a.w : 1;
 
-	};
+    return v;
 
-	this.multiply = function ( a, b ) {
+  },
 
-		this.n11 = a.n11 * b.n11 + a.n12 * b.n21 + a.n13 * b.n31 + a.n14 * b.n41;
-		this.n12 = a.n11 * b.n12 + a.n12 * b.n22 + a.n13 * b.n32 + a.n14 * b.n42;
-		this.n13 = a.n11 * b.n13 + a.n12 * b.n23 + a.n13 * b.n33 + a.n14 * b.n43;
-		this.n14 = a.n11 * b.n14 + a.n12 * b.n24 + a.n13 * b.n34 + a.n14 * b.n44;
+  multiply: function ( a, b ) {
 
-		this.n21 = a.n21 * b.n11 + a.n22 * b.n21 + a.n23 * b.n31 + a.n24 * b.n41;
-		this.n22 = a.n21 * b.n12 + a.n22 * b.n22 + a.n23 * b.n32 + a.n24 * b.n42;
-		this.n23 = a.n21 * b.n13 + a.n22 * b.n23 + a.n23 * b.n33 + a.n24 * b.n43;
-		this.n24 = a.n21 * b.n14 + a.n22 * b.n24 + a.n23 * b.n34 + a.n24 * b.n44;
+    this.n11 = a.n11 * b.n11 + a.n12 * b.n21 + a.n13 * b.n31 + a.n14 * b.n41;
+    this.n12 = a.n11 * b.n12 + a.n12 * b.n22 + a.n13 * b.n32 + a.n14 * b.n42;
+    this.n13 = a.n11 * b.n13 + a.n12 * b.n23 + a.n13 * b.n33 + a.n14 * b.n43;
+    this.n14 = a.n11 * b.n14 + a.n12 * b.n24 + a.n13 * b.n34 + a.n14 * b.n44;
 
-		this.n31 = a.n31 * b.n11 + a.n32 * b.n21 + a.n33 * b.n31 + a.n34 * b.n41;
-		this.n32 = a.n31 * b.n12 + a.n32 * b.n22 + a.n33 * b.n32 + a.n34 * b.n42;
-		this.n33 = a.n31 * b.n13 + a.n32 * b.n23 + a.n33 * b.n33 + a.n34 * b.n43;
-		this.n34 = a.n31 * b.n14 + a.n32 * b.n24 + a.n33 * b.n34 + a.n34 * b.n44;
+    this.n21 = a.n21 * b.n11 + a.n22 * b.n21 + a.n23 * b.n31 + a.n24 * b.n41;
+    this.n22 = a.n21 * b.n12 + a.n22 * b.n22 + a.n23 * b.n32 + a.n24 * b.n42;
+    this.n23 = a.n21 * b.n13 + a.n22 * b.n23 + a.n23 * b.n33 + a.n24 * b.n43;
+    this.n24 = a.n21 * b.n14 + a.n22 * b.n24 + a.n23 * b.n34 + a.n24 * b.n44;
 
-		this.n41 = a.n41 * b.n11 + a.n42 * b.n21 + a.n43 * b.n31 + a.n44 * b.n41;
-		this.n42 = a.n41 * b.n12 + a.n42 * b.n22 + a.n43 * b.n32 + a.n44 * b.n42;
-		this.n43 = a.n41 * b.n13 + a.n42 * b.n23 + a.n43 * b.n33 + a.n44 * b.n43;
-		this.n44 = a.n41 * b.n14 + a.n42 * b.n24 + a.n43 * b.n34 + a.n44 * b.n44;
+    this.n31 = a.n31 * b.n11 + a.n32 * b.n21 + a.n33 * b.n31 + a.n34 * b.n41;
+    this.n32 = a.n31 * b.n12 + a.n32 * b.n22 + a.n33 * b.n32 + a.n34 * b.n42;
+    this.n33 = a.n31 * b.n13 + a.n32 * b.n23 + a.n33 * b.n33 + a.n34 * b.n43;
+    this.n34 = a.n31 * b.n14 + a.n32 * b.n24 + a.n33 * b.n34 + a.n34 * b.n44;
 
-	};
+    this.n41 = a.n41 * b.n11 + a.n42 * b.n21 + a.n43 * b.n31 + a.n44 * b.n41;
+    this.n42 = a.n41 * b.n12 + a.n42 * b.n22 + a.n43 * b.n32 + a.n44 * b.n42;
+    this.n43 = a.n41 * b.n13 + a.n42 * b.n23 + a.n43 * b.n33 + a.n44 * b.n43;
+    this.n44 = a.n41 * b.n14 + a.n42 * b.n24 + a.n43 * b.n34 + a.n44 * b.n44;
 
-	this.multiplySelf = function ( m ) {
+  },
 
-		var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14,
-		n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24,
-		n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34,
-		n41 = this.n41, n42 = this.n42, n43 = this.n43, n44 = this.n44;
+  multiplySelf: function ( m ) {
 
-		this.n11 = n11 * m.n11 + n12 * m.n21 + n13 * m.n31 + n14 * m.n41;
-		this.n12 = n11 * m.n12 + n12 * m.n22 + n13 * m.n32 + n14 * m.n42;
-		this.n13 = n11 * m.n13 + n12 * m.n23 + n13 * m.n33 + n14 * m.n43;
-		this.n14 = n11 * m.n14 + n12 * m.n24 + n13 * m.n34 + n14 * m.n44;
+    var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14,
+    n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24,
+    n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34,
+    n41 = this.n41, n42 = this.n42, n43 = this.n43, n44 = this.n44;
 
-		this.n21 = n21 * m.n11 + n22 * m.n21 + n23 * m.n31 + n24 * m.n41;
-		this.n22 = n21 * m.n12 + n22 * m.n22 + n23 * m.n32 + n24 * m.n42;
-		this.n23 = n21 * m.n13 + n22 * m.n23 + n23 * m.n33 + n24 * m.n43;
-		this.n24 = n21 * m.n14 + n22 * m.n24 + n23 * m.n34 + n24 * m.n44;
+    this.n11 = n11 * m.n11 + n12 * m.n21 + n13 * m.n31 + n14 * m.n41;
+    this.n12 = n11 * m.n12 + n12 * m.n22 + n13 * m.n32 + n14 * m.n42;
+    this.n13 = n11 * m.n13 + n12 * m.n23 + n13 * m.n33 + n14 * m.n43;
+    this.n14 = n11 * m.n14 + n12 * m.n24 + n13 * m.n34 + n14 * m.n44;
 
-		this.n31 = n31 * m.n11 + n32 * m.n21 + n33 * m.n31 + n34 * m.n41;
-		this.n32 = n31 * m.n12 + n32 * m.n22 + n33 * m.n32 + n34 * m.n42;
-		this.n33 = n31 * m.n13 + n32 * m.n23 + n33 * m.n33 + n34 * m.n43;
-		this.n34 = n31 * m.n14 + n32 * m.n24 + n33 * m.n34 + n34 * m.n44;
+    this.n21 = n21 * m.n11 + n22 * m.n21 + n23 * m.n31 + n24 * m.n41;
+    this.n22 = n21 * m.n12 + n22 * m.n22 + n23 * m.n32 + n24 * m.n42;
+    this.n23 = n21 * m.n13 + n22 * m.n23 + n23 * m.n33 + n24 * m.n43;
+    this.n24 = n21 * m.n14 + n22 * m.n24 + n23 * m.n34 + n24 * m.n44;
 
-		this.n41 = n41 * m.n11 + n42 * m.n21 + n43 * m.n31 + n44 * m.n41;
-		this.n42 = n41 * m.n12 + n42 * m.n22 + n43 * m.n32 + n44 * m.n42;
-		this.n43 = n41 * m.n13 + n42 * m.n23 + n43 * m.n33 + n44 * m.n43;
-		this.n44 = n41 * m.n14 + n42 * m.n24 + n43 * m.n34 + n44 * m.n44;
+    this.n31 = n31 * m.n11 + n32 * m.n21 + n33 * m.n31 + n34 * m.n41;
+    this.n32 = n31 * m.n12 + n32 * m.n22 + n33 * m.n32 + n34 * m.n42;
+    this.n33 = n31 * m.n13 + n32 * m.n23 + n33 * m.n33 + n34 * m.n43;
+    this.n34 = n31 * m.n14 + n32 * m.n24 + n33 * m.n34 + n34 * m.n44;
 
-	};
+    this.n41 = n41 * m.n11 + n42 * m.n21 + n43 * m.n31 + n44 * m.n41;
+    this.n42 = n41 * m.n12 + n42 * m.n22 + n43 * m.n32 + n44 * m.n42;
+    this.n43 = n41 * m.n13 + n42 * m.n23 + n43 * m.n33 + n44 * m.n43;
+    this.n44 = n41 * m.n14 + n42 * m.n24 + n43 * m.n34 + n44 * m.n44;
 
-	this.clone = function () {
+  },
 
-		var m = new THREE.Matrix4();
-		m.n11 = this.n11; m.n12 = this.n12; m.n13 = this.n13; m.n14 = this.n14;
-		m.n21 = this.n21; m.n22 = this.n22; m.n23 = this.n23; m.n24 = this.n24;
-		m.n31 = this.n31; m.n32 = this.n32; m.n33 = this.n33; m.n34 = this.n34;
-		m.n41 = this.n41; m.n42 = this.n42; m.n43 = this.n43; m.n44 = this.n44;
-		return m;
+  clone: function () {
 
-	};
+    var m = new THREE.Matrix4();
+    m.n11 = this.n11; m.n12 = this.n12; m.n13 = this.n13; m.n14 = this.n14;
+    m.n21 = this.n21; m.n22 = this.n22; m.n23 = this.n23; m.n24 = this.n24;
+    m.n31 = this.n31; m.n32 = this.n32; m.n33 = this.n33; m.n34 = this.n34;
+    m.n41 = this.n41; m.n42 = this.n42; m.n43 = this.n43; m.n44 = this.n44;
+    return m;
 
-	this.toString = function() {
+  },
 
-		return "| " + this.n11 + " " + this.n12 + " " + this.n13 + " " + this.n14 + " |\n" +
-			"| " + this.n21 + " " + this.n22 + " " + this.n23 + " " + this.n24 + " |\n" +
-			"| " + this.n31 + " " + this.n32 + " " + this.n33 + " " + this.n34 + " |\n" +
-			"| " + this.n41 + " " + this.n42 + " " + this.n43 + " " + this.n44 + " |";
+  toString: function() {
 
-	};
+    return "| " + this.n11 + " " + this.n12 + " " + this.n13 + " " + this.n14 + " |\n" +
+      "| " + this.n21 + " " + this.n22 + " " + this.n23 + " " + this.n24 + " |\n" +
+      "| " + this.n31 + " " + this.n32 + " " + this.n33 + " " + this.n34 + " |\n" +
+      "| " + this.n41 + " " + this.n42 + " " + this.n43 + " " + this.n44 + " |";
 
+  }
+    
 };
 
 THREE.Matrix4.translationMatrix = function ( x, y, z ) {
 
-	var m = new THREE.Matrix4();
+  var m = new THREE.Matrix4();
 
-	m.n14 = x;
-	m.n24 = y;
-	m.n34 = z;
+  m.n14 = x;
+  m.n24 = y;
+  m.n34 = z;
 
-	return m;
+  return m;
 
 };
 
 THREE.Matrix4.scaleMatrix = function ( x, y, z ) {
 
-	var m = new THREE.Matrix4();
+  var m = new THREE.Matrix4();
 
-	m.n11 = x;
-	m.n22 = y;
-	m.n33 = z;
+  m.n11 = x;
+  m.n22 = y;
+  m.n33 = z;
 
-	return m;
+  return m;
 
 };
 
 THREE.Matrix4.rotationXMatrix = function ( theta ) {
 
-	var rot = new THREE.Matrix4();
+  var rot = new THREE.Matrix4();
 
-	rot.n22 = rot.n33 = Math.cos( theta );
-	rot.n32 = Math.sin( theta );
-	rot.n23 = - rot.n32;
+  rot.n22 = rot.n33 = Math.cos( theta );
+  rot.n32 = Math.sin( theta );
+  rot.n23 = - rot.n32;
 
-	return rot;
+  return rot;
 
 };
 
 THREE.Matrix4.rotationYMatrix = function ( theta ) {
 
-	var rot = new THREE.Matrix4();
+  var rot = new THREE.Matrix4();
 
-	rot.n11 = rot.n33 = Math.cos( theta );
-	rot.n13 = Math.sin( theta );
-	rot.n31 = - rot.n13;
+  rot.n11 = rot.n33 = Math.cos( theta );
+  rot.n13 = Math.sin( theta );
+  rot.n31 = - rot.n13;
 
-	return rot;
+  return rot;
 
 };
 
 THREE.Matrix4.rotationZMatrix = function( theta ) {
 
-	var rot = new THREE.Matrix4();
+  var rot = new THREE.Matrix4();
 
-	rot.n11 = rot.n22 = Math.cos( theta );
-	rot.n21 = Math.sin( theta );
-	rot.n12 = - rot.n21;
+  rot.n11 = rot.n22 = Math.cos( theta );
+  rot.n21 = Math.sin( theta );
+  rot.n12 = - rot.n21;
 
-	return rot;
+  return rot;
 
 };
 
 THREE.Matrix4.makeFrustum = function( left, right, bottom, top, near, far ) {
 
-	var m, x, y, a, b, c, d;
+  var m, x, y, a, b, c, d;
 
-	m = new THREE.Matrix4();
-	x = 2 * near / ( right - left );
-	y = 2 * near / ( top - bottom );
-	a = ( right + left ) / ( right - left );
-	b = ( top + bottom ) / ( top - bottom );
-	c = - ( far + near ) / ( far - near );
-	d = - 2 * far * near / ( far - near );
+  m = new THREE.Matrix4();
+  x = 2 * near / ( right - left );
+  y = 2 * near / ( top - bottom );
+  a = ( right + left ) / ( right - left );
+  b = ( top + bottom ) / ( top - bottom );
+  c = - ( far + near ) / ( far - near );
+  d = - 2 * far * near / ( far - near );
 
-	m.n11 = x; m.n12 = 0; m.n13 = a; m.n14 = 0;
-	m.n21 = 0; m.n22 = y; m.n23 = b; m.n24 = 0;
-	m.n31 = 0; m.n32 = 0; m.n33 = c; m.n34 = d;
-	m.n41 = 0; m.n42 = 0; m.n43 = - 1; m.n44 = 0;
+  m.n11 = x; m.n12 = 0; m.n13 = a; m.n14 = 0;
+  m.n21 = 0; m.n22 = y; m.n23 = b; m.n24 = 0;
+  m.n31 = 0; m.n32 = 0; m.n33 = c; m.n34 = d;
+  m.n41 = 0; m.n42 = 0; m.n43 = - 1; m.n44 = 0;
 
-	return m;
+  return m;
 
 };
 
 THREE.Matrix4.makePerspective = function( fov, aspect, near, far ) {
 
-	var ymax, ymin, xmin, xmax;
+  var ymax, ymin, xmin, xmax;
 
-	ymax = near * Math.tan( fov * Math.PI / 360 );
-	ymin = - ymax;
-	xmin = ymin * aspect;
-	xmax = ymax * aspect;
+  ymax = near * Math.tan( fov * Math.PI / 360 );
+  ymin = - ymax;
+  xmin = ymin * aspect;
+  xmax = ymax * aspect;
 
-	return THREE.Matrix4.makeFrustum( xmin, xmax, ymin, ymax, near, far );
+  return THREE.Matrix4.makeFrustum( xmin, xmax, ymin, ymax, near, far );
 
 };

+ 247 - 0
src/core/Matrix4.old.js

@@ -0,0 +1,247 @@
+/**
+ * @author supereggbert / http://www.paulbrunt.co.uk/
+ * @author mr.doob / http://mrdoob.com/
+ */
+
+THREE.Matrix4Orig = function () {
+
+  var x, y, z;
+
+  x = new THREE.Vector3Orig();
+  y = new THREE.Vector3Orig();
+  z = new THREE.Vector3Orig();
+
+  this.n11 = 1; this.n12 = 0; this.n13 = 0; this.n14 = 0;
+  this.n21 = 0; this.n22 = 1; this.n23 = 0; this.n24 = 0;
+  this.n31 = 0; this.n32 = 0; this.n33 = 1; this.n34 = 0;
+  this.n41 = 0; this.n42 = 0; this.n43 = 0; this.n44 = 1;
+
+  this.identity = function () {
+
+    this.n11 = 1; this.n12 = 0; this.n13 = 0; this.n14 = 0;
+    this.n21 = 0; this.n22 = 1; this.n23 = 0; this.n24 = 0;
+    this.n31 = 0; this.n32 = 0; this.n33 = 1; this.n34 = 0;
+    this.n41 = 0; this.n42 = 0; this.n43 = 0; this.n44 = 1;
+  };
+
+  this.lookAt = function ( eye, center, up ) {
+
+    z.sub( eye, center );
+    z.normalize();
+
+    x.cross( up, z );
+    x.normalize();
+
+    y.cross( z, x );
+    y.normalize();
+
+    this.n11 = x.x; this.n12 = x.y; this.n13 = x.z; this.n14 = - x.dot( eye );
+    this.n21 = y.x; this.n22 = y.y; this.n23 = y.z; this.n24 = - y.dot( eye );
+    this.n31 = z.x; this.n32 = z.y; this.n33 = z.z; this.n34 = - z.dot( eye );
+  };
+
+  this.transform = function ( v ) {
+
+    var vx = v.x, vy = v.y, vz = v.z, vw = v.w ? v.w : 1.0;
+
+    v.x = this.n11 * vx + this.n12 * vy + this.n13 * vz + this.n14 * vw;
+    v.y = this.n21 * vx + this.n22 * vy + this.n23 * vz + this.n24 * vw;
+    v.z = this.n31 * vx + this.n32 * vy + this.n33 * vz + this.n34 * vw;
+
+    vw = this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 * vw;
+
+    if( v.w ) {
+
+      v.w = vw;
+
+    } else {
+
+      v.x = v.x / vw;
+      v.y = v.y / vw;
+      v.z = v.z / vw;
+
+    }
+  };
+
+  this.crossVector = function ( a ) {
+
+    var v = new THREE.Vector4Orig();
+
+    v.x = this.n11 * a.x + this.n12 * a.y + this.n13 * a.z + this.n14 * a.w;
+    v.y = this.n21 * a.x + this.n22 * a.y + this.n23 * a.z + this.n24 * a.w;
+    v.z = this.n31 * a.x + this.n32 * a.y + this.n33 * a.z + this.n34 * a.w;
+
+    v.w = ( a.w ) ? this.n41 * a.x + this.n42 * a.y + this.n43 * a.z + this.n44 * a.w : 1;
+
+    return v;
+
+  };
+
+  this.multiply = function ( a, b ) {
+
+    this.n11 = a.n11 * b.n11 + a.n12 * b.n21 + a.n13 * b.n31 + a.n14 * b.n41;
+    this.n12 = a.n11 * b.n12 + a.n12 * b.n22 + a.n13 * b.n32 + a.n14 * b.n42;
+    this.n13 = a.n11 * b.n13 + a.n12 * b.n23 + a.n13 * b.n33 + a.n14 * b.n43;
+    this.n14 = a.n11 * b.n14 + a.n12 * b.n24 + a.n13 * b.n34 + a.n14 * b.n44;
+
+    this.n21 = a.n21 * b.n11 + a.n22 * b.n21 + a.n23 * b.n31 + a.n24 * b.n41;
+    this.n22 = a.n21 * b.n12 + a.n22 * b.n22 + a.n23 * b.n32 + a.n24 * b.n42;
+    this.n23 = a.n21 * b.n13 + a.n22 * b.n23 + a.n23 * b.n33 + a.n24 * b.n43;
+    this.n24 = a.n21 * b.n14 + a.n22 * b.n24 + a.n23 * b.n34 + a.n24 * b.n44;
+
+    this.n31 = a.n31 * b.n11 + a.n32 * b.n21 + a.n33 * b.n31 + a.n34 * b.n41;
+    this.n32 = a.n31 * b.n12 + a.n32 * b.n22 + a.n33 * b.n32 + a.n34 * b.n42;
+    this.n33 = a.n31 * b.n13 + a.n32 * b.n23 + a.n33 * b.n33 + a.n34 * b.n43;
+    this.n34 = a.n31 * b.n14 + a.n32 * b.n24 + a.n33 * b.n34 + a.n34 * b.n44;
+
+    this.n41 = a.n41 * b.n11 + a.n42 * b.n21 + a.n43 * b.n31 + a.n44 * b.n41;
+    this.n42 = a.n41 * b.n12 + a.n42 * b.n22 + a.n43 * b.n32 + a.n44 * b.n42;
+    this.n43 = a.n41 * b.n13 + a.n42 * b.n23 + a.n43 * b.n33 + a.n44 * b.n43;
+    this.n44 = a.n41 * b.n14 + a.n42 * b.n24 + a.n43 * b.n34 + a.n44 * b.n44;
+
+  };
+
+  this.multiplySelf = function ( m ) {
+
+    var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14,
+    n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24,
+    n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34,
+    n41 = this.n41, n42 = this.n42, n43 = this.n43, n44 = this.n44;
+
+    this.n11 = n11 * m.n11 + n12 * m.n21 + n13 * m.n31 + n14 * m.n41;
+    this.n12 = n11 * m.n12 + n12 * m.n22 + n13 * m.n32 + n14 * m.n42;
+    this.n13 = n11 * m.n13 + n12 * m.n23 + n13 * m.n33 + n14 * m.n43;
+    this.n14 = n11 * m.n14 + n12 * m.n24 + n13 * m.n34 + n14 * m.n44;
+
+    this.n21 = n21 * m.n11 + n22 * m.n21 + n23 * m.n31 + n24 * m.n41;
+    this.n22 = n21 * m.n12 + n22 * m.n22 + n23 * m.n32 + n24 * m.n42;
+    this.n23 = n21 * m.n13 + n22 * m.n23 + n23 * m.n33 + n24 * m.n43;
+    this.n24 = n21 * m.n14 + n22 * m.n24 + n23 * m.n34 + n24 * m.n44;
+
+    this.n31 = n31 * m.n11 + n32 * m.n21 + n33 * m.n31 + n34 * m.n41;
+    this.n32 = n31 * m.n12 + n32 * m.n22 + n33 * m.n32 + n34 * m.n42;
+    this.n33 = n31 * m.n13 + n32 * m.n23 + n33 * m.n33 + n34 * m.n43;
+    this.n34 = n31 * m.n14 + n32 * m.n24 + n33 * m.n34 + n34 * m.n44;
+
+    this.n41 = n41 * m.n11 + n42 * m.n21 + n43 * m.n31 + n44 * m.n41;
+    this.n42 = n41 * m.n12 + n42 * m.n22 + n43 * m.n32 + n44 * m.n42;
+    this.n43 = n41 * m.n13 + n42 * m.n23 + n43 * m.n33 + n44 * m.n43;
+    this.n44 = n41 * m.n14 + n42 * m.n24 + n43 * m.n34 + n44 * m.n44;
+
+  };
+
+  this.clone = function () {
+
+    var m = new THREE.Matrix4Orig();
+    m.n11 = this.n11; m.n12 = this.n12; m.n13 = this.n13; m.n14 = this.n14;
+    m.n21 = this.n21; m.n22 = this.n22; m.n23 = this.n23; m.n24 = this.n24;
+    m.n31 = this.n31; m.n32 = this.n32; m.n33 = this.n33; m.n34 = this.n34;
+    m.n41 = this.n41; m.n42 = this.n42; m.n43 = this.n43; m.n44 = this.n44;
+    return m;
+
+  };
+
+  this.toString = function() {
+
+    return "| " + this.n11 + " " + this.n12 + " " + this.n13 + " " + this.n14 + " |\n" +
+      "| " + this.n21 + " " + this.n22 + " " + this.n23 + " " + this.n24 + " |\n" +
+      "| " + this.n31 + " " + this.n32 + " " + this.n33 + " " + this.n34 + " |\n" +
+      "| " + this.n41 + " " + this.n42 + " " + this.n43 + " " + this.n44 + " |";
+
+  };
+
+};
+
+THREE.Matrix4Orig.translationMatrix = function ( x, y, z ) {
+
+  var m = new THREE.Matrix4Orig();
+
+  m.n14 = x;
+  m.n24 = y;
+  m.n34 = z;
+
+  return m;
+
+};
+
+THREE.Matrix4Orig.scaleMatrix = function ( x, y, z ) {
+
+  var m = new THREE.Matrix4Orig();
+
+  m.n11 = x;
+  m.n22 = y;
+  m.n33 = z;
+
+  return m;
+
+};
+
+THREE.Matrix4Orig.rotationXMatrix = function ( theta ) {
+
+  var rot = new THREE.Matrix4Orig();
+
+  rot.n22 = rot.n33 = Math.cos( theta );
+  rot.n32 = Math.sin( theta );
+  rot.n23 = - rot.n32;
+
+  return rot;
+
+};
+
+THREE.Matrix4Orig.rotationYMatrix = function ( theta ) {
+
+  var rot = new THREE.Matrix4Orig();
+
+  rot.n11 = rot.n33 = Math.cos( theta );
+  rot.n13 = Math.sin( theta );
+  rot.n31 = - rot.n13;
+
+  return rot;
+
+};
+
+THREE.Matrix4Orig.rotationZMatrix = function( theta ) {
+
+  var rot = new THREE.Matrix4Orig();
+
+  rot.n11 = rot.n22 = Math.cos( theta );
+  rot.n21 = Math.sin( theta );
+  rot.n12 = - rot.n21;
+
+  return rot;
+
+};
+
+THREE.Matrix4Orig.makeFrustum = function( left, right, bottom, top, near, far ) {
+
+  var m, x, y, a, b, c, d;
+
+  m = new THREE.Matrix4Orig();
+  x = 2 * near / ( right - left );
+  y = 2 * near / ( top - bottom );
+  a = ( right + left ) / ( right - left );
+  b = ( top + bottom ) / ( top - bottom );
+  c = - ( far + near ) / ( far - near );
+  d = - 2 * far * near / ( far - near );
+
+  m.n11 = x; m.n12 = 0; m.n13 = a; m.n14 = 0;
+  m.n21 = 0; m.n22 = y; m.n23 = b; m.n24 = 0;
+  m.n31 = 0; m.n32 = 0; m.n33 = c; m.n34 = d;
+  m.n41 = 0; m.n42 = 0; m.n43 = - 1; m.n44 = 0;
+
+  return m;
+
+};
+
+THREE.Matrix4Orig.makePerspective = function( fov, aspect, near, far ) {
+
+  var ymax, ymin, xmin, xmax;
+
+  ymax = near * Math.tan( fov * Math.PI / 360 );
+  ymin = - ymax;
+  xmin = ymin * aspect;
+  xmax = ymax * aspect;
+
+  return THREE.Matrix4Orig.makeFrustum( xmin, xmax, ymin, ymax, near, far );
+
+};

+ 54 - 49
src/core/Vector2.js

@@ -4,92 +4,97 @@
 
 THREE.Vector2 = function ( x, y ) {
 
-	this.x = x || 0;
-	this.y = y || 0;
+  this.x = x || 0;
+  this.y = y || 0;
 
-	this.set = function ( x, y ) {
+};
+
+THREE.Vector2.prototype = {
+  
+  set: function ( x, y ) {
 
-		this.x = x;
-		this.y = y;
+    this.x = x;
+    this.y = y;
 
-	};
+  },
 
-	this.copy = function ( v ) {
+  copy: function ( v ) {
 
-		this.x = v.x;
-		this.y = v.y;
+    this.x = v.x;
+    this.y = v.y;
 
-	};
+  },
 
-	this.addSelf = function ( v ) {
+  addSelf: function ( v ) {
 
-		this.x += v.x;
-		this.y += v.y;
+    this.x += v.x;
+    this.y += v.y;
 
-	};
+  },
 
-	this.add = function ( v1, v2 ) {
+  add: function ( v1, v2 ) {
 
-		this.x = v1.x + v2.x;
-		this.y = v1.y + v2.y;
+    this.x = v1.x + v2.x;
+    this.y = v1.y + v2.y;
 
-	};
+  },
 
-	this.subSelf = function ( v ) {
+  subSelf: function ( v ) {
 
-		this.x -= v.x;
-		this.y -= v.y;
+    this.x -= v.x;
+    this.y -= v.y;
 
-	};
+  },
 
-	this.sub = function ( v1, v2 ) {
+  sub: function ( v1, v2 ) {
 
-		this.x = v1.x - v2.x;
-		this.y = v1.y - v2.y;
+    this.x = v1.x - v2.x;
+    this.y = v1.y - v2.y;
 
-	};
+  },
 
-	this.multiplyScalar = function ( s ) {
+  multiplyScalar: function ( s ) {
 
-		this.x *= s;
-		this.y *= s;
+    this.x *= s;
+    this.y *= s;
 
-	};
+  },
 
-	this.unit = function () {
+  unit: function () {
 
-		this.multiplyScalar( 1 / this.length() );
+    this.multiplyScalar( 1 / this.length() );
 
-	};
+  },
 
-	this.length = function () {
+  length: function () {
 
-		return Math.sqrt( this.x * this.x + this.y * this.y );
+    return Math.sqrt( this.x * this.x + this.y * this.y );
 
-	};
+  },
 
-	this.lengthSq = function () {
+  lengthSq: function () {
 
-		return this.x * this.x + this.y * this.y;
+    return this.x * this.x + this.y * this.y;
 
-	};
+  },
 
-	this.negate = function() {
+  negate: function() {
 
-		this.x = - this.x;
-		this.y = - this.y;
+    this.x = - this.x;
+    this.y = - this.y;
 
-	};
+  },
 
-	this.clone = function () {
+  clone: function () {
 
-		return new THREE.Vector2( this.x, this.y );
+    return new THREE.Vector2( this.x, this.y );
 
-	};
+  },
 
-	this.toString = function () {
+  toString: function () {
 
-		return 'THREE.Vector2 (' + this.x + ', ' + this.y + ')';
+    return 'THREE.Vector2 (' + this.x + ', ' + this.y + ')';
 
-	};
+  }
+        
 };

+ 95 - 0
src/core/Vector2.old.js

@@ -0,0 +1,95 @@
+/**
+ * @author mr.doob / http://mrdoob.com/
+ */
+
+THREE.Vector2Orig = function ( x, y ) {
+
+	this.x = x || 0;
+	this.y = y || 0;
+
+	this.set = function ( x, y ) {
+
+		this.x = x;
+		this.y = y;
+
+	};
+
+	this.copy = function ( v ) {
+
+		this.x = v.x;
+		this.y = v.y;
+
+	};
+
+	this.addSelf = function ( v ) {
+
+		this.x += v.x;
+		this.y += v.y;
+
+	};
+
+	this.add = function ( v1, v2 ) {
+
+		this.x = v1.x + v2.x;
+		this.y = v1.y + v2.y;
+
+	};
+
+	this.subSelf = function ( v ) {
+
+		this.x -= v.x;
+		this.y -= v.y;
+
+	};
+
+	this.sub = function ( v1, v2 ) {
+
+		this.x = v1.x - v2.x;
+		this.y = v1.y - v2.y;
+
+	};
+
+	this.multiplyScalar = function ( s ) {
+
+		this.x *= s;
+		this.y *= s;
+
+	};
+
+	this.unit = function () {
+
+		this.multiplyScalar( 1 / this.length() );
+
+	};
+
+	this.length = function () {
+
+		return Math.sqrt( this.x * this.x + this.y * this.y );
+
+	};
+
+	this.lengthSq = function () {
+
+		return this.x * this.x + this.y * this.y;
+
+	};
+
+	this.negate = function() {
+
+		this.x = - this.x;
+		this.y = - this.y;
+
+	};
+
+	this.clone = function () {
+
+		return new THREE.Vector2Orig( this.x, this.y );
+
+	};
+
+	this.toString = function () {
+
+		return 'THREE.Vector2Orig (' + this.x + ', ' + this.y + ')';
+
+	};
+};

+ 97 - 93
src/core/Vector3.js

@@ -5,162 +5,166 @@
 
 THREE.Vector3 = function ( x, y, z ) {
 
-	this.x = x || 0;
-	this.y = y || 0;
-	this.z = z || 0;
+  this.x = x || 0;
+  this.y = y || 0;
+  this.z = z || 0;
 
-	this.set = function ( x, y, z ) {
+};
 
-		this.x = x;
-		this.y = y;
-		this.z = z;
+THREE.Vector3.prototype = {
+  
+  set: function ( x, y, z ) {
 
-	};
+    this.x = x;
+    this.y = y;
+    this.z = z;
 
-	this.copy = function ( v ) {
+  },
 
-		this.x = v.x;
-		this.y = v.y;
-		this.z = v.z;
+  copy: function ( v ) {
 
-	};
+    this.x = v.x;
+    this.y = v.y;
+    this.z = v.z;
 
-	this.add = function( v1, v2 ) {
+  },
 
-		this.x = v1.x + v2.x;
-		this.y = v1.y + v2.y;
-		this.z = v1.z + v2.z;
+  add: function( v1, v2 ) {
 
-	};
+    this.x = v1.x + v2.x;
+    this.y = v1.y + v2.y;
+    this.z = v1.z + v2.z;
 
-	this.addSelf = function ( v ) {
+  },
 
-		this.x += v.x;
-		this.y += v.y;
-		this.z += v.z;
+  addSelf: function ( v ) {
 
-	};
+    this.x += v.x;
+    this.y += v.y;
+    this.z += v.z;
 
-	this.addScalar = function ( s ) {
+  },
 
-		this.x += s;
-		this.y += s;
-		this.z += s;
+  addScalar: function ( s ) {
 
-	};
+    this.x += s;
+    this.y += s;
+    this.z += s;
 
-	this.sub = function( v1, v2 ) {
+  },
 
-		this.x = v1.x - v2.x;
-		this.y = v1.y - v2.y;
-		this.z = v1.z - v2.z;
+  sub: function( v1, v2 ) {
 
-	};
+    this.x = v1.x - v2.x;
+    this.y = v1.y - v2.y;
+    this.z = v1.z - v2.z;
 
-	this.subSelf = function ( v ) {
+  },
 
-		this.x -= v.x;
-		this.y -= v.y;
-		this.z -= v.z;
+  subSelf: function ( v ) {
 
-	};
+    this.x -= v.x;
+    this.y -= v.y;
+    this.z -= v.z;
 
-	this.cross = function ( v1, v2 ) {
+  },
 
-		this.x = v1.y * v2.z - v1.z * v2.y;
-		this.y = v1.z * v2.x - v1.x * v2.z;
-		this.z = v1.x * v2.y - v1.y * v2.x;
+  cross: function ( v1, v2 ) {
 
-	};
+    this.x = v1.y * v2.z - v1.z * v2.y;
+    this.y = v1.z * v2.x - v1.x * v2.z;
+    this.z = v1.x * v2.y - v1.y * v2.x;
 
-	this.crossSelf = function ( v ) {
+  },
 
-		var tx = this.x, ty = this.y, tz = this.z;
+  crossSelf: function ( v ) {
 
-		this.x = ty * v.z - tz * v.y;
-		this.y = tz * v.x - tx * v.z;
-		this.z = tx * v.y - ty * v.x;
+    var tx = this.x, ty = this.y, tz = this.z;
 
-	};
+    this.x = ty * v.z - tz * v.y;
+    this.y = tz * v.x - tx * v.z;
+    this.z = tx * v.y - ty * v.x;
 
-	this.multiplySelf = function ( v ) {
+  },
 
-		this.x *= v.x;
-		this.y *= v.y;
-		this.z *= v.z;
-	};
+  multiplySelf: function ( v ) {
 
-	this.multiplyScalar = function ( s ) {
+    this.x *= v.x;
+    this.y *= v.y;
+    this.z *= v.z;
+  },
 
-		this.x *= s;
-		this.y *= s;
-		this.z *= s;
+  multiplyScalar: function ( s ) {
 
-	};
+    this.x *= s;
+    this.y *= s;
+    this.z *= s;
 
-	this.dot = function ( v ) {
+  },
 
-		return this.x * v.x + this.y * v.y + this.z * v.z;
+  dot: function ( v ) {
 
-	};
+    return this.x * v.x + this.y * v.y + this.z * v.z;
 
-	this.distanceTo = function ( v ) {
+  },
 
-		return Math.sqrt( this.distanceToSquared( v ) );
+  distanceTo: function ( v ) {
 
-	};
+    return Math.sqrt( this.distanceToSquared( v ) );
 
-	this.distanceToSquared = function ( v ) {
+  },
 
-		var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
-		return dx * dx + dy * dy + dz * dz;
+  distanceToSquared: function ( v ) {
 
-	};
+    var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
+    return dx * dx + dy * dy + dz * dz;
 
-	this.length = function () {
+  },
 
-		return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
+  length: function () {
 
-	};
+    return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
 
-	this.lengthSq = function () {
+  },
 
-		return this.x * this.x + this.y * this.y + this.z * this.z;
+  lengthSq: function () {
 
-	};
+    return this.x * this.x + this.y * this.y + this.z * this.z;
 
-	this.negate = function () {
+  },
 
-		this.x = - this.x;
-		this.y = - this.y;
-		this.z = - this.z;
+  negate: function () {
 
-	};
+    this.x = - this.x;
+    this.y = - this.y;
+    this.z = - this.z;
 
-	this.normalize = function () {
+  },
 
-		if (this.length() > 0) {
+  normalize: function () {
 
-			this.multiplyScalar( 1 / this.length() );
+    if (this.length() > 0) {
 
-		} else {
+      this.multiplyScalar( 1 / this.length() );
 
-			this.multiplyScalar( 0 );
+    } else {
 
-		}
+      this.multiplyScalar( 0 );
 
-	};
+    }
 
-	this.clone = function () {
+  },
 
-		return new THREE.Vector3( this.x, this.y, this.z );
+  clone: function () {
 
-	};
+    return new THREE.Vector3( this.x, this.y, this.z );
 
-	this.toString = function () {
+  },
 
-		return 'THREE.Vector3 ( ' + this.x + ', ' + this.y + ', ' + this.z + ' )';
+  toString: function () {
 
-	};
+    return 'THREE.Vector3 ( ' + this.x + ', ' + this.y + ', ' + this.z + ' )';
 
+  }
+    
 };

+ 166 - 0
src/core/Vector3.old.js

@@ -0,0 +1,166 @@
+/**
+ * @author mr.doob / http://mrdoob.com/
+ * @author kile / http://kile.stravaganza.org/
+ */
+
+THREE.Vector3Orig = function ( x, y, z ) {
+
+	this.x = x || 0;
+	this.y = y || 0;
+	this.z = z || 0;
+
+	this.set = function ( x, y, z ) {
+
+		this.x = x;
+		this.y = y;
+		this.z = z;
+
+	};
+
+	this.copy = function ( v ) {
+
+		this.x = v.x;
+		this.y = v.y;
+		this.z = v.z;
+
+	};
+
+	this.add = function( v1, v2 ) {
+
+		this.x = v1.x + v2.x;
+		this.y = v1.y + v2.y;
+		this.z = v1.z + v2.z;
+
+	};
+
+	this.addSelf = function ( v ) {
+
+		this.x += v.x;
+		this.y += v.y;
+		this.z += v.z;
+
+	};
+
+	this.addScalar = function ( s ) {
+
+		this.x += s;
+		this.y += s;
+		this.z += s;
+
+	};
+
+	this.sub = function( v1, v2 ) {
+
+		this.x = v1.x - v2.x;
+		this.y = v1.y - v2.y;
+		this.z = v1.z - v2.z;
+
+	};
+
+	this.subSelf = function ( v ) {
+
+		this.x -= v.x;
+		this.y -= v.y;
+		this.z -= v.z;
+
+	};
+
+	this.cross = function ( v1, v2 ) {
+
+		this.x = v1.y * v2.z - v1.z * v2.y;
+		this.y = v1.z * v2.x - v1.x * v2.z;
+		this.z = v1.x * v2.y - v1.y * v2.x;
+
+	};
+
+	this.crossSelf = function ( v ) {
+
+		var tx = this.x, ty = this.y, tz = this.z;
+
+		this.x = ty * v.z - tz * v.y;
+		this.y = tz * v.x - tx * v.z;
+		this.z = tx * v.y - ty * v.x;
+
+	};
+
+	this.multiplySelf = function ( v ) {
+
+		this.x *= v.x;
+		this.y *= v.y;
+		this.z *= v.z;
+	};
+
+	this.multiplyScalar = function ( s ) {
+
+		this.x *= s;
+		this.y *= s;
+		this.z *= s;
+
+	};
+
+	this.dot = function ( v ) {
+
+		return this.x * v.x + this.y * v.y + this.z * v.z;
+
+	};
+
+	this.distanceTo = function ( v ) {
+
+		return Math.sqrt( this.distanceToSquared( v ) );
+
+	};
+
+	this.distanceToSquared = function ( v ) {
+
+		var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
+		return dx * dx + dy * dy + dz * dz;
+
+	};
+
+	this.length = function () {
+
+		return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
+
+	};
+
+	this.lengthSq = function () {
+
+		return this.x * this.x + this.y * this.y + this.z * this.z;
+
+	};
+
+	this.negate = function () {
+
+		this.x = - this.x;
+		this.y = - this.y;
+		this.z = - this.z;
+
+	};
+
+	this.normalize = function () {
+
+		if (this.length() > 0) {
+
+			this.multiplyScalar( 1 / this.length() );
+
+		} else {
+
+			this.multiplyScalar( 0 );
+
+		}
+
+	};
+
+	this.clone = function () {
+
+		return new THREE.Vector3Orig( this.x, this.y, this.z );
+
+	};
+
+	this.toString = function () {
+
+		return 'THREE.Vector3Orig ( ' + this.x + ', ' + this.y + ', ' + this.z + ' )';
+
+	};
+
+};

+ 82 - 78
src/core/Vector4.js

@@ -1,78 +1,82 @@
-/**
- * @author supereggbert / http://www.paulbrunt.co.uk/
- */
-
-THREE.Vector4 = function ( x, y, z, w ) {
-
-	this.x = x || 0;
-	this.y = y || 0;
-	this.z = z || 0;
-	this.w = w || 1;
-
-	this.set = function ( x, y, z, w ) {
-
-		this.x = x;
-		this.y = y;
-		this.z = z;
-		this.w = w;
-
-	};
-
-	this.copy = function ( v ) {
-
-		this.x = v.x;
-		this.y = v.y;
-		this.z = v.z;
-		this.w = v.w;
-
-	};
-
-	this.add = function ( v1, v2 ) {
-
-		this.x = v1.x + v2.x;
-		this.y = v1.y + v2.y;
-		this.z = v1.z + v2.z;
-		this.w = v1.w + v2.w;
-
-	};
-
-	this.addSelf = function ( v ) {
-
-		this.x += v.x;
-		this.y += v.y;
-		this.z += v.z;
-		this.w += v.w;
-
-	};
-
-	this.sub = function ( v1, v2 ) {
-
-		this.x = v1.x - v2.x;
-		this.y = v1.y - v2.y;
-		this.z = v1.z - v2.z;
-		this.w = v1.w - v2.w;
-
-	};
-
-	this.subSelf = function ( v ) {
-
-		this.x -= v.x;
-		this.y -= v.y;
-		this.z -= v.z;
-		this.w -= v.w;
-
-	};
-
-	this.clone = function () {
-
-		return new THREE.Vector4( this.x, this.y, this.z, this.w );
-
-	};
-
-	this.toString = function () {
-
-		return 'THREE.Vector4 (' + this.x + ', ' + this.y + ', ' + this.z + ', ' + this.w + ')';
-
-	};
-
-};
+/**
+ * @author supereggbert / http://www.paulbrunt.co.uk/
+ */
+
+THREE.Vector4 = function ( x, y, z, w ) {
+
+  this.x = x || 0;
+  this.y = y || 0;
+  this.z = z || 0;
+  this.w = w || 1;
+
+};
+
+THREE.Vector4.prototype = {
+
+  set: function ( x, y, z, w ) {
+
+    this.x = x;
+    this.y = y;
+    this.z = z;
+    this.w = w;
+
+  },
+
+  copy: function ( v ) {
+
+    this.x = v.x;
+    this.y = v.y;
+    this.z = v.z;
+    this.w = v.w;
+
+  },
+
+  add: function ( v1, v2 ) {
+
+    this.x = v1.x + v2.x;
+    this.y = v1.y + v2.y;
+    this.z = v1.z + v2.z;
+    this.w = v1.w + v2.w;
+
+  },
+
+  addSelf: function ( v ) {
+
+    this.x += v.x;
+    this.y += v.y;
+    this.z += v.z;
+    this.w += v.w;
+
+  },
+
+  sub: function ( v1, v2 ) {
+
+    this.x = v1.x - v2.x;
+    this.y = v1.y - v2.y;
+    this.z = v1.z - v2.z;
+    this.w = v1.w - v2.w;
+
+  },
+
+  subSelf: function ( v ) {
+
+    this.x -= v.x;
+    this.y -= v.y;
+    this.z -= v.z;
+    this.w -= v.w;
+
+  },
+
+  clone: function () {
+
+    return new THREE.Vector4( this.x, this.y, this.z, this.w );
+
+  },
+
+  toString: function () {
+
+    return 'THREE.Vector4 (' + this.x + ', ' + this.y + ', ' + this.z + ', ' + this.w + ')';
+
+  }
+
+};

+ 78 - 0
src/core/Vector4.old.js

@@ -0,0 +1,78 @@
+/**
+ * @author supereggbert / http://www.paulbrunt.co.uk/
+ */
+
+THREE.Vector4Orig = function ( x, y, z, w ) {
+
+	this.x = x || 0;
+	this.y = y || 0;
+	this.z = z || 0;
+	this.w = w || 1;
+
+	this.set = function ( x, y, z, w ) {
+
+		this.x = x;
+		this.y = y;
+		this.z = z;
+		this.w = w;
+
+	};
+
+	this.copy = function ( v ) {
+
+		this.x = v.x;
+		this.y = v.y;
+		this.z = v.z;
+		this.w = v.w;
+
+	};
+
+	this.add = function ( v1, v2 ) {
+
+		this.x = v1.x + v2.x;
+		this.y = v1.y + v2.y;
+		this.z = v1.z + v2.z;
+		this.w = v1.w + v2.w;
+
+	};
+
+	this.addSelf = function ( v ) {
+
+		this.x += v.x;
+		this.y += v.y;
+		this.z += v.z;
+		this.w += v.w;
+
+	};
+
+	this.sub = function ( v1, v2 ) {
+
+		this.x = v1.x - v2.x;
+		this.y = v1.y - v2.y;
+		this.z = v1.z - v2.z;
+		this.w = v1.w - v2.w;
+
+	};
+
+	this.subSelf = function ( v ) {
+
+		this.x -= v.x;
+		this.y -= v.y;
+		this.z -= v.z;
+		this.w -= v.w;
+
+	};
+
+	this.clone = function () {
+
+		return new THREE.Vector4Orig( this.x, this.y, this.z, this.w );
+
+	};
+
+	this.toString = function () {
+
+		return 'THREE.Vector4Orig (' + this.x + ', ' + this.y + ', ' + this.z + ', ' + this.w + ')';
+
+	};
+
+};

Some files were not shown because too many files changed in this diff