Browse Source

Added translate( distance, axis ), translateX( distance ), translateY( distance ) and translateZ( distance ) methods to Object3D.
Camera3D translate method overrides Object3D's one. NoFly parameter removed (this should be handled from outside I think).

Mr.doob 14 years ago
parent
commit
c89b4008f3

+ 0 - 0
examples/misc_lookAt.html → examples/misc_lookat.html


+ 0 - 2
examples/webgl_performance.html

@@ -144,8 +144,6 @@
 
 
 				}
 				}
 
 
-				scene.matrixAutoUpdate = false;
-
 				renderer = new THREE.WebGLRenderer();
 				renderer = new THREE.WebGLRenderer();
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.sortObjects = false;
 				renderer.sortObjects = false;

+ 9 - 25
src/cameras/Camera.js

@@ -20,39 +20,23 @@ THREE.Camera = function ( fov, aspect, near, far, target ) {
 
 
 	this.updateProjectionMatrix();
 	this.updateProjectionMatrix();
 
 
-	// movement
-
-	var vector = new THREE.Vector3();
-
-	this.translateX = function ( amount, noFly ) {
-
-		vector.sub( this.target.position, this.position ).normalize().multiplyScalar( amount );
-		vector.crossSelf( this.up );
-
-		if ( noFly ) vector.y = 0;
-
-		this.position.addSelf( vector );
-		this.target.position.addSelf( vector );
-
-	};
+}
 
 
-	this.translateZ = function ( amount, noFly ) {
+THREE.Camera.prototype = new THREE.Object3D();
+THREE.Camera.prototype.constructor = THREE.Camera;
+THREE.Camera.prototype.supr = THREE.Object3D.prototype;
 
 
-		vector.sub( this.target.position, this.position ).normalize().multiplyScalar( amount );
 
 
-		if ( noFly ) vector.y = 0;
+// Overrides Object3D::translate()
 
 
-		this.position.subSelf( vector );
-		this.target.position.subSelf( vector );
+THREE.Camera.prototype.translate = function ( distance, axis ) {
 
 
-	};
+	this.matrix.rotateAxis( axis );
+	this.position.addSelf( axis.multiplyScalar( distance ) );
+	this.target.position.addSelf( axis.multiplyScalar( distance ) );
 
 
 }
 }
 
 
-THREE.Camera.prototype = new THREE.Object3D();
-THREE.Camera.prototype.constructor = THREE.Camera;
-THREE.Camera.prototype.supr = THREE.Object3D.prototype;
-
 
 
 THREE.Camera.prototype.updateProjectionMatrix = function () {
 THREE.Camera.prototype.updateProjectionMatrix = function () {
 
 

+ 18 - 6
src/core/Matrix4.js

@@ -75,9 +75,9 @@ THREE.Matrix4.prototype = {
 		x.cross( up, z ).normalize();
 		x.cross( up, z ).normalize();
 		y.cross( z, x ).normalize();
 		y.cross( z, x ).normalize();
 
 
-		this.n11 = x.x; this.n12 = y.x; this.n13 = z.x; // this.n14 = eye.x;
-		this.n21 = x.y; this.n22 = y.y; this.n23 = z.y; // this.n24 = eye.y;
-		this.n31 = x.z; this.n32 = y.z; this.n33 = z.z; // this.n34 = eye.z;
+		this.n11 = x.x; this.n12 = y.x; this.n13 = z.x;
+		this.n21 = x.y; this.n22 = y.y; this.n23 = z.y;
+		this.n31 = x.z; this.n32 = y.z; this.n33 = z.z;
 
 
 		return this;
 		return this;
 
 
@@ -118,6 +118,20 @@ THREE.Matrix4.prototype = {
 
 
 	},
 	},
 
 
+	rotateAxis : function ( v ) {
+
+		var vx = v.x, vy = v.y, vz = v.z;
+
+		v.x = vx * this.n11 + vy * this.n12 + vz * this.n13;
+		v.y = vx * this.n21 + vy * this.n22 + vz * this.n23;
+		v.z = vx * this.n31 + vy * this.n32 + vz * this.n33;
+
+		v.normalize();
+
+		return v;
+
+	},
+
 	crossVector : function ( a ) {
 	crossVector : function ( a ) {
 
 
 		var v = new THREE.Vector4();
 		var v = new THREE.Vector4();
@@ -583,9 +597,7 @@ THREE.Matrix4.makeInvert3x3 = function ( m1 ) {
 	// input:  THREE.Matrix4, output: THREE.Matrix3
 	// input:  THREE.Matrix4, output: THREE.Matrix3
 	// ( based on http://code.google.com/p/webgl-mjs/ )
 	// ( based on http://code.google.com/p/webgl-mjs/ )
 
 
-	var m33 = m1.m33,
-		m33m = m33.m,
-
+	var m33 = m1.m33, m33m = m33.m,
 	a11 =   m1.n33 * m1.n22 - m1.n32 * m1.n23,
 	a11 =   m1.n33 * m1.n22 - m1.n32 * m1.n23,
 	a21 = - m1.n33 * m1.n21 + m1.n31 * m1.n23,
 	a21 = - m1.n33 * m1.n21 + m1.n31 * m1.n23,
 	a31 =   m1.n32 * m1.n21 - m1.n31 * m1.n22,
 	a31 =   m1.n32 * m1.n21 - m1.n31 * m1.n22,

+ 17 - 10
src/core/Object3D.js

@@ -9,11 +9,11 @@ THREE.Object3D = function() {
 	this.parent = undefined;
 	this.parent = undefined;
 	this.children = [];
 	this.children = [];
 
 
-	this.up = new THREE.Vector3( 0.0, 1.0, 0.0 );
+	this.up = new THREE.Vector3( 0, 1, 0 );
 
 
 	this.position = new THREE.Vector3();
 	this.position = new THREE.Vector3();
 	this.rotation = new THREE.Vector3();
 	this.rotation = new THREE.Vector3();
-	this.scale = new THREE.Vector3( 1.0, 1.0, 1.0 );
+	this.scale = new THREE.Vector3( 1, 1, 1 );
 
 
 	this.rotationAutoUpdate = true;
 	this.rotationAutoUpdate = true;
 
 
@@ -32,30 +32,37 @@ THREE.Object3D = function() {
 
 
 	this.visible = true;
 	this.visible = true;
 
 
+	this._vector = new THREE.Vector3();
+
 };
 };
 
 
 
 
 THREE.Object3D.prototype = {
 THREE.Object3D.prototype = {
 
 
-	/*
-	translateX : function () {
+	translate : function ( distance, axis ) {
+
+		this.matrix.rotateAxis( axis );
+		this.position.addSelf( axis.multiplyScalar( distance ) );
+
+	},
+
+	translateX : function ( distance ) {
 
 
-		
+		this.translate( distance, this._vector.set( 1, 0, 0 ) );
 
 
 	},
 	},
 
 
-	translateY : function () {
+	translateY : function ( distance ) {
 
 
-		
+		this.translate( distance, this._vector.set( 0, 1, 0 ) );
 
 
 	},
 	},
 
 
-	translateZ : function () {
+	translateZ : function ( distance ) {
 
 
-		
+		this.translate( distance, this._vector.set( 0, 0, 1 ) );
 
 
 	},
 	},
-	*/
 
 
 	lookAt : function ( vector ) {
 	lookAt : function ( vector ) {
 
 

+ 4 - 4
src/core/Vector3.js

@@ -292,12 +292,12 @@ THREE.Vector3.prototype = {
 
 
 		this.y = Math.asin( m.n13 );
 		this.y = Math.asin( m.n13 );
 
 
-		var yc = Math.cos( this.y );
+		var cosY = Math.cos( this.y );
 
 
-		if ( Math.abs( yc ) > 0.00001 ) {
+		if ( Math.abs( cosY ) > 0.00001 ) {
 
 
-			this.x = Math.atan2( - m.n23 / yc, m.n33 / yc );
-			this.z = Math.atan2( - m.n13 / yc, m.n11 / yc );
+			this.x = Math.atan2( - m.n23 / cosY, m.n33 / cosY );
+			this.z = Math.atan2( - m.n13 / cosY, m.n11 / cosY );
 
 
 		} else {
 		} else {