Browse Source

Merge branch 'camera-clone-method' of https://github.com/Slayvin/three.js into dev

Mr.doob 12 years ago
parent
commit
5f02d65994
3 changed files with 48 additions and 0 deletions
  1. 13 0
      src/cameras/Camera.js
  2. 19 0
      src/cameras/OrthographicCamera.js
  3. 16 0
      src/cameras/PerspectiveCamera.js

+ 13 - 0
src/cameras/Camera.js

@@ -32,3 +32,16 @@ THREE.Camera.prototype.lookAt = function () {
 	};
 	};
 
 
 }();
 }();
+
+THREE.Camera.prototype.clone = function (camera) {
+
+	if ( camera === undefined ) camera = new THREE.Camera();
+
+	THREE.Object3D.prototype.clone.call( this, camera );
+
+	camera.matrixWorldInverse.copy(this.matrixWorldInverse);
+	camera.projectionMatrix.copy(this.projectionMatrix);
+	camera.projectionMatrixInverse.copy(this.projectionMatrixInverse);
+
+	return camera;
+};

+ 19 - 0
src/cameras/OrthographicCamera.js

@@ -25,3 +25,22 @@ THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
 	this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far );
 	this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far );
 
 
 };
 };
+
+THREE.OrthographicCamera.prototype.clone = function () {
+
+	var camera = new THREE.OrthographicCamera();
+
+	THREE.Camera.prototype.clone.call( this, camera );
+
+	camera.left = this.left;
+	camera.right = this.right;
+	camera.top = this.top;
+	camera.bottom = this.bottom;
+	
+	camera.near = this.near;
+	camera.far = this.far;
+	
+	camera.updateProjectionMatrix();
+
+	return camera;
+};

+ 16 - 0
src/cameras/PerspectiveCamera.js

@@ -114,3 +114,19 @@ THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
 	}
 	}
 
 
 };
 };
+
+THREE.PerspectiveCamera.prototype.clone = function () {
+
+	var camera = new THREE.PerspectiveCamera();
+
+	THREE.Camera.prototype.clone.call( this, camera );
+
+	camera.fov = this.fov;
+	camera.aspect = this.aspect;
+	camera.near = this.near;
+	camera.far = this.far;
+	
+	camera.updateProjectionMatrix();
+
+	return camera;
+};