Matrix4.html 8.5 KB

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