Browse Source

Docs: Quaternion.

Mr.doob 13 years ago
parent
commit
5030e6e1d2
4 changed files with 119 additions and 204 deletions
  1. 1 1
      docs/api/core/Matrix4.html
  2. 91 7
      docs/api/core/Quaternion.html
  3. 0 169
      docs/api/core/Quaternion.rst
  4. 27 27
      src/core/Quaternion.js

+ 1 - 1
docs/api/core/Matrix4.html

@@ -303,7 +303,7 @@ Clones this matrix.
 </div>
 
 
-<h2>Static Methods</h2>
+<h2>Static methods</h2>
 
 <h3>.makeInvert3x3( [page:Matrix4 m] ) [page:Matrix3]</h3>
 <div>

+ 91 - 7
docs/api/core/Quaternion.html

@@ -3,27 +3,103 @@
 <div class="desc">Implementation of a quaternion</div>
 
 
+<h2>Example</h2>
+
+<code>var q = new THREE.Quaternion();
+q.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 );
+
+var v = new THREE.Vector3( 1, 0, 0 );
+q.multiplyVector3( v );
+</code>
+
+
 <h2>Constructor</h2>
 
-<h3>[name]( [page:Number x], [page:Number y], [page:Number z], [page:Number w] )</h3>
+<h3>[name]( [page:Float x], [page:Float y], [page:Float z], [page:Float w] )</h3>
+<div>
+x - x coordinate<br />
+y - y coordinate<br />
+z - z coordinate<br />
+w - w coordinate
+</div>
 
 
 <h2>Properties</h2>
 
-<h3>.[page:Number x]</h3>
+<h3>.[page:Float x]</h3>
 
-<h3>.[page:Number y]</h3>
+<h3>.[page:Float y]</h3>
 
-<h3>.[page:Number z]</h3>
+<h3>.[page:Float z]</h3>
 
-<h3>.[page:Number w]</h3>
+<h3>.[page:Float w]</h3>
 
 
 <h2>Methods</h2>
 
-<h3>.copy( q ) [page:Quaternion]</h3>
+<h3>.set( [page:Float x], [page:Float y], [page:Float z], [page:Float w] ) [page:Quaternion]</h3>
+<div>
+Sets values of this quaternion.
+</div>
+
+<h3>.copy( [page:Quaternion q] ) [page:Quaternion]</h3>
+<div>
+Copies values of *q* to this quaternion.
+</div>
+
+<h3>.setFromEuler( [page:Vector3 vector] ) [page:Quaternion]</h3>
+<div>
+Sets this quaternion from rotation specified by Euler angles.
+</div>
+
+<h3>.setFromAxisAngle( [page:Vector3 axis], [page:Float angle] ) [page:Quaternion]</h3>
+<div>
+Sets this quaternion from rotation specified by axis and angle.<br />
+Adapted from [link:http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm].<br />
+*Axis* have to be normalized, *angle* is in radians.
+</div>
+
+<h3>.setFromRotationMatrix( [page:Matrix4 m] ) [page:Quaternion]</h3>
+<div>
+Sets this quaternion from rotation component of *m*.
+Adapted from [link:http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm].
+</div>
+
+<h3>.calculateW() [page:Quaternion]</h3>
+<div>
+Calculates *w* component of this quaternion.
+</div>
+
+<h3>.inverse() [page:Quaternion]</h3>
+<div>
+Inverts this quaternion.
+</div>
+
+<h3>.length() [page:Float]</h3>
+<div>
+Computes length of this quaternion.
+</div>
+
+<h3>.normalize() [page:Quaternion]</h3>
+<div>
+Normalizes this quaternion.
+</div>
+
+<h3>.multiply( [page:Quaternion a], [page:Quaternion b] ) [page:Quaternion]</h3>
 <div>
-Copies value of *q* to this quaternion.
+Sets this quaternion to *a x b*<br />
+Adapted from [link:http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm].
+</div>
+
+<h3>.multiplySelf( [page:Quaternion b] ) [page:Quaternion]</h3>
+<div>
+Multiplies this quaternion by *b*.
+</div>
+
+<h3>.multiplyVector3( [page:Vector3 vector], [page:Vector3 dest] ) [page:Quaternion]</h3>
+<div>
+Rotates *vector* by this quaternion into *dest*.<br />
+If *dest* is not specified, result goes to *vec*.
 </div>
 
 <h3>.clone() [page:Quaternion]</h3>
@@ -32,6 +108,14 @@ Clones this quaternion.
 </div>
 
 
+<h2>Static methods</h2>
+
+<h3>.slerp( [page:Quaternion qa], [page:Quaternion qb], [page:Quaternion qm], [page:Float t] ) [page:Quaternion]</h3>
+<div>
+Adapted from [link:http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/].
+</div>
+
+
 <h2>Source</h2>
 
 [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

+ 0 - 169
docs/api/core/Quaternion.rst

@@ -1,169 +0,0 @@
-Quaternion - Implementation of a quaternion
--------------------------------------------
-
-.. ...............................................................................
-.. rubric:: Constructor
-.. ...............................................................................
-
-.. class:: Quaternion( x, y, z, w )
-
-    Implementation of a quaternion
-
-    :param float x: x-coordinate
-    :param float y: y-coordinate
-    :param float z: z-coordinate
-    :param float w: w-coordinate
-
-.. ...............................................................................
-.. rubric:: Attributes
-.. ...............................................................................
-
-.. attribute:: Quaternion.x
-
-    float - default ``0``
-
-.. attribute:: Quaternion.y
-
-    float - default ``0``
-
-.. attribute:: Quaternion.z
-
-    float - default ``0``
-
-.. attribute:: Quaternion.w
-
-    float - default ``1``
-
-.. ...............................................................................
-.. rubric:: Methods
-.. ...............................................................................
-
-.. function:: Quaternion.clone( )
-
-    Clones this quaternion
-
-    :returns: New instance identical to this quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.set( x, y, z, w )
-
-    Sets value of this vector
-
-    :param float x: x-coordinate
-    :param float y: y-coordinate
-    :param float z: z-coordinate
-    :param float w: w-coordinate
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.copy( q )
-
-    Copies value of ``q`` to this quaternion
-
-    :param Quaternion v: source quaternion
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.setFromEuler ( vec3 )
-
-    Sets this quaternion from rotation specified by Euler angles
-
-    Angles are in degrees
-
-    :param Vector3 vec3: Euler angles vector
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.setFromAxisAngle ( axis, angle )
-
-    Sets this quaternion from rotation specified by axis and angle
-
-    Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
-
-    Axis have to be normalized, angle is in radians
-
-    :param Vector3 axis: axis vector
-    :param float angle: angle
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.setFromRotationMatrix ( m )
-
-    Sets this quaternion from rotation specified by matrix
-
-    Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
-
-    :param Matrix4 m: rotation matrix
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.calculateW( )
-
-    Calculates ``w`` component of this quaternion
-
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.inverse( )
-
-    Inverts this quaternion
-
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.length( )
-
-    Computes length of this quaternion
-
-    :returns: length
-    :rtype: float
-
-.. function:: Quaternion.normalize( )
-
-    Normalizes this quaternion
-
-    :returns: This vector
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.multiplySelf( quat2 )
-
-    Multiplies this quaternion by ``quat2``
-
-    :param Quaternion quat2: quaternion
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.multiply( q1, q2 )
-
-    Sets this quaternion to ``q1 * q2``
-
-    Adapted from: http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
-
-    :param Quaternion q1: quaternion 1
-    :param Quaternion q2: quaternion 2
-    :returns: This quaternion
-    :rtype: :class:`Quaternion`
-
-.. function:: Quaternion.multiplyVector3( vec, dest )
-
-    Rotates ``vec`` by this quaternion into ``dest``
-
-    If ``dest`` is not specified, result goes to ``vec``
-
-    :param Vector3 vec: source vector
-    :param Vector3 dest: destination vector
-    :returns: Rotated vector
-    :rtype: :class:`Vector3`
-
-
-.. ...............................................................................
-.. rubric:: Example
-.. ...............................................................................
-
-::
-
-    var q = new THREE.Quaternion();
-    q.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 );
-
-    var v = new THREE.Vector3( 1, 0, 0 );
-    q.multiplyVector3( v );

+ 27 - 27
src/core/Quaternion.js

@@ -38,18 +38,12 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	clone: function () {
-
-		return new THREE.Quaternion( this.x, this.y, this.z, this.w );
-
-	},
-
-	setFromEuler: function ( vec3 ) {
+	setFromEuler: function ( vector ) {
 
 		var c = Math.PI / 360, // 0.5 * Math.PI / 360, // 0.5 is an optimization
-		x = vec3.x * c,
-		y = vec3.y * c,
-		z = vec3.z * c,
+		x = vector.x * c,
+		y = vector.y * c,
+		z = vector.z * c,
 
 		c1 = Math.cos( y  ),
 		s1 = Math.sin( y  ),
@@ -161,41 +155,41 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	multiplySelf: function ( quat2 ) {
+	multiply: function ( a, b ) {
 
-		var qax = this.x,  qay = this.y,  qaz = this.z,  qaw = this.w,
-		qbx = quat2.x, qby = quat2.y, qbz = quat2.z, qbw = quat2.w;
+		// from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
 
-		this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
-		this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
-		this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
-		this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
+		this.x =  a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x;
+		this.y = -a.x * b.z + a.y * b.w + a.z * b.x + a.w * b.y;
+		this.z =  a.x * b.y - a.y * b.x + a.z * b.w + a.w * b.z;
+		this.w = -a.x * b.x - a.y * b.y - a.z * b.z + a.w * b.w;
 
 		return this;
 
 	},
 
-	multiply: function ( q1, q2 ) {
+	multiplySelf: function ( b ) {
 
-		// from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
+		var qax = this.x, qay = this.y, qaz = this.z, qaw = this.w,
+		qbx = b.x, qby = b.y, qbz = b.z, qbw = b.w;
 
-		this.x =  q1.x * q2.w + q1.y * q2.z - q1.z * q2.y + q1.w * q2.x;
-		this.y = -q1.x * q2.z + q1.y * q2.w + q1.z * q2.x + q1.w * q2.y;
-		this.z =  q1.x * q2.y - q1.y * q2.x + q1.z * q2.w + q1.w * q2.z;
-		this.w = -q1.x * q2.x - q1.y * q2.y - q1.z * q2.z + q1.w * q2.w;
+		this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
+		this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
+		this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
+		this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
 
 		return this;
 
 	},
 
-	multiplyVector3: function ( vec, dest ) {
+	multiplyVector3: function ( vector, dest ) {
 
-		if ( !dest ) { dest = vec; }
+		if ( !dest ) { dest = vector; }
 
-		var x    = vec.x,  y  = vec.y,  z  = vec.z,
+		var x    = vector.x,  y  = vector.y,  z  = vector.z,
 			qx   = this.x, qy = this.y, qz = this.z, qw = this.w;
 
-		// calculate quat * vec
+		// calculate quat * vector
 
 		var ix =  qw * x + qy * z - qz * y,
 			iy =  qw * y + qz * x - qx * z,
@@ -210,6 +204,12 @@ THREE.Quaternion.prototype = {
 
 		return dest;
 
+	},
+
+	clone: function () {
+
+		return new THREE.Quaternion( this.x, this.y, this.z, this.w );
+
 	}
 
 }