From d99ce611a139579b2e11e3bed8c9fdda1f601ca9 Mon Sep 17 00:00:00 2001 From: WestLangley Date: Wed, 20 Mar 2013 15:05:46 -0400 Subject: [PATCH] Added Object.rotateOnAxis() and Object.translateOnAxis() --- src/core/Object3D.js | 60 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 61a5301ee0..ca528db802 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -79,13 +79,46 @@ THREE.Object3D.prototype = { }(), - translate: function () { + rotateOnAxis: function() { - var v1 = new THREE.Vector3(); + // rotate object on axis in object space + // axis is assumed to be normalized + + var q1 = new THREE.Quaternion(); + var q2 = new THREE.Quaternion(); + + return function ( axis, angle ) { + + q1.setFromAxisAngle( axis, angle ); - return function ( distance, axis ) { + if ( this.useQuaternion === true ) { + + this.quaternion.multiply( q1 ); + + } else { - // axis is assumed to be normalized + q2.setFromEuler( this.rotation, this.eulerOrder ); + q2.multiply( q1 ); + + this.rotation.setEulerFromQuaternion( q2, this.eulerOrder ); + + } + + return this; + + } + + }(), + + translateOnAxis: function () { + + // translate object by distance along axis in object space + // axis is assumed to be normalized + + var v1 = new THREE.Vector3(); + var q1 = new THREE.Quaternion(); + + return function ( axis, distance ) { v1.copy( axis ); @@ -99,23 +132,28 @@ THREE.Object3D.prototype = { } - v1.multiplyScalar( distance ); - - this.position.add( v1 ); + this.position.add( v1.multiplyScalar( distance ) ); return this; - }; + } }(), + translate: function ( distance, axis ) { + + console.warn( 'DEPRECATED: Object3D\'s .translate() has been removed. Use .translateOnAxis( axis, distance ) instead. Note args have been changed.' ); + return this.translateOnAxis( axis, distance ); + + }, + translateX: function () { var v1 = new THREE.Vector3( 1, 0, 0 ); return function ( distance ) { - return this.translate( distance, v1 ); + return this.translateOnAxis( v1, distance ); }; @@ -127,7 +165,7 @@ THREE.Object3D.prototype = { return function ( distance ) { - return this.translate( distance, v1 ); + return this.translateOnAxis( v1, distance ); }; @@ -139,7 +177,7 @@ THREE.Object3D.prototype = { return function ( distance ) { - return this.translate( distance, v1 ); + return this.translateOnAxis( v1, distance ); }; -- GitLab