Matrix4.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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>Initialises the matrix with the supplied n11..n44 values, or just creates an identity matrix if no values are passed.</div>
  30. <h2>Properties</h2>
  31. <h3>.[page:Float32Array elements]</h3>
  32. <h2>Methods</h2>
  33. <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>
  34. <div>
  35. Sets all fields of this matrix.
  36. </div>
  37. <h3>.identity() [page:Matrix4]</h3>
  38. <div>
  39. Resets this matrix to identity.
  40. </div>
  41. <h3>.copy( [page:Matrix4 m] ) [page:Matrix4]</h3>
  42. <div>
  43. Copies a matrix *m* into this matrix.
  44. </div>
  45. <h3>.copyPosition( [page:Matrix4 m] ) [page:Matrix4]</h3>
  46. <div>
  47. Copies the translation component of the supplied matrix *m* into this matrix translation component.
  48. </div>
  49. <h3>.extractRotation( [page:Matrix4 m] ) [page:Matrix4]</h3>
  50. <div>
  51. Extracts the rotation of the supplied matrix *m* into this matrix rotation component.
  52. </div>
  53. <h3>.lookAt( [page:Vector3 eye], [page:Vector3 center], [page:Vector3 up], ) [page:Matrix4]</h3>
  54. <div>
  55. Constructs a rotation matrix, looking from *eye* towards *center* with defined *up* vector.
  56. </div>
  57. <h3>.multiply( [page:Matrix4 m] ) [page:Matrix4]</h3>
  58. <div>
  59. Multiplies this matrix by *m*.
  60. </div>
  61. <h3>.multiplyMatrices( [page:Matrix4 a], [page:Matrix4 b] ) [page:Matrix4]</h3>
  62. <div>
  63. Sets this matrix to *a x b*.
  64. </div>
  65. <h3>.multiplyToArray( [page:Matrix4 a], [page:Matrix4 b], [page:Array r] ) [page:Matrix4]</h3>
  66. <div>
  67. Sets this matrix to *a x b* and stores the result into the flat array *r*.<br />
  68. *r* can be either a regular Array or a TypedArray.
  69. </div>
  70. <h3>.multiplyScalar( [page:Float s] ) [page:Matrix4]</h3>
  71. <div>
  72. Multiplies this matrix by *s*.
  73. </div>
  74. <h3>.multiplyVector3( [page:Vector3 v] ) [page:Vector3]</h3>
  75. <div>
  76. Applies this matrix to *v*.
  77. </div>
  78. <h3>.multiplyVector4( [page:Vector4 v] ) [page:Vector4]</h3>
  79. <div>
  80. Applies this matrix to *v*.
  81. </div>
  82. <h3>.determinant() [page:Float]</h3>
  83. <div>
  84. Computes determinant of this matrix.<br />
  85. Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm]
  86. </div>
  87. <h3>.transpose() [page:Matrix4]</h3>
  88. <div>
  89. Transposes this matrix.
  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>.setPosition( [page:Vector3 v] ) [page:Matrix4]</h3>
  100. <div>
  101. Sets the position component for this matrix from vector *v*.
  102. </div>
  103. <h3>.getPosition() [page:Vector3]</h3>
  104. <div>
  105. Returns position component from this matrix.<br />
  106. Note: this method returns a reference to the internal class vector, make a copy or clone it if you don't use it right away.
  107. </div>
  108. <h3>.getInverse( [page:Matrix4 m] ) [page:Matrix4]</h3>
  109. <div>
  110. Sets this matrix to the inverse of matrix *m*.<br />
  111. Based on [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm].
  112. </div>
  113. <h3>.makeRotationFromEuler( [page:Vector3 v], [page:String order] ) [page:Matrix4]</h3>
  114. <div>
  115. v — Rotation vector.
  116. order — The order of rotations. Eg. "XYZ".
  117. </div>
  118. <div>
  119. Sets the rotation submatrix of this matrix to the rotation specified by Euler angles, the rest of the matrix is identity.<br />
  120. Default order is *"XYZ"*.
  121. </div>
  122. <h3>.makeRotationFromQuaternion( [page:Quaternion q] ) [page:Matrix4]</h3>
  123. <div>
  124. Sets the rotation submatrix of this matrix to the rotation specified by *q*. The rest of the matrix is identity.
  125. </div>
  126. <h3>.scale( [page:Vector3 v] ) [page:Matrix4]</h3>
  127. <div>
  128. Multiplies the columns of this matrix by vector *v*.
  129. </div>
  130. <h3>.makeFromPositionQuaternionScale( [page:Vector3 translation], [page:Quaternion rotation], [page:Vector3 scale] ) [page:Matrix4]</h3>
  131. <div>
  132. Sets this matrix to the transformation composed of *translation*, *rotation* and *scale*.
  133. </div>
  134. <h3>.makeFromPositionEulerScale( [page:Vector3 translation], [page:Vector3 rotation], eulerOrder, [page:Vector3 scale] ) [page:Matrix4]</h3>
  135. <div>
  136. Sets this matrix to the transformation composed of *translation*, *rotation* (as euler angle triple and order) and *scale*.
  137. </div>
  138. <h3>.decompose( [page:Vector3 translation], [page:Quaternion rotation], [page:Vector3 scale] ) [page:Array]</h3>
  139. <div>
  140. Decomposes this matrix into the *translation*, *rotation* and *scale* components.<br />
  141. If parameters are not passed, new instances will be created.
  142. </div>
  143. <h3>.makeTranslation( [page:Float x], [page:Float y], [page:Float z] ) [page:Matrix4]</h3>
  144. <div>
  145. Sets this matrix as translation transform.
  146. </div>
  147. <h3>.makeRotationX( [page:Float theta] ) [page:Matrix4]</h3>
  148. <div>
  149. theta — Rotation angle in radians.
  150. </div>
  151. <div>
  152. Sets this matrix as rotation transform around x axis by *theta* radians.
  153. </div>
  154. <h3>.makeRotationY( [page:Float theta] ) [page:Matrix4]</h3>
  155. <div>
  156. theta — Rotation angle in radians.
  157. </div>
  158. <div>
  159. Sets this matrix as rotation transform around y axis by *theta* radians.
  160. </div>
  161. <h3>.makeRotationZ( [page:Float theta] ) [page:Matrix4]</h3>
  162. <div>
  163. theta — Rotation angle in radians.
  164. </div>
  165. <div>
  166. Sets this matrix as rotation transform around z axis by *theta* radians.
  167. </div>
  168. <h3>.makeRotationAxis( [page:Vector3 axis], [page:Float theta] ) [page:Matrix4]</h3>
  169. <div>
  170. axis — Rotation axis, should be normalized.
  171. theta — Rotation angle in radians.
  172. </div>
  173. <div>
  174. Sets this matrix as rotation transform around *axis* by *angle* radians.<br />
  175. Based on [link:http://www.gamedev.net/reference/articles/article1199.asp].
  176. </div>
  177. <h3>.makeScale( [page:Float x], [page:Float y], [page:Float z] ) [page:Matrix4]</h3>
  178. <div>
  179. Sets this matrix as scale transform.
  180. </div>
  181. <h3>.makeFrustum( [page:Float left], [page:Float right], [page:Float bottom], [page:Float top], [page:Float near], [page:Float far] ) [page:Matrix4]</h3>
  182. <div>
  183. Creates a [page:Frustum frustum] matrix.
  184. </div>
  185. <h3>.makePerspective( [page:Float fov], [page:Float aspect], [page:Float near], [page:Float far] ) [page:Matrix4]</h3>
  186. <div>
  187. Creates a perspective projection matrix.
  188. </div>
  189. <h3>.makeOrthographic( [page:Float left], [page:Float right], [page:Float bottom], [page:Float top], [page:Float near], [page:Float far] ) [page:Matrix4]</h3>
  190. <div>
  191. Creates an orthographic projection matrix.
  192. </div>
  193. <h3>.clone() [page:Matrix4]</h3>
  194. <div>
  195. Clones this matrix.
  196. </div>
  197. <h3>.compose([page:todo position], [page:todo quaternion], [page:todo scale]) [page:todo]</h3>
  198. <div>
  199. position -- todo <br />
  200. quaternion -- todo <br />
  201. scale -- todo
  202. </div>
  203. <div>
  204. todo
  205. </div>
  206. <h3>.rotateAxis([page:todo v]) [page:todo]</h3>
  207. <div>
  208. v -- todo
  209. </div>
  210. <div>
  211. todo
  212. </div>
  213. <h3>.setRotationFromEuler([page:todo v], [page:todo order]) [page:todo]</h3>
  214. <div>
  215. v -- todo <br />
  216. order -- todo
  217. </div>
  218. <div>
  219. todo
  220. </div>
  221. <h3>.crossVector([page:todo vector]) [page:todo]</h3>
  222. <div>
  223. vector -- todo
  224. </div>
  225. <div>
  226. todo
  227. </div>
  228. <h3>.rotateByAxis([page:todo axis], [page:todo angle]) [page:todo]</h3>
  229. <div>
  230. axis -- todo <br />
  231. angle -- todo
  232. </div>
  233. <div>
  234. todo
  235. </div>
  236. <h3>.setRotationFromQuaternion([page:todo q]) [page:todo]</h3>
  237. <div>
  238. q -- todo
  239. </div>
  240. <div>
  241. todo
  242. </div>
  243. <h3>.extractPosition([page:todo m]) [page:todo]</h3>
  244. <div>
  245. m -- todo
  246. </div>
  247. <div>
  248. todo
  249. </div>
  250. <h3>.rotateX([page:todo angle]) [page:todo]</h3>
  251. <div>
  252. angle -- todo
  253. </div>
  254. <div>
  255. todo
  256. </div>
  257. <h3>.rotateY([page:todo angle]) [page:todo]</h3>
  258. <div>
  259. angle -- todo
  260. </div>
  261. <div>
  262. todo
  263. </div>
  264. <h3>.rotateZ([page:todo angle]) [page:todo]</h3>
  265. <div>
  266. angle -- todo
  267. </div>
  268. <div>
  269. todo
  270. </div>
  271. <h3>.multiplyVector3Array([page:todo a]) [page:todo]</h3>
  272. <div>
  273. a -- todo
  274. </div>
  275. <div>
  276. todo
  277. </div>
  278. <h3>.getMaxScaleOnAxis() [page:todo]</h3>
  279. <div>
  280. todo
  281. </div>
  282. <h3>.translate([page:todo v]) [page:todo]</h3>
  283. <div>
  284. v -- todo
  285. </div>
  286. <div>
  287. todo
  288. </div>
  289. <h2>Source</h2>
  290. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  291. </body>
  292. </html>