Browse Source

Added identity()

WestLangley 5 years ago
parent
commit
da41d95dec

+ 5 - 0
docs/api/en/math/Quaternion.html

@@ -98,6 +98,11 @@
 		from an array.
 		</p>
 
+		<h3>[method:Quaternion identity]()</h3>
+		<p>
+			Sets this quaternion to the identity quaternion; that is, to the quaternion that represents "no rotation".
+		</p>
+
 		<h3>[method:Quaternion inverse]()</h3>
 		<p>
 			Inverts this quaternion - calculates the [page:.conjugate conjugate]. The quaternion is assumed to have unit length.

+ 5 - 0
docs/api/zh/math/Quaternion.html

@@ -98,6 +98,11 @@
 		from an array.
 		</p>
 
+		<h3>[method:Quaternion identity]()</h3>
+		<p>
+			Sets this quaternion to the identity quaternion; that is, to the quaternion that represents "no rotation".
+		</p>
+
 		<h3>[method:Quaternion inverse]()</h3>
 		<p>
 			Inverts this quaternion - calculates the [page:.conjugate conjugate]. The quaternion is assumed to have unit length.

+ 2 - 0
src/math/Quaternion.d.ts

@@ -62,6 +62,8 @@ export class Quaternion {
 	angleTo( q: Quaternion ): number;
 	rotateTowards( q: Quaternion, step: number ): Quaternion;
 
+	identity(): Quaternion;
+
 	/**
 	 * Inverts this quaternion.
 	 */

+ 6 - 0
src/math/Quaternion.js

@@ -437,6 +437,12 @@ Object.assign( Quaternion.prototype, {
 
 	},
 
+	identity: function () {
+
+		return this.set( 0, 0, 0, 1 );
+
+	},
+
 	inverse: function () {
 
 		// quaternion is assumed to have unit length

+ 14 - 0
test/unit/src/math/Quaternion.tests.js

@@ -528,6 +528,20 @@ export default QUnit.module( 'Maths', () => {
 
 		} );
 
+		QUnit.test( "identity", ( assert ) => {
+
+			var a = new Quaternion();
+
+			a.set( x, y, z, w );
+			a.identity();
+
+			assert.ok( a.x == 0, "Passed!" );
+			assert.ok( a.y == 0, "Passed!" );
+			assert.ok( a.z === 0, "Passed!" );
+			assert.ok( a.w === 1, "Passed!" );
+
+		} );
+
 		QUnit.test( "inverse/conjugate", ( assert ) => {
 
 			var a = new Quaternion( x, y, z, w );