Matrix4.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <script src="../../list.js"></script>
  6. <script src="../../page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="../../page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <div class="desc">A 4x4 Matrix.</div>
  12. <h2>Example</h2>
  13. <code>// Simple rig for rotating around 3 axes
  14. var m = new THREE.Matrix4();
  15. var m1 = new THREE.Matrix4();
  16. var m2 = new THREE.Matrix4();
  17. var m3 = new THREE.Matrix4();
  18. var alpha = 0;
  19. var beta = Math.PI;
  20. var gamma = Math.PI/2;
  21. m1.makeRotationX( alpha );
  22. m2.makeRotationY( beta );
  23. m3.makeRotationZ( gamma );
  24. m.multiplyMatrices( m1, m2 );
  25. m.multiply( m3 );
  26. </code>
  27. <h2>Constructor</h2>
  28. <h3>[name]( [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>
  29. <div>
  30. Initialises the matrix with the supplied row-major values n11..n44, or just creates an identity matrix if no values are passed.
  31. </div>
  32. <h2>Properties</h2>
  33. <h3>.[page:Float32Array elements]</h3>
  34. <div>A column-major list of matrix values.</div>
  35. <h2>Methods</h2>
  36. <h3>.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] ) [page:Matrix4 this]</h3>
  37. <div>
  38. Sets all fields of this matrix to the supplied row-major values n11..n44.
  39. </div>
  40. <h3>.identity() [page:Matrix4 this]</h3>
  41. <div>
  42. Resets this matrix to identity.
  43. </div>
  44. <h3>.copy( [page:Matrix4 m] ) [page:Matrix4 this]</h3>
  45. <div>
  46. Copies a matrix *m* into this matrix.
  47. </div>
  48. <h3>.copyPosition( [page:Matrix4 m] ) [page:Matrix4 this]</h3>
  49. <div>
  50. Copies the translation component of the supplied matrix *m* into this matrix translation component.
  51. </div>
  52. <h3>.extractRotation( [page:Matrix4 m] ) [page:Matrix4 this]</h3>
  53. <div>
  54. Extracts the rotation of the supplied matrix *m* into this matrix rotation component.
  55. </div>
  56. <h3>.lookAt( [page:Vector3 eye], [page:Vector3 center], [page:Vector3 up], ) [page:Matrix4 this]</h3>
  57. <div>
  58. Constructs a rotation matrix, looking from *eye* towards *center* with defined *up* vector.
  59. </div>
  60. <h3>.multiply( [page:Matrix4 m] ) [page:Matrix4 this]</h3>
  61. <div>
  62. Multiplies this matrix by *m*.
  63. </div>
  64. <h3>.multiplyMatrices( [page:Matrix4 a], [page:Matrix4 b] ) [page:Matrix4 this]</h3>
  65. <div>
  66. Sets this matrix to *a x b*.
  67. </div>
  68. <h3>.multiplyToArray( [page:Matrix4 a], [page:Matrix4 b], [page:Array r] ) [page:Matrix4 this]</h3>
  69. <div>
  70. Sets this matrix to *a x b* and stores the result into the flat array *r*.<br />
  71. *r* can be either a regular Array or a TypedArray.
  72. </div>
  73. <h3>.multiplyScalar( [page:Float s] ) [page:Matrix4 this]</h3>
  74. <div>
  75. Multiplies this matrix by *s*.
  76. </div>
  77. <h3>.determinant() [page:Float]</h3>
  78. <div>
  79. Computes determinant of this matrix.<br />
  80. Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm]
  81. </div>
  82. <h3>.transpose() [page:Matrix4 this]</h3>
  83. <div>
  84. Transposes this matrix.
  85. </div>
  86. <h3>.flattenToArrayOffset( [page:Array flat], [page:Integer offset] ) [page:Array]</h3>
  87. <div>
  88. Flattens this matrix into supplied *flat* array starting from *offset* position in the array.
  89. </div>
  90. <h3>.setPosition( [page:Vector3 v] ) [page:Matrix4 this]</h3>
  91. <div>
  92. Sets the position component for this matrix from vector *v*.
  93. </div>
  94. <h3>.getInverse( [page:Matrix4 m] ) [page:Matrix4 this]</h3>
  95. <div>
  96. Sets this matrix to the inverse of matrix *m*.<br />
  97. Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm].
  98. </div>
  99. <h3>.makeRotationFromEuler( [page:Vector3 v], [page:String order] ) [page:Matrix4 this]</h3>
  100. <div>
  101. v — Rotation vector.
  102. order — The order of rotations. Eg. "XYZ".
  103. </div>
  104. <div>
  105. Sets the rotation submatrix of this matrix to the rotation specified by Euler angles, the rest of the matrix is identity.<br />
  106. Default order is *"XYZ"*.
  107. </div>
  108. <h3>.makeRotationFromQuaternion( [page:Quaternion q] ) [page:Matrix4 this]</h3>
  109. <div>
  110. Sets the rotation submatrix of this matrix to the rotation specified by *q*. The rest of the matrix is identity.
  111. </div>
  112. <h3>.scale( [page:Vector3 v] ) [page:Matrix4 this]</h3>
  113. <div>
  114. Multiplies the columns of this matrix by vector *v*.
  115. </div>
  116. <h3>.compose( [page:Vector3 translation], [page:Quaternion quaternion], [page:Vector3 scale] ) [page:Matrix4 this]</h3>
  117. <div>
  118. Sets this matrix to the transformation composed of *translation*, *quaternion* and *scale*.
  119. </div>
  120. <h3>.decompose( [page:Vector3 translation], [page:Quaternion quaternion], [page:Vector3 scale] ) [page:Array]</h3>
  121. <div>
  122. Decomposes this matrix into the *translation*, *quaternion* and *scale* components.<br />
  123. If parameters are not passed, new instances will be created.
  124. </div>
  125. <h3>.makeTranslation( [page:Float x], [page:Float y], [page:Float z] ) [page:Matrix4 this]</h3>
  126. <div>
  127. Sets this matrix as translation transform.
  128. </div>
  129. <h3>.makeRotationX( [page:Float theta] ) [page:Matrix4 this]</h3>
  130. <div>
  131. theta — Rotation angle in radians.
  132. </div>
  133. <div>
  134. Sets this matrix as rotation transform around x axis by *theta* radians.
  135. </div>
  136. <h3>.makeRotationY( [page:Float theta] ) [page:Matrix4 this]</h3>
  137. <div>
  138. theta — Rotation angle in radians.
  139. </div>
  140. <div>
  141. Sets this matrix as rotation transform around y axis by *theta* radians.
  142. </div>
  143. <h3>.makeRotationZ( [page:Float theta] ) [page:Matrix4 this]</h3>
  144. <div>
  145. theta — Rotation angle in radians.
  146. </div>
  147. <div>
  148. Sets this matrix as rotation transform around z axis by *theta* radians.
  149. </div>
  150. <h3>.makeRotationAxis( [page:Vector3 axis], [page:Float theta] ) [page:Matrix4 this]</h3>
  151. <div>
  152. axis — Rotation axis, should be normalized.
  153. theta — Rotation angle in radians.
  154. </div>
  155. <div>
  156. Sets this matrix as rotation transform around *axis* by *angle* radians.<br />
  157. Based on [link:http://www.gamedev.net/reference/articles/article1199.asp].
  158. </div>
  159. <h3>.makeScale( [page:Float x], [page:Float y], [page:Float z] ) [page:Matrix4 this]</h3>
  160. <div>
  161. Sets this matrix as scale transform.
  162. </div>
  163. <h3>.makeFrustum( [page:Float left], [page:Float right], [page:Float bottom], [page:Float top], [page:Float near], [page:Float far] ) [page:Matrix4 this]</h3>
  164. <div>
  165. Creates a [page:Frustum frustum] matrix.
  166. </div>
  167. <h3>.makePerspective( [page:Float fov], [page:Float aspect], [page:Float near], [page:Float far] ) [page:Matrix4 this]</h3>
  168. <div>
  169. Creates a perspective projection matrix.
  170. </div>
  171. <h3>.makeOrthographic( [page:Float left], [page:Float right], [page:Float bottom], [page:Float top], [page:Float near], [page:Float far] ) [page:Matrix4 this]</h3>
  172. <div>
  173. Creates an orthographic projection matrix.
  174. </div>
  175. <h3>.clone() [page:Matrix4]</h3>
  176. <div>
  177. Clones this matrix.
  178. </div>
  179. <h3>.applyToVector3Array([page:Array a]) [page:Array]</h3>
  180. <div>
  181. array -- An array in the form [vector1x, vector1y, vector1z, vector2x, vector2y, vector2z, ...]
  182. </div>
  183. <div>
  184. Multiply (apply) this matrix to every vector3 in the array.
  185. </div>
  186. <h3>.getMaxScaleOnAxis() [page:Float]</h3>
  187. <div>
  188. Gets the max scale value of the 3 axes.
  189. </div>
  190. <h2>Source</h2>
  191. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  192. </body>
  193. </html>