Browse Source

Matrix4.compose -> makeFromPositionQuaternionScale, add Matrix4.makeFromPositionEulerScale().

Ben Houston 12 năm trước cách đây
mục cha
commit
715ed487a8

+ 6 - 1
docs/api/math/Matrix4.html

@@ -195,11 +195,16 @@
 		Multiplies the columns of this matrix by vector *v*.
 		</div>
 
-		<h3>.compose( [page:Vector3 translation], [page:Quaternion rotation], [page:Vector3 scale] ) [page:Matrix4]</h3>
+		<h3>.makeFromPositionQuaternionScale( [page:Vector3 translation], [page:Quaternion rotation], [page:Vector3 scale] ) [page:Matrix4]</h3>
 		<div>
 		Sets this matrix to the transformation composed of *translation*, *rotation* and *scale*.
 		</div>
 
+		<h3>.makeFromPositionEulerScale( [page:Vector3 translation], [page:Vector3 rotation], eulerOrder, [page:Vector3 scale] ) [page:Matrix4]</h3>
+		<div>
+		Sets this matrix to the transformation composed of *translation*, *rotation* (as euler angle triple and order) and *scale*.
+		</div>
+
 		<h3>.decompose( [page:Vector3 translation], [page:Quaternion rotation], [page:Vector3 scale] ) [page:Array]</h3>
 		<div>
 		Decomposes this matrix into the *translation*, *rotation* and *scale* components.<br />

+ 5 - 2
src/core/Object3D.js

@@ -319,11 +319,14 @@ THREE.Object3D.prototype = {
 		// if we are not using a quaternion directly, convert Euler rotation to this.quaternion.
 		if ( this.useQuaternion === false )  {
 
-			this.quaternion.setFromEuler( this.rotation, this.eulerOrder );
+			this.matrix.makeFromPositionEulerScale( this.position, this.rotation, this.eulerOrder, this.scale );
 
 		} 
+		else {
 		
-		this.matrix.compose( this.position, this.quaternion, this.scale );
+			this.matrix.makeFromPositionQuaternionScale( this.position, this.quaternion, this.scale );
+
+		}
 
 		this.matrixWorldNeedsUpdate = true;
 

+ 1 - 1
src/extras/core/Gyroscope.js

@@ -25,7 +25,7 @@ THREE.Gyroscope.prototype.updateMatrixWorld = function ( force ) {
 			this.matrixWorld.decompose( this.translationWorld, this.rotationWorld, this.scaleWorld );
 			this.matrix.decompose( this.translationObject, this.rotationObject, this.scaleObject );
 
-			this.matrixWorld.compose( this.translationWorld, this.rotationObject, this.scaleWorld );
+			this.matrixWorld.makeFromPositionQuaternionScale( this.translationWorld, this.rotationObject, this.scaleWorld );
 
 
 		} else {

+ 21 - 1
src/math/Matrix4.js

@@ -894,7 +894,7 @@ THREE.Matrix4.prototype = {
 
 THREE.extend( THREE.Matrix4.prototype, {
 
-	compose: function ( position, quaternion, scale ) {
+	makeFromPositionQuaternionScale: function ( position, quaternion, scale ) {
 
 		var te = this.elements;
 
@@ -914,6 +914,26 @@ THREE.extend( THREE.Matrix4.prototype, {
 
 	},
 
+	makeFromPositionEulerScale: function ( position, rotation, eulerOrder, scale ) {
+
+		var te = this.elements;
+
+		this.makeRotationFromEuler( rotation, eulerOrder );
+	
+		if ( scale.x !== 1 || scale.y !== 1 || scale.z !== 1 ) {
+
+			this.scale( scale );
+
+		}
+		
+		te[12] = position.x;
+		te[13] = position.y;
+		te[14] = position.z;
+
+		return this;
+
+	},
+
 	decompose: function() {
 
 		var x = new THREE.Vector3();

+ 1 - 1
src/objects/Sprite.js

@@ -24,7 +24,7 @@ THREE.Sprite.prototype.updateMatrix = function () {
 
 	this.rotation3d.set( 0, 0, this.rotation );
 	this.quaterion.setFromEuler( this.rotation3d, this.eulerOrder );
-	this.matrix.compose( this.position, this.quaternion, this.scale );
+	this.matrix.makeFromPositionQuaternionScale( this.position, this.quaternion, this.scale );
 
 	this.matrixWorldNeedsUpdate = true;