Matrix4.d.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. * @deprecated Use {@link Matrix4#applyToBufferAttribute matrix4.applyToBufferAttribute( attribute )} instead.
  92. */
  93. applyToBuffer(
  94. buffer: BufferAttribute,
  95. offset?: number,
  96. length?: number
  97. ): BufferAttribute;
  98. applyToBufferAttribute( attribute: BufferAttribute ): BufferAttribute;
  99. /**
  100. * Computes determinant of this matrix.
  101. * Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  102. */
  103. determinant(): number;
  104. /**
  105. * Transposes this matrix.
  106. */
  107. transpose(): Matrix4;
  108. /**
  109. * Sets the position component for this matrix from vector v.
  110. */
  111. setPosition( v: Vector3 | number, y?: number, z?: number ): Matrix4;
  112. /**
  113. * Sets this matrix to the inverse of matrix m.
  114. * Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm.
  115. */
  116. getInverse( m: Matrix4, throwOnDegeneratee?: boolean ): Matrix4;
  117. /**
  118. * Multiplies the columns of this matrix by vector v.
  119. */
  120. scale( v: Vector3 ): Matrix4;
  121. getMaxScaleOnAxis(): number;
  122. /**
  123. * Sets this matrix as translation transform.
  124. */
  125. makeTranslation( x: number, y: number, z: number ): Matrix4;
  126. /**
  127. * Sets this matrix as rotation transform around x axis by theta radians.
  128. *
  129. * @param theta Rotation angle in radians.
  130. */
  131. makeRotationX( theta: number ): Matrix4;
  132. /**
  133. * Sets this matrix as rotation transform around y axis by theta radians.
  134. *
  135. * @param theta Rotation angle in radians.
  136. */
  137. makeRotationY( theta: number ): Matrix4;
  138. /**
  139. * Sets this matrix as rotation transform around z axis by theta radians.
  140. *
  141. * @param theta Rotation angle in radians.
  142. */
  143. makeRotationZ( theta: number ): Matrix4;
  144. /**
  145. * Sets this matrix as rotation transform around axis by angle radians.
  146. * Based on http://www.gamedev.net/reference/articles/article1199.asp.
  147. *
  148. * @param axis Rotation axis.
  149. * @param theta Rotation angle in radians.
  150. */
  151. makeRotationAxis( axis: Vector3, angle: number ): Matrix4;
  152. /**
  153. * Sets this matrix as scale transform.
  154. */
  155. makeScale( x: number, y: number, z: number ): Matrix4;
  156. /**
  157. * Sets this matrix to the transformation composed of translation, rotation and scale.
  158. */
  159. compose( translation: Vector3, rotation: Quaternion, scale: Vector3 ): Matrix4;
  160. /**
  161. * Decomposes this matrix into the translation, rotation and scale components.
  162. * If parameters are not passed, new instances will be created.
  163. */
  164. decompose(
  165. translation?: Vector3,
  166. rotation?: Quaternion,
  167. scale?: Vector3
  168. ): Object[]; // [Vector3, Quaternion, Vector3]
  169. /**
  170. * Creates a frustum matrix.
  171. */
  172. makePerspective(
  173. left: number,
  174. right: number,
  175. bottom: number,
  176. top: number,
  177. near: number,
  178. far: number
  179. ): Matrix4;
  180. /**
  181. * Creates a perspective projection matrix.
  182. */
  183. makePerspective(
  184. fov: number,
  185. aspect: number,
  186. near: number,
  187. far: number
  188. ): Matrix4;
  189. /**
  190. * Creates an orthographic projection matrix.
  191. */
  192. makeOrthographic(
  193. left: number,
  194. right: number,
  195. top: number,
  196. bottom: number,
  197. near: number,
  198. far: number
  199. ): Matrix4;
  200. equals( matrix: Matrix4 ): boolean;
  201. fromArray( array: number[], offset?: number ): Matrix4;
  202. toArray(): number[];
  203. /**
  204. * @deprecated Use {@link Matrix4#copyPosition .copyPosition()} instead.
  205. */
  206. extractPosition( m: Matrix4 ): Matrix4;
  207. /**
  208. * @deprecated Use {@link Matrix4#makeRotationFromQuaternion .makeRotationFromQuaternion()} instead.
  209. */
  210. setRotationFromQuaternion( q: Quaternion ): Matrix4;
  211. /**
  212. * @deprecated Use {@link Vector3#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  213. */
  214. multiplyVector3( v: any ): any;
  215. /**
  216. * @deprecated Use {@link Vector4#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  217. */
  218. multiplyVector4( v: any ): any;
  219. /**
  220. * @deprecated This method has been removed completely.
  221. */
  222. multiplyVector3Array( array: number[] ): number[];
  223. /**
  224. * @deprecated Use {@link Vector3#transformDirection Vector3.transformDirection( matrix )} instead.
  225. */
  226. rotateAxis( v: any ): void;
  227. /**
  228. * @deprecated Use {@link Vector3#applyMatrix4 vector.applyMatrix4( matrix )} instead.
  229. */
  230. crossVector( v: any ): void;
  231. /**
  232. * @deprecated Use {@link Matrix4#toArray .toArray()} instead.
  233. */
  234. flattenToArrayOffset( array: number[], offset: number ): number[];
  235. }