Matrix4.d.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import { Vector3 } from './Vector3';
  2. import { Euler } from './Euler';
  3. import { Quaternion } from './Quaternion';
  4. import { BufferAttribute } from './../core/BufferAttribute';
  5. import { Matrix } from './Matrix3';
  6. /**
  7. * A 4x4 Matrix.
  8. *
  9. * @example
  10. * // Simple rig for rotating around 3 axes
  11. * var m = new THREE.Matrix4();
  12. * var m1 = new THREE.Matrix4();
  13. * var m2 = new THREE.Matrix4();
  14. * var m3 = new THREE.Matrix4();
  15. * var alpha = 0;
  16. * var beta = Math.PI;
  17. * var gamma = Math.PI/2;
  18. * m1.makeRotationX( alpha );
  19. * m2.makeRotationY( beta );
  20. * m3.makeRotationZ( gamma );
  21. * m.multiplyMatrices( m1, m2 );
  22. * m.multiply( m3 );
  23. */
  24. export class Matrix4 implements Matrix {
  25. constructor();
  26. /**
  27. * Array with matrix values.
  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. * Sets this matrix to the inverse of matrix m.
  105. * Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm.
  106. */
  107. getInverse( m: Matrix4, throwOnDegeneratee?: boolean ): Matrix4;
  108. /**
  109. * Multiplies the columns of this matrix by vector v.
  110. */
  111. scale( v: Vector3 ): Matrix4;
  112. getMaxScaleOnAxis(): number;
  113. /**
  114. * Sets this matrix as translation transform.
  115. */
  116. makeTranslation( x: number, y: number, z: number ): Matrix4;
  117. /**
  118. * Sets this matrix as rotation transform around x axis by theta radians.
  119. *
  120. * @param theta Rotation angle in radians.
  121. */
  122. makeRotationX( theta: number ): Matrix4;
  123. /**
  124. * Sets this matrix as rotation transform around y axis by theta radians.
  125. *
  126. * @param theta Rotation angle in radians.
  127. */
  128. makeRotationY( theta: number ): Matrix4;
  129. /**
  130. * Sets this matrix as rotation transform around z axis by theta radians.
  131. *
  132. * @param theta Rotation angle in radians.
  133. */
  134. makeRotationZ( theta: number ): Matrix4;
  135. /**
  136. * Sets this matrix as rotation transform around axis by angle radians.
  137. * Based on http://www.gamedev.net/reference/articles/article1199.asp.
  138. *
  139. * @param axis Rotation axis.
  140. * @param theta Rotation angle in radians.
  141. */
  142. makeRotationAxis( axis: Vector3, angle: number ): Matrix4;
  143. /**
  144. * Sets this matrix as scale transform.
  145. */
  146. makeScale( x: number, y: number, z: number ): Matrix4;
  147. /**
  148. * Sets this matrix to the transformation composed of translation, rotation and scale.
  149. */
  150. compose( translation: Vector3, rotation: Quaternion, scale: Vector3 ): Matrix4;
  151. /**
  152. * Decomposes this matrix into the translation, rotation and scale components.
  153. * If parameters are not passed, new instances will be created.
  154. */
  155. decompose(
  156. translation?: Vector3,
  157. rotation?: Quaternion,
  158. scale?: Vector3
  159. ): Object[]; // [Vector3, Quaternion, Vector3]
  160. /**
  161. * Creates a frustum matrix.
  162. */
  163. makePerspective(
  164. left: number,
  165. right: number,
  166. bottom: number,
  167. top: number,
  168. near: number,
  169. far: number
  170. ): Matrix4;
  171. /**
  172. * Creates a perspective projection matrix.
  173. */
  174. makePerspective(
  175. fov: number,
  176. aspect: number,
  177. near: number,
  178. far: number
  179. ): Matrix4;
  180. /**
  181. * Creates an orthographic projection matrix.
  182. */
  183. makeOrthographic(
  184. left: number,
  185. right: number,
  186. top: number,
  187. bottom: number,
  188. near: number,
  189. far: number
  190. ): Matrix4;
  191. equals( matrix: Matrix4 ): boolean;
  192. /**
  193. * Sets the values of this matrix from the provided array.
  194. * @param array the source array.
  195. * @param offset (optional) offset into the array. Default is 0.
  196. */
  197. fromArray( array: number[], offset?: number ): Matrix4;
  198. /**
  199. * Sets the values of this matrix from the provided array-like.
  200. * @param array the source array-like.
  201. * @param offset (optional) offset into the array-like. Default is 0.
  202. */
  203. fromArray( array: ArrayLike<number>, offset?: number ): Matrix4;
  204. /**
  205. * Returns an array with the values of this matrix, or copies them into the provided array.
  206. * @param array (optional) array to store the matrix to. If this is not provided, a new array will be created.
  207. * @param offset (optional) optional offset into the array.
  208. * @return The created or provided array.
  209. */
  210. toArray( array?: number[], offset?: number ): number[];
  211. /**
  212. * Copies he values of this matrix into the provided array-like.
  213. * @param array array-like to store the matrix to.
  214. * @param offset (optional) optional offset into the array-like.
  215. * @return The provided array-like.
  216. */
  217. toArray( array?: ArrayLike<number>, offset?: number ): ArrayLike<number>;
  218. /**
  219. * @deprecated Use {@link Matrix4#copyPosition .copyPosition()} instead.
  220. */
  221. extractPosition( m: Matrix4 ): Matrix4;
  222. /**
  223. * @deprecated Use {@link Matrix4#makeRotationFromQuaternion .makeRotationFromQuaternion()} instead.
  224. */
  225. setRotationFromQuaternion( q: Quaternion ): Matrix4;
  226. /**
  227. * @deprecated Use {@link Vector3#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  228. */
  229. multiplyVector3( v: any ): any;
  230. /**
  231. * @deprecated Use {@link Vector4#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  232. */
  233. multiplyVector4( v: any ): any;
  234. /**
  235. * @deprecated This method has been removed completely.
  236. */
  237. multiplyVector3Array( array: number[] ): number[];
  238. /**
  239. * @deprecated Use {@link Vector3#transformDirection Vector3.transformDirection( matrix )} instead.
  240. */
  241. rotateAxis( v: any ): void;
  242. /**
  243. * @deprecated Use {@link Vector3#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  244. */
  245. crossVector( v: any ): void;
  246. /**
  247. * @deprecated Use {@link Matrix4#toArray .toArray()} instead.
  248. */
  249. flattenToArrayOffset( array: number[], offset: number ): number[];
  250. }
粤ICP备19079148号