Quaternion.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { Euler } from './Euler';
  2. import { Vector3 } from './Vector3';
  3. import { Matrix4 } from './Matrix4';
  4. /**
  5. * Implementation of a quaternion. This is used for rotating things without incurring in the dreaded gimbal lock issue, amongst other advantages.
  6. *
  7. * @example
  8. * const quaternion = new THREE.Quaternion();
  9. * quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 );
  10. * const vector = new THREE.Vector3( 1, 0, 0 );
  11. * vector.applyQuaternion( quaternion );
  12. */
  13. export class Quaternion {
  14. /**
  15. * @param x x coordinate
  16. * @param y y coordinate
  17. * @param z z coordinate
  18. * @param w w coordinate
  19. */
  20. constructor( x?: number, y?: number, z?: number, w?: number );
  21. /**
  22. * @default 0
  23. */
  24. x: number;
  25. /**
  26. * @default 0
  27. */
  28. y: number;
  29. /**
  30. * @default 0
  31. */
  32. z: number;
  33. /**
  34. * @default 1
  35. */
  36. w: number;
  37. readonly isQuaternion: true;
  38. /**
  39. * Sets values of this quaternion.
  40. */
  41. set( x: number, y: number, z: number, w: number ): Quaternion;
  42. /**
  43. * Clones this quaternion.
  44. */
  45. clone(): Quaternion;
  46. /**
  47. * Copies values of q to this quaternion.
  48. */
  49. copy( q: Quaternion ): this;
  50. /**
  51. * Sets this quaternion from rotation specified by Euler angles.
  52. */
  53. setFromEuler( euler: Euler ): Quaternion;
  54. /**
  55. * Sets this quaternion from rotation specified by axis and angle.
  56. * Adapted from http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm.
  57. * Axis have to be normalized, angle is in radians.
  58. */
  59. setFromAxisAngle( axis: Vector3, angle: number ): Quaternion;
  60. /**
  61. * Sets this quaternion from rotation component of m. Adapted from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm.
  62. */
  63. setFromRotationMatrix( m: Matrix4 ): Quaternion;
  64. setFromUnitVectors( vFrom: Vector3, vTo: Vector3 ): Quaternion;
  65. angleTo( q: Quaternion ): number;
  66. rotateTowards( q: Quaternion, step: number ): Quaternion;
  67. identity(): Quaternion;
  68. /**
  69. * Inverts this quaternion.
  70. */
  71. invert(): Quaternion;
  72. conjugate(): Quaternion;
  73. dot( v: Quaternion ): number;
  74. lengthSq(): number;
  75. /**
  76. * Computes length of this quaternion.
  77. */
  78. length(): number;
  79. /**
  80. * Normalizes this quaternion.
  81. */
  82. normalize(): Quaternion;
  83. /**
  84. * Multiplies this quaternion by b.
  85. */
  86. multiply( q: Quaternion ): Quaternion;
  87. premultiply( q: Quaternion ): Quaternion;
  88. /**
  89. * Sets this quaternion to a x b
  90. * Adapted from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm.
  91. */
  92. multiplyQuaternions( a: Quaternion, b: Quaternion ): Quaternion;
  93. slerp( qb: Quaternion, t: number ): Quaternion;
  94. equals( v: Quaternion ): boolean;
  95. /**
  96. * Sets this quaternion's x, y, z and w value from the provided array.
  97. * @param array the source array.
  98. * @param offset (optional) offset into the array. Default is 0.
  99. */
  100. fromArray( array: number[], offset?: number ): this;
  101. /**
  102. * Sets this quaternion's x, y, z and w value from the provided array-like.
  103. * @param array the source array-like.
  104. * @param offset (optional) offset into the array-like. Default is 0.
  105. */
  106. fromArray( array: ArrayLike<number>, offset?: number ): this;
  107. /**
  108. * Returns an array [x, y, z, w], or copies x, y, z and w into the provided array.
  109. * @param array (optional) array to store the quaternion to. If this is not provided, a new array will be created.
  110. * @param offset (optional) optional offset into the array.
  111. * @return The created or provided array.
  112. */
  113. toArray( array?: number[], offset?: number ): number[];
  114. /**
  115. * Copies x, y, z and w into the provided array-like.
  116. * @param array array-like to store the quaternion to.
  117. * @param offset (optional) optional offset into the array.
  118. * @return The provided array-like.
  119. */
  120. toArray( array: ArrayLike<number>, offset?: number ): ArrayLike<number>;
  121. _onChange( callback: Function ): Quaternion;
  122. _onChangeCallback: Function;
  123. /**
  124. * Adapted from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/.
  125. */
  126. static slerp(
  127. qa: Quaternion,
  128. qb: Quaternion,
  129. qm: Quaternion,
  130. t: number
  131. ): Quaternion;
  132. static slerpFlat(
  133. dst: number[],
  134. dstOffset: number,
  135. src0: number[],
  136. srcOffset: number,
  137. src1: number[],
  138. stcOffset1: number,
  139. t: number
  140. ): Quaternion;
  141. static multiplyQuaternionsFlat(
  142. dst: number[],
  143. dstOffset: number,
  144. src0: number[],
  145. srcOffset: number,
  146. src1: number[],
  147. stcOffset1: number
  148. ): number[];
  149. /**
  150. * @deprecated Use {@link Vector#applyQuaternion vector.applyQuaternion( quaternion )} instead.
  151. */
  152. multiplyVector3( v: any ): any;
  153. /**
  154. * @deprecated Use {@link Quaternion#invert .invert()} instead.
  155. */
  156. inverse(): Quaternion;
  157. }