Matrix4.d.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import { Vector3 } from './Vector3';
  2. import { Euler } from './Euler';
  3. import { Quaternion } from './Quaternion';
  4. import { Matrix } from './Matrix3';
  5. /**
  6. * A 4x4 Matrix.
  7. *
  8. * @example
  9. * // Simple rig for rotating around 3 axes
  10. * const m = new THREE.Matrix4();
  11. * const m1 = new THREE.Matrix4();
  12. * const m2 = new THREE.Matrix4();
  13. * const m3 = new THREE.Matrix4();
  14. * const alpha = 0;
  15. * const beta = Math.PI;
  16. * const gamma = Math.PI/2;
  17. * m1.makeRotationX( alpha );
  18. * m2.makeRotationY( beta );
  19. * m3.makeRotationZ( gamma );
  20. * m.multiplyMatrices( m1, m2 );
  21. * m.multiply( m3 );
  22. */
  23. export class Matrix4 implements Matrix {
  24. constructor();
  25. /**
  26. * Array with matrix values.
  27. * @default [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
  28. */
  29. elements: number[];
  30. /**
  31. * Sets all fields of this matrix.
  32. */
  33. set(
  34. n11: number,
  35. n12: number,
  36. n13: number,
  37. n14: number,
  38. n21: number,
  39. n22: number,
  40. n23: number,
  41. n24: number,
  42. n31: number,
  43. n32: number,
  44. n33: number,
  45. n34: number,
  46. n41: number,
  47. n42: number,
  48. n43: number,
  49. n44: number
  50. ): Matrix4;
  51. /**
  52. * Resets this matrix to identity.
  53. */
  54. identity(): Matrix4;
  55. clone(): this;
  56. copy( m: Matrix4 ): this;
  57. copyPosition( m: Matrix4 ): Matrix4;
  58. extractBasis( xAxis: Vector3, yAxis: Vector3, zAxis: Vector3 ): Matrix4;
  59. makeBasis( xAxis: Vector3, yAxis: Vector3, zAxis: Vector3 ): Matrix4;
  60. /**
  61. * Copies the rotation component of the supplied matrix m into this matrix rotation component.
  62. */
  63. extractRotation( m: Matrix4 ): Matrix4;
  64. makeRotationFromEuler( euler: Euler ): Matrix4;
  65. makeRotationFromQuaternion( q: Quaternion ): Matrix4;
  66. /**
  67. * Constructs a rotation matrix, looking from eye towards center with defined up vector.
  68. */
  69. lookAt( eye: Vector3, target: Vector3, up: Vector3 ): Matrix4;
  70. /**
  71. * Multiplies this matrix by m.
  72. */
  73. multiply( m: Matrix4 ): Matrix4;
  74. premultiply( m: Matrix4 ): Matrix4;
  75. /**
  76. * Sets this matrix to a x b.
  77. */
  78. multiplyMatrices( a: Matrix4, b: Matrix4 ): Matrix4;
  79. /**
  80. * Sets this matrix to a x b and stores the result into the flat array r.
  81. * r can be either a regular Array or a TypedArray.
  82. *
  83. * @deprecated This method has been removed completely.
  84. */
  85. multiplyToArray( a: Matrix4, b: Matrix4, r: number[] ): Matrix4;
  86. /**
  87. * Multiplies this matrix by s.
  88. */
  89. multiplyScalar( s: number ): Matrix4;
  90. /**
  91. * Computes determinant of this matrix.
  92. * Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  93. */
  94. determinant(): number;
  95. /**
  96. * Transposes this matrix.
  97. */
  98. transpose(): Matrix4;
  99. /**
  100. * Sets the position component for this matrix from vector v.
  101. */
  102. setPosition( v: Vector3 | number, y?: number, z?: number ): Matrix4;
  103. /**
  104. * Inverts this matrix.
  105. */
  106. invert(): Matrix;
  107. /**
  108. * Multiplies the columns of this matrix by vector v.
  109. */
  110. scale( v: Vector3 ): Matrix4;
  111. getMaxScaleOnAxis(): number;
  112. /**
  113. * Sets this matrix as translation transform.
  114. */
  115. makeTranslation( x: number, y: number, z: number ): Matrix4;
  116. /**
  117. * Sets this matrix as rotation transform around x axis by theta radians.
  118. *
  119. * @param theta Rotation angle in radians.
  120. */
  121. makeRotationX( theta: number ): Matrix4;
  122. /**
  123. * Sets this matrix as rotation transform around y axis by theta radians.
  124. *
  125. * @param theta Rotation angle in radians.
  126. */
  127. makeRotationY( theta: number ): Matrix4;
  128. /**
  129. * Sets this matrix as rotation transform around z axis by theta radians.
  130. *
  131. * @param theta Rotation angle in radians.
  132. */
  133. makeRotationZ( theta: number ): Matrix4;
  134. /**
  135. * Sets this matrix as rotation transform around axis by angle radians.
  136. * Based on http://www.gamedev.net/reference/articles/article1199.asp.
  137. *
  138. * @param axis Rotation axis.
  139. * @param theta Rotation angle in radians.
  140. */
  141. makeRotationAxis( axis: Vector3, angle: number ): Matrix4;
  142. /**
  143. * Sets this matrix as scale transform.
  144. */
  145. makeScale( x: number, y: number, z: number ): Matrix4;
  146. /**
  147. * Sets this matrix to the transformation composed of translation, rotation and scale.
  148. */
  149. compose( translation: Vector3, rotation: Quaternion, scale: Vector3 ): Matrix4;
  150. /**
  151. * Decomposes this matrix into it's position, quaternion and scale components.
  152. */
  153. decompose(
  154. translation: Vector3,
  155. rotation: Quaternion,
  156. scale: Vector3
  157. ): Matrix4;
  158. /**
  159. * Creates a frustum matrix.
  160. */
  161. makePerspective(
  162. left: number,
  163. right: number,
  164. bottom: number,
  165. top: number,
  166. near: number,
  167. far: number
  168. ): Matrix4;
  169. /**
  170. * Creates a perspective projection matrix.
  171. */
  172. makePerspective(
  173. fov: number,
  174. aspect: number,
  175. near: number,
  176. far: number
  177. ): Matrix4;
  178. /**
  179. * Creates an orthographic projection matrix.
  180. */
  181. makeOrthographic(
  182. left: number,
  183. right: number,
  184. top: number,
  185. bottom: number,
  186. near: number,
  187. far: number
  188. ): Matrix4;
  189. equals( matrix: Matrix4 ): boolean;
  190. /**
  191. * Sets the values of this matrix from the provided array.
  192. * @param array the source array.
  193. * @param offset (optional) offset into the array. Default is 0.
  194. */
  195. fromArray( array: number[], offset?: number ): Matrix4;
  196. /**
  197. * Sets the values of this matrix from the provided array-like.
  198. * @param array the source array-like.
  199. * @param offset (optional) offset into the array-like. Default is 0.
  200. */
  201. fromArray( array: ArrayLike<number>, offset?: number ): Matrix4;
  202. /**
  203. * Returns an array with the values of this matrix, or copies them into the provided array.
  204. * @param array (optional) array to store the matrix to. If this is not provided, a new array will be created.
  205. * @param offset (optional) optional offset into the array.
  206. * @return The created or provided array.
  207. */
  208. toArray( array?: number[], offset?: number ): number[];
  209. /**
  210. * Copies he values of this matrix into the provided array-like.
  211. * @param array array-like to store the matrix to.
  212. * @param offset (optional) optional offset into the array-like.
  213. * @return The provided array-like.
  214. */
  215. toArray( array?: ArrayLike<number>, offset?: number ): ArrayLike<number>;
  216. /**
  217. * @deprecated Use {@link Matrix4#copyPosition .copyPosition()} instead.
  218. */
  219. extractPosition( m: Matrix4 ): Matrix4;
  220. /**
  221. * @deprecated Use {@link Matrix4#makeRotationFromQuaternion .makeRotationFromQuaternion()} instead.
  222. */
  223. setRotationFromQuaternion( q: Quaternion ): Matrix4;
  224. /**
  225. * @deprecated Use {@link Vector3#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  226. */
  227. multiplyVector3( v: any ): any;
  228. /**
  229. * @deprecated Use {@link Vector4#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  230. */
  231. multiplyVector4( v: any ): any;
  232. /**
  233. * @deprecated This method has been removed completely.
  234. */
  235. multiplyVector3Array( array: number[] ): number[];
  236. /**
  237. * @deprecated Use {@link Vector3#transformDirection Vector3.transformDirection( matrix )} instead.
  238. */
  239. rotateAxis( v: any ): void;
  240. /**
  241. * @deprecated Use {@link Vector3#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  242. */
  243. crossVector( v: any ): void;
  244. /**
  245. * @deprecated Use {@link Matrix4#toArray .toArray()} instead.
  246. */
  247. flattenToArrayOffset( array: number[], offset: number ): number[];
  248. /**
  249. * @deprecated Use {@link Matrix4#invert .invert()} instead.
  250. */
  251. getInverse( matrix: Matrix ): Matrix;
  252. }
粤ICP备19079148号