提交 d99ce611 编写于 作者: W WestLangley

Added Object.rotateOnAxis() and Object.translateOnAxis()

上级 2c8c1b8a
......@@ -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 );
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册