Matrix4.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <div class="desc">A class representing a 4x4 [link:https://en.wikipedia.org/wiki/Matrix_(mathematics) matrix].</div>
  13. <h2>Example</h2>
  14. <code>// Simple rig for rotating around 3 axes
  15. var m = new THREE.Matrix4();
  16. var m1 = new THREE.Matrix4();
  17. var m2 = new THREE.Matrix4();
  18. var m3 = new THREE.Matrix4();
  19. var alpha = 0;
  20. var beta = Math.PI;
  21. var gamma = Math.PI/2;
  22. m1.makeRotationX( alpha );
  23. m2.makeRotationY( beta );
  24. m3.makeRotationZ( gamma );
  25. m.multiplyMatrices( m1, m2 );
  26. m.multiply( m3 );
  27. </code>
  28. <h2>Constructor</h2>
  29. <h3>[name]()</h3>
  30. <div>
  31. Creates and initializes the [name] to the 4x4
  32. [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
  33. </div>
  34. <h2>Properties</h2>
  35. <h3>[property:Float32Array elements]</h3>
  36. <div>
  37. A [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]
  38. list of matrix values.
  39. </div>
  40. <h3>[property:Boolean isMatrix4]</h3>
  41. <div>
  42. Used to check whether this or derived classes are Matrix4s. Default is *true*.<br /><br />
  43. You should not change this, as it used internally for optimisation.
  44. </div>
  45. <h2>Methods</h2>
  46. <h3>[method:Array applyToBuffer]( [page:ArrayBuffer buffer], [page:Number offset], [page:Number length] )</h3>
  47. <div>
  48. [page:Array buffer] - An [link:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ArrayBuffer]
  49. of floats in the form [vector1x, vector1y, vector1z, vector2x, vector2y, vector2z, ...], that represent 3D vectors.<br />>
  50. [page:Number offset] - (optional) index in the array of the first vector's x component. Default is 0.<br />
  51. [page:Number length] - (optional) index in the array of the last vector's z component.
  52. Default is the last element in the array.<br /><br />
  53. Multiplies (applies) the upper 3x3 matrix of this matrix to every 3D vector in the [page:ArrayBuffer buffer].
  54. </div>
  55. <h3>[method:Array applyToVector3Array]( [page:Array array], [page:Number offset], [page:Number length] )</h3>
  56. <div>
  57. [page:Array array] - An array of floats in the form [vector1x, vector1y, vector1z, vector2x, vector2y, vector2z, ...],
  58. that represent 3D vectors.<br />>
  59. [page:Number offset] - (optional) index in the array of the first vector's x component. Default is 0.<br />
  60. [page:Number length] - (optional) index in the array of the last vector's z component.
  61. Default is the last element in the array.<br /><br />
  62. Multiplies (applies) the upper 3x3 matrix of this matrix to every 3D vector in the [page:Array array].
  63. </div>
  64. <h3>[method:Matrix4 clone]()</h3>
  65. <div>Creates a new Matrix4 and with identical elements to this one.</div>
  66. <h3>[method:Matrix4 compose]( [page:Vector3 translation], [page:Quaternion quaternion], [page:Vector3 scale] )</h3>
  67. <div>
  68. Sets this matrix to the transformation composed of [page:Vector3 translation], [page:Quaternion quaternion] and [page:Vector3 scale].
  69. </div>
  70. <h3>[method:Matrix4 copy]( [page:Matrix4 m] )</h3>
  71. <div>Copies the elements of matrix [page:Matrix4 m] into this matrix.</div>
  72. <h3>[method:Matrix4 copyPosition]( [page:Matrix4 m] )</h3>
  73. <div>
  74. Copies the translation component of the supplied matrix *m* into this matrix's translation component.
  75. </div>
  76. <h3>[method:null decompose]( [page:Vector3 translation], [page:Quaternion quaternion], [page:Vector3 scale] )</h3>
  77. <div>
  78. Decomposes this matrix into the *translation*, *quaternion* and *scale* components.
  79. </div>
  80. <h3>[method:Float determinant]()</h3>
  81. <div>
  82. Computes and returns the determinant of this matrix.<br />
  83. Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm]
  84. </div>
  85. <h3>[method:Boolean equals]( [page:Matrix4 m] )</h3>
  86. <div>Return true if this and [page:Matrix4 m] are equals.</div>
  87. <h3>[method:Matrix4 extractBasis]( [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis] )</h3>
  88. <div>
  89. Extracts basis of into the three axis vectors provided. Returns the current matrix.
  90. </div>
  91. <h3>[method:Matrix4 extractRotation]( [page:Matrix4 m] )</h3>
  92. <div>
  93. Extracts the rotation of the supplied matrix *m* into this matrix rotation component.
  94. </div>
  95. <h3>[method:Matrix4 fromArray]( [page:Array array], [page:Integer offset] )</h3>
  96. <div>
  97. array -- [page:Array] The array to read the elements from.<br />
  98. offset -- [page:Integer] optional offset into the array. Default is 0.
  99. </div>
  100. <div>
  101. Sets the elements of this matrix based on an array in column-major format.
  102. </div>
  103. <h3>[method:Matrix4 getInverse]( [page:Matrix4 m] )</h3>
  104. <div>
  105. Sets this matrix to the inverse of matrix *m*.<br />
  106. Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm].
  107. </div>
  108. <h3>[method:Float getMaxScaleOnAxis]()</h3>
  109. <div>
  110. Gets the maximum scale value of the 3 axes.
  111. </div>
  112. <h3>[method:Matrix4 identity]()</h3>
  113. <div>
  114. Resets this matrix to identity.
  115. </div>
  116. <h3>[method:Matrix4 lookAt]( [page:Vector3 eye], [page:Vector3 center], [page:Vector3 up], )</h3>
  117. <div>
  118. Constructs a rotation matrix, looking from *eye* towards *center* with defined *up* vector.
  119. </div>
  120. <h3>[method:Matrix4 makeRotationAxis]( [page:Vector3 axis], [page:Float theta] )</h3>
  121. <div>
  122. axis — Rotation axis, should be normalized.
  123. theta — Rotation angle in radians.
  124. </div>
  125. <div>
  126. Sets this matrix as rotation transform around *axis* by *angle* radians.<br />
  127. Based on [link:http://www.gamedev.net/reference/articles/article1199.asp].
  128. </div>
  129. <h3>[method:Matrix4 makeBasis]( [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis] )</h3>
  130. <div>
  131. Creates the basis matrix consisting of the three provided axis vectors. Returns the current matrix.
  132. </div>
  133. <h3>[method:Matrix4 makeFrustum]( [page:Float left], [page:Float right], [page:Float bottom], [page:Float top], [page:Float near], [page:Float far] )</h3>
  134. <div>
  135. Creates a [page:Frustum frustum] matrix.
  136. </div>
  137. <h3>[method:Matrix4 makeOrthographic]( [page:Float left], [page:Float right], [page:Float top], [page:Float bottom], [page:Float near], [page:Float far] )</h3>
  138. <div>
  139. Creates an orthographic projection matrix.
  140. </div>
  141. <h3>[method:Matrix4 makePerspective]( [page:Float fov], [page:Float aspect], [page:Float near], [page:Float far] )</h3>
  142. <div>
  143. Creates a perspective projection matrix.
  144. </div>
  145. <h3>[method:Matrix4 makeRotationFromEuler]( [page:Euler euler] )</h3>
  146. <div>
  147. euler — Rotation vector followed by order of rotations, e.g., "XYZ".
  148. </div>
  149. <div>
  150. Sets the rotation submatrix of this matrix to the rotation specified by Euler angles, the rest of the matrix is identity.<br />
  151. Default order is *"XYZ"*.
  152. </div>
  153. <h3>[method:Matrix4 makeRotationFromQuaternion]( [page:Quaternion q] )</h3>
  154. <div>
  155. Sets the rotation submatrix of this matrix to the rotation specified by *q*. The rest of the matrix is identity.
  156. </div>
  157. <h3>[method:Matrix4 makeRotationX]( [page:Float theta] )</h3>
  158. <div>
  159. theta — Rotation angle in radians.
  160. </div>
  161. <div>
  162. Sets this matrix as rotation transform around x axis by *theta* radians.
  163. </div>
  164. <h3>[method:Matrix4 makeRotationY]( [page:Float theta] )</h3>
  165. <div>
  166. theta — Rotation angle in radians.
  167. </div>
  168. <div>
  169. Sets this matrix as rotation transform around y axis by *theta* radians.
  170. </div>
  171. <h3>[method:Matrix4 makeRotationZ]( [page:Float theta] )</h3>
  172. <div>
  173. theta — Rotation angle in radians.
  174. </div>
  175. <div>
  176. Sets this matrix as rotation transform around z axis by *theta* radians.
  177. </div>
  178. <h3>[method:Matrix4 makeScale]( [page:Float x], [page:Float y], [page:Float z] )</h3>
  179. <div>
  180. Sets this matrix as scale transform.
  181. </div>
  182. <h3>[method:Matrix4 makeShear]( [page:Float x], [page:Float y], [page:Float z] )</h3>
  183. <div>
  184. Sets this matrix as shear transform.
  185. </div>
  186. <h3>[method:Matrix4 makeTranslation]( [page:Float x], [page:Float y], [page:Float z] )</h3>
  187. <div>
  188. Sets this matrix as translation transform.
  189. </div>
  190. <h3>[method:Matrix4 multiply]( [page:Matrix4 m] )</h3>
  191. <div>
  192. Post-multiplies this matrix by *m*.
  193. </div>
  194. <h3>[method:Matrix4 multiplyMatrices]( [page:Matrix4 a], [page:Matrix4 b] )</h3>
  195. <div>
  196. Sets this matrix to *a x b*.
  197. </div>
  198. <h3>[method:Matrix4 multiplyScalar]( [page:Float s] )</h3>
  199. <div>
  200. Multiplies every component of the matrix by a scalar value *s*.
  201. </div>
  202. <h3>[method:Matrix4 multiplyToArray]( [page:Matrix4 a], [page:Matrix4 b], [page:Array r] )</h3>
  203. <div>
  204. Sets this matrix to *a x b* and stores the result into the flat array *r*.<br />
  205. *r* can be either a regular Array or a TypedArray.
  206. </div>
  207. <h3>[method:Matrix4 premultiply]( [page:Matrix4 m] )</h3>
  208. <div>
  209. Pre-multiplies this matrix by *m*.
  210. </div>
  211. <h3>[method:Matrix4 scale]( [page:Vector3 v] )</h3>
  212. <div>
  213. Multiplies the columns of this matrix by vector *v*.
  214. </div>
  215. <h3>[method:Matrix4 set]( [page:Float n11], [page:Float n12], [page:Float n13], [page:Float n14], [page:Float n21], [page:Float n22], [page:Float n23], [page:Float n24], [page:Float n31], [page:Float n32], [page:Float n33], [page:Float n34], [page:Float n41], [page:Float n42], [page:Float n43], [page:Float n44] )</h3>
  216. <div>
  217. Sets all fields of this matrix to the supplied row-major values n11..n44.
  218. </div>
  219. <h3>[method:Matrix4 setPosition]( [page:Vector3 v] )</h3>
  220. <div>
  221. Sets the position component for this matrix from vector *v*.
  222. </div>
  223. <h3>[method:Array toArray]( [page:Array array], [page:Integer offset] )</h3>
  224. <div>
  225. array -- [page:Array] optional array to store the vector <br />
  226. offset -- [page:Integer] optional offset into the array
  227. </div>
  228. <div>
  229. Writes the elements of this matrix to an array in column-major format.
  230. </div>
  231. <h3>[method:Matrix4 transpose]()</h3>
  232. <div>
  233. Transposes this matrix.
  234. </div>
  235. <h2>Source</h2>
  236. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  237. </body>
  238. </html>