Matrix4.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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.setRotationX( alpha );
  22. m2.setRotationY( beta );
  23. m3.setRotationZ( gamma );
  24. m.multiply( m1, m2 );
  25. m.multiplySelf( 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. <h2>Properties</h2>
  30. <h3>.[page:Float32Array elements]</h3>
  31. <h2>Methods</h2>
  32. <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]</h3>
  33. <div>
  34. Sets all fields of this matrix.
  35. </div>
  36. <h3>.identity() [page:Matrix4]</h3>
  37. <div>
  38. Resets this matrix to identity.
  39. </div>
  40. <h3>.copy( [page:Matrix4 m] ) [page:Matrix4]</h3>
  41. <div>
  42. Copies a matrix *m* into this matrix.
  43. </div>
  44. <h3>.lookAt( [page:Vector3 eye], [page:Vector3 center], [page:Vector3 up], ) [page:Matrix4]</h3>
  45. <div>
  46. Constructs a rotation matrix, looking from *eye* towards *center* with defined *up* vector.
  47. </div>
  48. <h3>.multiply( [page:Matrix4 a], [page:Matrix4 b] ) [page:Matrix4]</h3>
  49. <div>
  50. Sets this matrix to *a x b*.
  51. </div>
  52. <h3>.multiplySelf( [page:Matrix4 m] ) [page:Matrix4]</h3>
  53. <div>
  54. Multiplies this matrix by *m*.
  55. </div>
  56. <h3>.multiplyToArray( [page:Matrix4 a], [page:Matrix4 b], [page:Array r] ) [page:Matrix4]</h3>
  57. <div>
  58. Sets this matrix to *a x b* and sets result into flat array *r*.<br />
  59. Destination array can be regular Array or TypedArray.
  60. </div>
  61. <h3>.multiplyScalar( [page:Float s] ) [page:Matrix4]</h3>
  62. <div>
  63. Multiplies this matrix by *s*.
  64. </div>
  65. <h3>.multiplyVector3( [page:Vector3 v] ) [page:Vector3]</h3>
  66. <div>
  67. Applies this matrix to *v*.
  68. </div>
  69. <h3>.multiplyVector4( [page:Vector4 v] ) [page:Vector4]</h3>
  70. <div>
  71. Applies this matrix to *v*.
  72. </div>
  73. <h3>.rotateAxis( [page:Vector3 v] ) [page:Vector3]</h3>
  74. <div>
  75. Applies rotation submatrix of this matrix to vector *v* and then normalizes it.
  76. </div>
  77. <h3>.crossVector( [page:Vector4 a] ) [page:Vector4]</h3>
  78. <h3>.determinant() [page:Float]</h3>
  79. <div>
  80. Computes determinant of this matrix.<br />
  81. Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm]
  82. </div>
  83. <h3>.transpose() [page:Matrix4]</h3>
  84. <div>
  85. Transposes this matrix.
  86. </div>
  87. <h3>.flatten() [page:Array]</h3>
  88. <div>
  89. Flattens this matrix into internal [page:Matrix4 Matrix4.flat] array.
  90. </div>
  91. <h3>.flattenToArray( [page:Array flat] ) [page:Array]</h3>
  92. <div>
  93. Flattens this matrix into supplied *flat* array.
  94. </div>
  95. <h3>.flattenToArrayOffset( [page:Array flat], [page:Integer offset] ) [page:Array]</h3>
  96. <div>
  97. Flattens this matrix into supplied *flat* array starting from *offset* position in the array.
  98. </div>
  99. <h3>.setTranslation( [page:Float x], [page:Float y], [page:Float z] ) [page:Matrix4]</h3>
  100. <div>
  101. Sets this matrix as translation transform.
  102. </div>
  103. <h3>.setScale( [page:Float x], [page:Float y], [page:Float z] ) [page:Matrix4]</h3>
  104. <div>
  105. Sets this matrix as scale transform.
  106. </div>
  107. <h3>.makeRotationX( [page:Float theta] ) [page:Matrix4]</h3>
  108. <div>
  109. theta — Rotation angle in radians.
  110. </div>
  111. <div>
  112. Sets this matrix as rotation transform around x axis by *theta* radians.
  113. </div>
  114. <h3>.makeRotationY( [page:Float theta] ) [page:Matrix4]</h3>
  115. <div>
  116. theta — Rotation angle in radians.
  117. </div>
  118. <div>
  119. Sets this matrix as rotation transform around y axis by *theta* radians.
  120. </div>
  121. <h3>.makeRotationZ( [page:Float theta] ) [page:Matrix4]</h3>
  122. <div>
  123. theta — Rotation angle in radians.
  124. </div>
  125. <div>
  126. Sets this matrix as rotation transform around z axis by *theta* radians.
  127. </div>
  128. <h3>.makeRotationAxis( [page:Vector3 axis], [page:Float theta] ) [page:Matrix4]</h3>
  129. <div>
  130. axis — Rotation axis.
  131. theta — Rotation angle in radians.
  132. </div>
  133. <div>
  134. Sets this matrix as rotation transform around *axis* by *angle* radians.<br />
  135. Based on [link:http://www.gamedev.net/reference/articles/article1199.asp].
  136. </div>
  137. <h3>.setPosition( [page:Vector3 v] ) [page:Matrix4]</h3>
  138. <div>
  139. Sets the position component for this matrix from vector *v*.
  140. </div>
  141. <h3>.getPosition() [page:Vector3]</h3>
  142. <div>
  143. Returns position component from this matrix.<br />
  144. Note: this method returns a reference to internal class vector, make copy or clone if you don't use it right away.
  145. </div>
  146. <h3>.getColumnX() [page:Vector3]</h3>
  147. <div>
  148. Returns x column component from this matrix.<br />
  149. Note: this method returns a reference to internal class vector, make copy or clone if you don't use it right away.
  150. </div>
  151. <h3>.getColumnY() [page:Vector3]</h3>
  152. <div>
  153. Returns y column component from this matrix.<br />
  154. Note: this method returns a reference to internal class vector, make copy or clone if you don't use it right away.
  155. </div>
  156. <h3>.getColumnZ() [page:Vector3]</h3>
  157. <div>
  158. Returns z column component from this matrix.<br />
  159. Note: this method returns a reference to internal class vector, make copy or clone if you don't use it right away.
  160. </div>
  161. <h3>.getInverse( [page:Matrix4 m] ) [page:Matrix4]</h3>
  162. <div>
  163. Sets this matrix to inverse of matrix *m*.<br />
  164. Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm].
  165. </div>
  166. <h3>.setRotationFromEuler( [page:Vector3 v], [page:String order] ) [page:Matrix4]</h3>
  167. <div>
  168. v — Rotation vector.
  169. order — The order of rotations. Eg. "XYZ".
  170. </div>
  171. <div>
  172. Sets rotation submatrix of this matrix to rotation specified by Euler angles.<br />
  173. Default order "XYZ".
  174. </div>
  175. <h3>.setRotationFromQuaternion( [page:Quaternion q] ) [page:Matrix4]</h3>
  176. <div>
  177. Sets rotation submatrix of this matrix to rotation specified by *q*.
  178. </div>
  179. <h3>.scale( [page:Vector3 v] ) [page:Matrix4]</h3>
  180. <div>
  181. Multiplies columns of this matrix by vector *v*.
  182. </div>
  183. <h3>.compose( [page:Vector3 translation], [page:Quaternion rotation], [page:Vector3 scale] ) [page:Matrix4]</h3>
  184. <div>
  185. Sets this matrix to transform composed of *translation*, *rotation* and *scale*.
  186. </div>
  187. <h3>.decompose( [page:Vector3 translation], [page:Quaternion rotation], [page:Vector3 scale] ) [page:Array]</h3>
  188. <div>
  189. Decomposes this matrix into *translation*, *rotation* and *scale* components.<br />
  190. If parameters are not supplied, new instances will be created.
  191. </div>
  192. <h3>.extractPosition( [page:Matrix4 m] ) [page:Matrix4]</h3>
  193. <div>
  194. Copies translation component of supplied matrix *m* into this matrix translation.
  195. </div>
  196. <h3>.extractRotation( [page:Matrix4 m] ) [page:Matrix4]</h3>
  197. <div>
  198. Copies rotation component of supplied matrix *m* into this matrix rotation.
  199. </div>
  200. <h3>.rotateByAxis( [page:Vector3 axis], [page:Float angle] ) [page:Matrix4]</h3>
  201. <div>
  202. Rotates this matrix around supplied *axis* by *angle*.
  203. </div>
  204. <h3>.rotateX( [page:Float angle] ) [page:Matrix4]</h3>
  205. <div>
  206. Rotates this matrix around x axis by *angle*.
  207. </div>
  208. <h3>.rotateY( [page:Float angle] ) [page:Matrix4]</h3>
  209. <div>
  210. Rotates this matrix around y axis by *angle*.
  211. </div>
  212. <h3>.rotateZ( [page:Float angle] ) [page:Matrix4]</h3>
  213. <div>
  214. Rotates this matrix around z axis by *angle*.
  215. </div>
  216. <h3>.translate( [page:Vector3 v] ) [page:Matrix4]</h3>
  217. <div>
  218. Translates this matrix by vector *v*.
  219. </div>
  220. <h3>.clone() [page:Matrix4]</h3>
  221. <div>
  222. Clones this matrix.
  223. </div>
  224. <h2>Static methods</h2>
  225. <h3>.makeInvert3x3( [page:Matrix4 m] ) [page:Matrix3]</h3>
  226. <div>
  227. Inverts just rotation submatrix of matrix *m*.<br />
  228. Note: this method returns a reference to internal 3x3 matrix, make copy or clone if you don't use it right away.<br />
  229. Based on [link:http://code.google.com/p/webgl-mjs/].
  230. </div>
  231. <h3>.makeFrustum( [page:Float left], [page:Float right], [page:Float bottom], [page:Float top], [page:Float near], [page:Float far] ) [page:Matrix4]</h3>
  232. <div>
  233. Creates frustum matrix.
  234. </div>
  235. <h3>.makePerspective( [page:Float fov], [page:Float aspect], [page:Float near], [page:Float far] ) [page:Matrix4]</h3>
  236. <div>
  237. Creates perspective projection matrix.
  238. </div>
  239. <h3>.makeOrtho( [page:Float left], [page:Float right], [page:Float bottom], [page:Float top], [page:Float near], [page:Float far] ) [page:Matrix4]</h3>
  240. <div>
  241. Creates orthographic projection matrix.
  242. </div>
  243. <h2>Source</h2>
  244. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  245. </body>
  246. </html>