Matrix4.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  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. <p class="desc">
  12. 表示为一个 4x4 [link:https://en.wikipedia.org/wiki/Matrix_(mathematics) matrix].<br /><br />
  13. 在3D计算机图形学中,4x4矩阵最常用的用法是作为一个变换矩阵[link:https://en.wikipedia.org/wiki/Transformation_matrix Transformation Matrix]。
  14. 有关WebGL中使用的变换矩阵的介绍,请参阅本教程[link:http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices this tutorial]。<br /><br />
  15. 这使得表示三维空间中的一个点的向量[page:Vector3]通过乘以矩阵来进行转换,如平移、旋转、剪切、缩放、反射、正交或透视投影等。这就是把矩阵<em>应用</em>到向量上。<br /><br />
  16. 任何3D物体[page:Object3D]都有三个关联的矩阵:
  17. <ul>
  18. <li>
  19. [page:Object3D.matrix]: 存储物体的本地变换矩阵。 这是对象相对于其父对象的变换矩阵。
  20. </li>
  21. <li>
  22. [page:Object3D.matrixWorld]: 对象的全局或世界变换矩阵。如果对象没有父对象,那么这与存储在矩阵[page:Object3D.matrix matrix]中的本地变换矩阵相同。
  23. </li>
  24. <li>
  25. [page:Object3D.modelViewMatrix]: 表示对象相对于摄像机坐标系的变换矩阵,
  26. 一个对象的 modelViewMatrix 是物体世界变换矩阵乘以摄像机相对于世界空间变换矩阵的逆矩阵。
  27. </li>
  28. </ul>
  29. 摄像机[page:Camera Cameras] 有三个额外的四维矩阵:
  30. <ul>
  31. <li>
  32. [page:Camera.matrixWorldInverse]: 视矩阵 - 摄像机世界坐标变换的逆矩阵。
  33. </li>
  34. <li>
  35. [page:Camera.projectionMatrix]: 投影变换矩阵,表示将场景中的信息投影到裁剪空间。
  36. </li>
  37. <li>
  38. [page:Camera.projectionMatrixInverse]: 投影变换矩阵的逆矩阵。
  39. </li>
  40. </ul>
  41. 注意:物体的正规矩阵 [page:Object3D.normalMatrix] 并不是一个4维矩阵,而是一个三维矩阵[page:Matrix3]。
  42. </p>
  43. <h2>注意行优先列优先的顺序。</h2>
  44. <p>
  45. 设置[page:.set set]()方法参数采用行优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order row-major],
  46. 而它们在内部是用列优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major]顺序存储在数组当中。<br /><br />
  47. 这意味着
  48. <code>
  49. const m = new THREE.Matrix4();
  50. m.set( 11, 12, 13, 14,
  51. 21, 22, 23, 24,
  52. 31, 32, 33, 34,
  53. 41, 42, 43, 44 );
  54. </code>
  55. 元素数组[page:.elements elements]将存储为:
  56. <code>
  57. m.elements = [ 11, 21, 31, 41,
  58. 12, 22, 32, 42,
  59. 13, 23, 33, 43,
  60. 14, 24, 34, 44 ];
  61. </code>
  62. 在内部,所有的计算都是使用列优先顺序进行的。然而,由于实际的排序在数学上没有什么不同,
  63. 而且大多数人习惯于以行优先顺序考虑矩阵,所以three.js文档以行为主的顺序显示矩阵。
  64. 请记住,如果您正在阅读源代码,您必须对这里列出的任何矩阵进行转置[link:https://en.wikipedia.org/wiki/Transpose transpose],以理解计算。
  65. </p>
  66. <h2>提取位置(平移)、旋转和缩放</h2>
  67. <p>
  68. 有多种选项可用于从 Matrix4 中提取位置、旋转和缩放。
  69. <ul>
  70. <li>
  71. [page:Vector3.setFromMatrixPosition]:可用于提取位置相关的分量。
  72. </li>
  73. <li>
  74. [page:Vector3.setFromMatrixScale]:可用于提取缩放相关的分量。
  75. </li>
  76. <li>
  77. [page:Quaternion.setFromRotationMatrix], [page:Euler.setFromRotationMatrix] 或 [page:.extractRotation extractRotation]:可用于从纯(未缩放)矩阵中提取旋转相关分量。
  78. </li>
  79. <li>
  80. [page:.decompose decompose]:可用于一次性提取位置、旋转和缩放
  81. </li>
  82. </ul>
  83. </p>
  84. <h2>构造器(Constructor)</h2>
  85. <h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13], [param:Number n14],
  86. [param:Number n21], [param:Number n22], [param:Number n23], [param:Number n24],
  87. [param:Number n31], [param:Number n32], [param:Number n33], [param:Number n34],
  88. [param:Number n41], [param:Number n42], [param:Number n43], [param:Number n44] )</h3>
  89. <p>
  90. Creates a 4x4 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
  91. the [name] to the 4x4 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
  92. </p>
  93. <h2>属性(Properties)</h2>
  94. <h3>[property:Array elements]</h3>
  95. <p>
  96. 矩阵列优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major]列表。
  97. </p>
  98. <h2>方法(Methods)</h2>
  99. <h3>[method:Matrix4 clone]()</h3>
  100. <p>创建一个新的矩阵,元素[page:.elements elements]与该矩阵相同。</p>
  101. <h3>[method:this compose]( [param:Vector3 position], [param:Quaternion quaternion], [param:Vector3 scale] )</h3>
  102. <p>
  103. 设置将该对象位置 [page:Vector3 position],四元数[page:Quaternion quaternion] 和 缩放[page:Vector3 scale] 组合变换的矩阵。
  104. </p>
  105. <h3>[method:this copy]( [param:Matrix4 m] )</h3>
  106. <p>将矩阵[page:Matrix3 m]的元素[page:.elements elements]复制到当前矩阵中。</p>
  107. <h3>[method:this copyPosition]( [param:Matrix4 m] )</h3>
  108. <p>
  109. 将给定矩阵 [param:Matrix4 m] 的平移分量拷贝到当前矩阵中。
  110. </p>
  111. <h3>[method:this decompose]( [param:Vector3 position], [param:Quaternion quaternion], [param:Vector3 scale] )</h3>
  112. <p>
  113. 将矩阵分解到给定的平移[page:Vector3 position] ,旋转 [page:Quaternion quaternion],缩放[page:Vector3 scale]分量中。<br/><br/>
  114. 注意:并非所有矩阵都可以通过这种方式分解。 例如,如果一个对象有一个非均匀缩放的父对象,那么该对象的世界矩阵可能是不可分解的,这种方法可能不合适。
  115. </p>
  116. <h3>[method:Float determinant]()</h3>
  117. <p>
  118. 计算并返回矩阵的行列式[link:https://en.wikipedia.org/wiki/Determinant determinant] 。<br /><br />
  119. 基于这个的方法概述[link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm here]。
  120. </p>
  121. <h3>[method:Boolean equals]( [param:Matrix4 m] )</h3>
  122. <p>如果矩阵[page:Matrix3 m] 与当前矩阵所有对应元素相同则返回true。</p>
  123. <h3>[method:this extractBasis]( [param:Vector3 xAxis], [param:Vector3 yAxis], [param:Vector3 zAxis] )</h3>
  124. <p>
  125. 将矩阵的基向量[link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis]提取到指定的3个轴向量中。
  126. 如果矩阵如下:
  127. </p>
  128. <math display="block">
  129. <mrow>
  130. <mo>[</mo>
  131. <mtable>
  132. <mtr>
  133. <mtd><mi>a</mi></mtd>
  134. <mtd><mi>b</mi></mtd>
  135. <mtd><mi>c</mi></mtd>
  136. <mtd><mi>d</mi></mtd>
  137. </mtr>
  138. <mtr>
  139. <mtd><mi>e</mi></mtd>
  140. <mtd><mi>f</mi></mtd>
  141. <mtd><mi>g</mi></mtd>
  142. <mtd><mi>h</mi></mtd>
  143. </mtr>
  144. <mtr>
  145. <mtd><mi>i</mi></mtd>
  146. <mtd><mi>j</mi></mtd>
  147. <mtd><mi>k</mi></mtd>
  148. <mtd><mi>l</mi></mtd>
  149. </mtr>
  150. <mtr>
  151. <mtd><mi>m</mi></mtd>
  152. <mtd><mi>n</mi></mtd>
  153. <mtd><mi>o</mi></mtd>
  154. <mtd><mi>p</mi></mtd>
  155. </mtr>
  156. </mtable>
  157. <mo>]</mo>
  158. </mrow>
  159. </math>
  160. <p>然后x轴y轴z轴被设为:</p>
  161. <div style="text-align: center">
  162. <math>
  163. <mrow>
  164. <mi>xAxis</mi>
  165. <mo>=</mo>
  166. <mo>[</mo>
  167. <mtable>
  168. <mtr><mtd style="height: 1rem"><mi>a</mi></mtd></mtr>
  169. <mtr><mtd style="height: 1rem"><mi>e</mi></mtd></mtr>
  170. <mtr><mtd style="height: 1rem"><mi>i</mi></mtd></mtr>
  171. </mtable>
  172. <mo>]</mo>
  173. </mrow>
  174. </math>,
  175. <math>
  176. <mrow>
  177. <mi>yAxis</mi>
  178. <mo>=</mo>
  179. <mo>[</mo>
  180. <mtable>
  181. <mtr><mtd style="height: 1rem"><mi>b</mi></mtd></mtr>
  182. <mtr><mtd style="height: 1rem"><mi>f</mi></mtd></mtr>
  183. <mtr><mtd style="height: 1rem"><mi>j</mi></mtd></mtr>
  184. </mtable>
  185. <mo>]</mo>
  186. </mrow>
  187. </math>, and
  188. <math>
  189. <mrow>
  190. <mi>zAxis</mi>
  191. <mo>=</mo>
  192. <mo>[</mo>
  193. <mtable>
  194. <mtr><mtd style="height: 1rem"><mi>c</mi></mtd></mtr>
  195. <mtr><mtd style="height: 1rem"><mi>g</mi></mtd></mtr>
  196. <mtr><mtd style="height: 1rem"><mi>k</mi></mtd></mtr>
  197. </mtable>
  198. <mo>]</mo>
  199. </mrow>
  200. </math>
  201. </div>
  202. <h3>[method:this extractRotation]( [param:Matrix4 m] )</h3>
  203. <p>
  204. 将给定矩阵[page:Matrix4 m]的旋转分量提取到该矩阵的旋转分量中。
  205. </p>
  206. <h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
  207. <p>
  208. [page:Array array] - 用来存储设置元素数据的数组<br />
  209. [page:Integer offset] - (可选参数) 数组的偏移量,默认值为 0。<br /><br />
  210. 使用基于列优先格式[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]的数组来设置该矩阵。
  211. </p>
  212. <h3>[method:this invert]()</h3>
  213. <p>
  214. 将当前矩阵翻转为它的逆矩阵,使用 [link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method] 解析方式。你不能对行或列为 0 的矩阵进行翻转,如果你尝试这样做,该方法将生成一个零矩阵。
  215. </p>
  216. <h3>[method:Float getMaxScaleOnAxis]()</h3>
  217. <p>获取3个轴方向的最大缩放值。</p>
  218. <h3>[method:this identity]()</h3>
  219. <p>将当前矩阵重置为单位矩阵[link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix]。</p>
  220. <h3>[method:this lookAt]( [param:Vector3 eye], [param:Vector3 target], [param:Vector3 up] )</h3>
  221. <p>
  222. 构造一个旋转矩阵,从[page:Vector3 eye] 指向 [page:Vector3 target],由向量 [page:Vector3 up] 定向。
  223. </p>
  224. <h3>[method:this makeRotationAxis]( [param:Vector3 axis], [param:Float theta] )</h3>
  225. <p>
  226. [page:Vector3 axis] — 旋转轴,需要被归一化。<br />
  227. [page:Float theta] — 旋转量(弧度)。<br /><br />
  228. 设置当前矩阵为围绕轴 [page:Vector3 axis] 旋转量为 [page:Float theta]弧度。<br />
  229. 这是一种有点争议但在数学上可以替代通过四元数[page:Quaternion Quaternions]旋转的办法。 请参阅此处[link:https://www.gamedev.net/articles/programming/math-and-physics/do-we-really-need-quaternions-r1199 here]的讨论。
  230. </p>
  231. <h3>[method:this makeBasis]( [param:Vector3 xAxis], [param:Vector3 yAxis], [param:Vector3 zAxis] )</h3>
  232. <p>
  233. 通过给定的三个向量设置该矩阵为基矩阵[link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis]:
  234. </p>
  235. <math display="block">
  236. <mrow>
  237. <mo>[</mo>
  238. <mtable>
  239. <mtr>
  240. <mtd><mi>xAxis.x</mi></mtd>
  241. <mtd><mi>yAxis.x</mi></mtd>
  242. <mtd><mi>zAxis.x</mi></mtd>
  243. <mtd><mn>0</mn></mtd>
  244. </mtr>
  245. <mtr>
  246. <mtd><mi>xAxis.y</mi></mtd>
  247. <mtd><mi>yAxis.y</mi></mtd>
  248. <mtd><mi>zAxis.y</mi></mtd>
  249. <mtd><mn>0</mn></mtd>
  250. </mtr>
  251. <mtr>
  252. <mtd><mi>xAxis.z</mi></mtd>
  253. <mtd><mi>yAxis.z</mi></mtd>
  254. <mtd><mi>zAxis.z</mi></mtd>
  255. <mtd><mn>0</mn></mtd>
  256. </mtr>
  257. <mtr>
  258. <mtd><mn>0</mn></mtd>
  259. <mtd><mn>0</mn></mtd>
  260. <mtd><mn>0</mn></mtd>
  261. <mtd><mn>1</mn></mtd>
  262. </mtr>
  263. </mtable>
  264. <mo>]</mo>
  265. </mrow>
  266. </math>
  267. <h3>[method:this makePerspective]( [param:Float left], [param:Float right], [param:Float top], [param:Float bottom], [param:Float near], [param:Float far] )</h3>
  268. <p>
  269. 创建一个透视投影矩阵[link:https://en.wikipedia.org/wiki/3D_projection#Perspective_projection perspective projection]。
  270. 在引擎内部由[page:PerspectiveCamera.updateProjectionMatrix]()使用。
  271. </p>
  272. <h3>[method:this makeOrthographic]( [param:Float left], [param:Float right], [param:Float top], [param:Float bottom], [param:Float near], [param:Float far] )</h3>
  273. <p>
  274. 创建一个正交投影矩阵[link:https://en.wikipedia.org/wiki/Orthographic_projection orthographic projection]。
  275. 在引擎内部由[page:OrthographicCamera.updateProjectionMatrix]()使用。
  276. </p>
  277. <h3>[method:this makeRotationFromEuler]( [param:Euler euler] )</h3>
  278. <p>
  279. 将传入的欧拉角转换为该矩阵的旋转分量(左上角的3x3矩阵)。
  280. 矩阵的其余部分被设为单位矩阵。根据欧拉角[page:Euler euler]的旋转顺序[page:Euler.order order],总共有六种可能的结果。
  281. 详细信息,请参阅本页[link:https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix this page]。
  282. </p>
  283. <h3>[method:this makeRotationFromQuaternion]( [param:Quaternion q] )</h3>
  284. <p>
  285. 将这个矩阵的旋转分量设置为四元数[page:Quaternion q]指定的旋转,如下链接所诉[link:https://en.wikipedia.org/wiki/Rotation_matrix#Quaternion here]。
  286. 矩阵的其余部分被设为单位矩阵。因此,给定四元数[page:Quaternion q] = w + xi + yj + zk,得到的矩阵为:
  287. </p>
  288. <math display="block">
  289. <mrow>
  290. <mo>[</mo>
  291. <mtable>
  292. <mtr>
  293. <mtd>
  294. <mn>1</mn>
  295. <mo>-</mo>
  296. <mn>2</mn>
  297. <msup>
  298. <mi>y</mi>
  299. <mn>2</mn>
  300. </msup>
  301. <mo>-</mo>
  302. <mn>2</mn>
  303. <msup>
  304. <mi>z</mi>
  305. <mn>2</mn>
  306. </msup>
  307. </mtd>
  308. <mtd>
  309. <mn>2</mn>
  310. <mi>x</mi>
  311. <mi>y</mi>
  312. <mo>-</mo>
  313. <mn>2</mn>
  314. <mi>z</mi>
  315. <mi>w</mi>
  316. </mtd>
  317. <mtd>
  318. <mn>2</mn>
  319. <mi>x</mi>
  320. <mi>z</mi>
  321. <mo>+</mo>
  322. <mn>2</mn>
  323. <mi>y</mi>
  324. <mi>w</mi>
  325. </mtd>
  326. <mtd>
  327. <mn>0</mn>
  328. </mtd>
  329. </mtr>
  330. <mtr>
  331. <mtd>
  332. <mn>2</mn>
  333. <mi>x</mi>
  334. <mi>y</mi>
  335. <mo>+</mo>
  336. <mn>2</mn>
  337. <mi>z</mi>
  338. <mi>w</mi>
  339. </mtd>
  340. <mtd>
  341. <mn>1</mn>
  342. <mo>-</mo>
  343. <mn>2</mn>
  344. <msup>
  345. <mi>x</mi>
  346. <mn>2</mn>
  347. </msup>
  348. <mo>-</mo>
  349. <mn>2</mn>
  350. <msup>
  351. <mi>z</mi>
  352. <mn>2</mn>
  353. </msup>
  354. </mtd>
  355. <mtd>
  356. <mn>2</mn>
  357. <mi>y</mi>
  358. <mi>z</mi>
  359. <mo>-</mo>
  360. <mn>2</mn>
  361. <mi>x</mi>
  362. <mi>w</mi>
  363. </mtd>
  364. <mtd>
  365. <mn>0</mn>
  366. </mtd>
  367. </mtr>
  368. <mtr>
  369. <mtd>
  370. <mn>2</mn>
  371. <mi>x</mi>
  372. <mi>z</mi>
  373. <mo>-</mo>
  374. <mn>2</mn>
  375. <mi>y</mi>
  376. <mi>w</mi>
  377. </mtd>
  378. <mtd>
  379. <mn>2</mn>
  380. <mi>y</mi>
  381. <mi>z</mi>
  382. <mo>+</mo>
  383. <mn>2</mn>
  384. <mi>x</mi>
  385. <mi>w</mi>
  386. </mtd>
  387. <mtd>
  388. <mn>1</mn>
  389. <mo>-</mo>
  390. <mn>2</mn>
  391. <msup>
  392. <mi>x</mi>
  393. <mn>2</mn>
  394. </msup>
  395. <mo>-</mo>
  396. <mn>2</mn>
  397. <msup>
  398. <mi>y</mi>
  399. <mn>2</mn>
  400. </msup>
  401. </mtd>
  402. <mtd>
  403. <mn>0</mn>
  404. </mtd>
  405. </mtr>
  406. <mtr>
  407. <mtd><mn>0</mn></mtd>
  408. <mtd><mn>0</mn></mtd>
  409. <mtd><mn>0</mn></mtd>
  410. <mtd><mn>1</mn></mtd>
  411. </mtr>
  412. </mtable>
  413. <mo>]</mo>
  414. </mrow>
  415. </math>
  416. <h3>[method:this makeRotationX]( [param:Float theta] )</h3>
  417. <p>
  418. [page:Float theta] — Rotation angle in radians.<br /><br />
  419. 把该矩阵设置为绕x轴旋转弧度[page:Float theta] (&theta;)大小的矩阵。
  420. 结果如下:
  421. </p>
  422. <math display="block">
  423. <mrow>
  424. <mo>[</mo>
  425. <mtable>
  426. <mtr>
  427. <mtd><mn>1</mn></mtd>
  428. <mtd><mn>0</mn></mtd>
  429. <mtd><mn>0</mn></mtd>
  430. <mtd><mn>0</mn></mtd>
  431. </mtr>
  432. <mtr>
  433. <mtd>
  434. <mn>0</mn>
  435. </mtd>
  436. <mtd>
  437. <mi>cos</mi>
  438. <mi>&theta;</mi>
  439. </mtd>
  440. <mtd>
  441. <mo>-</mo>
  442. <mi>sin</mi>
  443. <mi>&theta;</mi>
  444. </mtd>
  445. <mtd>
  446. <mn>0</mn>
  447. </mtd>
  448. </mtr>
  449. <mtr>
  450. <mtd>
  451. <mn>0</mn>
  452. </mtd>
  453. <mtd>
  454. <mi>sin</mi>
  455. <mi>&theta;</mi>
  456. </mtd>
  457. <mtd>
  458. <mi>cos</mi>
  459. <mi>&theta;</mi>
  460. </mtd>
  461. <mtd>
  462. <mn>0</mn>
  463. </mtd>
  464. </mtr>
  465. <mtr>
  466. <mtd><mn>0</mn></mtd>
  467. <mtd><mn>0</mn></mtd>
  468. <mtd><mn>0</mn></mtd>
  469. <mtd><mn>1</mn></mtd>
  470. </mtr>
  471. </mtable>
  472. <mo>]</mo>
  473. </mrow>
  474. </math>
  475. <h3>[method:this makeRotationY]( [param:Float theta] )</h3>
  476. <p>
  477. [page:Float theta] — Rotation angle in radians.<br /><br />
  478. 把该矩阵设置为绕Y轴旋转弧度[page:Float theta] (&theta;)大小的矩阵。
  479. 结果如下:
  480. </p>
  481. <math display="block">
  482. <mrow>
  483. <mo>[</mo>
  484. <mtable>
  485. <mtr>
  486. <mtd>
  487. <mi>cos</mi>
  488. <mi>&theta;</mi>
  489. </mtd>
  490. <mtd>
  491. <mn>0</mn>
  492. </mtd>
  493. <mtd>
  494. <mi>sin</mi>
  495. <mi>&theta;</mi>
  496. </mtd>
  497. <mtd>
  498. <mn>0</mn>
  499. </mtd>
  500. </mtr>
  501. <mtr>
  502. <mtd><mn>0</mn></mtd>
  503. <mtd><mn>1</mn></mtd>
  504. <mtd><mn>0</mn></mtd>
  505. <mtd><mn>0</mn></mtd>
  506. </mtr>
  507. <mtr>
  508. <mtd>
  509. <mo>-</mo>
  510. <mi>sin</mi>
  511. <mi>&theta;</mi>
  512. </mtd>
  513. <mtd>
  514. <mn>0</mn>
  515. </mtd>
  516. <mtd>
  517. <mi>cos</mi>
  518. <mi>&theta;</mi>
  519. </mtd>
  520. <mtd>
  521. <mn>0</mn>
  522. </mtd>
  523. </mtr>
  524. <mtr>
  525. <mtd><mn>0</mn></mtd>
  526. <mtd><mn>0</mn></mtd>
  527. <mtd><mn>0</mn></mtd>
  528. <mtd><mn>1</mn></mtd>
  529. </mtr>
  530. </mtable>
  531. <mo>]</mo>
  532. </mrow>
  533. </math>
  534. <h3>[method:this makeRotationZ]( [param:Float theta] )</h3>
  535. <p>
  536. [page:Float theta] — Rotation angle in radians.<br /><br />
  537. 把该矩阵设置为绕z轴旋转弧度[page:Float theta] (&theta;)大小的矩阵。
  538. 结果如下:
  539. </p>
  540. <math display="block">
  541. <mrow>
  542. <mo>[</mo>
  543. <mtable>
  544. <mtr>
  545. <mtd>
  546. <mi>cos</mi>
  547. <mi>&theta;</mi>
  548. </mtd>
  549. <mtd>
  550. <mo>-</mo>
  551. <mi>sin</mi>
  552. <mi>&theta;</mi>
  553. </mtd>
  554. <mtd>
  555. <mn>0</mn>
  556. </mtd>
  557. <mtd>
  558. <mn>0</mn>
  559. </mtd>
  560. </mtr>
  561. <mtr>
  562. <mtd>
  563. <mi>sin</mi>
  564. <mi>&theta;</mi>
  565. </mtd>
  566. <mtd>
  567. <mi>cos</mi>
  568. <mi>&theta;</mi>
  569. </mtd>
  570. <mtd>
  571. <mn>0</mn>
  572. </mtd>
  573. <mtd>
  574. <mn>0</mn>
  575. </mtd>
  576. </mtr>
  577. <mtr>
  578. <mtd><mn>0</mn></mtd>
  579. <mtd><mn>0</mn></mtd>
  580. <mtd><mn>1</mn></mtd>
  581. <mtd><mn>0</mn></mtd>
  582. </mtr>
  583. <mtr>
  584. <mtd><mn>0</mn></mtd>
  585. <mtd><mn>0</mn></mtd>
  586. <mtd><mn>0</mn></mtd>
  587. <mtd><mn>1</mn></mtd>
  588. </mtr>
  589. </mtable>
  590. <mo>]</mo>
  591. </mrow>
  592. </math>
  593. <h3>[method:this makeScale]( [param:Float x], [param:Float y], [param:Float z] )</h3>
  594. <p>
  595. [page:Float x] - 在X轴方向的缩放比。<br />
  596. [page:Float y] - 在Y轴方向的缩放比。<br />
  597. [page:Float z] - 在Z轴方向的缩放比。<br /><br />
  598. 将这个矩阵设置为缩放变换:
  599. </p>
  600. <math display="block">
  601. <mrow>
  602. <mo>[</mo>
  603. <mtable>
  604. <mtr>
  605. <mtd><mi>x</mi></mtd>
  606. <mtd><mn>0</mn></mtd>
  607. <mtd><mn>0</mn></mtd>
  608. <mtd><mn>0</mn></mtd>
  609. </mtr>
  610. <mtr>
  611. <mtd><mn>0</mn></mtd>
  612. <mtd><mi>y</mi></mtd>
  613. <mtd><mn>0</mn></mtd>
  614. <mtd><mn>0</mn></mtd>
  615. </mtr>
  616. <mtr>
  617. <mtd><mn>0</mn></mtd>
  618. <mtd><mn>0</mn></mtd>
  619. <mtd><mi>z</mi></mtd>
  620. <mtd><mn>0</mn></mtd>
  621. </mtr>
  622. <mtr>
  623. <mtd><mn>0</mn></mtd>
  624. <mtd><mn>0</mn></mtd>
  625. <mtd><mn>0</mn></mtd>
  626. <mtd><mn>1</mn></mtd>
  627. </mtr>
  628. </mtable>
  629. <mo>]</mo>
  630. </mrow>
  631. </math>
  632. <h3>[method:this makeShear]( [param:Float x], [param:Float y], [param:Float z] )</h3>
  633. <p>
  634. [page:Float x] - 在X轴上剪切的量。<br />
  635. [page:Float y] - 在Y轴上剪切的量。<br />
  636. [page:Float z] - 在Z轴上剪切的量。<br /><br />
  637. 将此矩阵设置为剪切变换:
  638. </p>
  639. <math display="block">
  640. <mrow>
  641. <mo>[</mo>
  642. <mtable>
  643. <mtr>
  644. <mtd><mn>1</mn></mtd>
  645. <mtd><mi>y</mi><mi>x</mi></mtd>
  646. <mtd><mi>z</mi><mi>x</mi></mtd>
  647. <mtd><mn>0</mn></mtd>
  648. </mtr>
  649. <mtr>
  650. <mtd><mi>x</mi><mi>y</mi></mtd>
  651. <mtd><mn>1</mn></mtd>
  652. <mtd><mi>z</mi><mi>y</mi></mtd>
  653. <mtd><mn>0</mn></mtd>
  654. </mtr>
  655. <mtr>
  656. <mtd><mi>x</mi><mi>z</mi></mtd>
  657. <mtd><mi>y</mi><mi>z</mi></mtd>
  658. <mtd><mn>1</mn></mtd>
  659. <mtd><mn>0</mn></mtd>
  660. </mtr>
  661. <mtr>
  662. <mtd><mn>0</mn></mtd>
  663. <mtd><mn>0</mn></mtd>
  664. <mtd><mn>0</mn></mtd>
  665. <mtd><mn>1</mn></mtd>
  666. </mtr>
  667. </mtable>
  668. <mo>]</mo>
  669. </mrow>
  670. </math>
  671. <h3>[method:this makeTranslation]( [param:Vector3 v] )</h3>
  672. <h3>
  673. [method:this makeTranslation]( [param:Float x], [param:Float y], [param:Float z] ) // optional API
  674. </h3>
  675. <p>
  676. 取传入参数[param:Vector3 v]中值设设置该矩阵为平移变换:
  677. </p>
  678. <math display="block">
  679. <mrow>
  680. <mo>[</mo>
  681. <mtable>
  682. <mtr>
  683. <mtd><mn>1</mn></mtd>
  684. <mtd><mn>0</mn></mtd>
  685. <mtd><mn>0</mn></mtd>
  686. <mtd><mi>x</mi></mtd>
  687. </mtr>
  688. <mtr>
  689. <mtd><mn>0</mn></mtd>
  690. <mtd><mn>1</mn></mtd>
  691. <mtd><mn>0</mn></mtd>
  692. <mtd><mi>y</mi></mtd>
  693. </mtr>
  694. <mtr>
  695. <mtd><mn>0</mn></mtd>
  696. <mtd><mn>0</mn></mtd>
  697. <mtd><mn>1</mn></mtd>
  698. <mtd><mi>z</mi></mtd>
  699. </mtr>
  700. <mtr>
  701. <mtd><mn>0</mn></mtd>
  702. <mtd><mn>0</mn></mtd>
  703. <mtd><mn>0</mn></mtd>
  704. <mtd><mn>1</mn></mtd>
  705. </mtr>
  706. </mtable>
  707. <mo>]</mo>
  708. </mrow>
  709. </math>
  710. <h3>[method:this multiply]( [param:Matrix4 m] )</h3>
  711. <p>将当前矩阵乘以矩阵[page:Matrix4 m]。</p>
  712. <h3>[method:this multiplyMatrices]( [param:Matrix4 a], [param:Matrix4 b] )</h3>
  713. <p>设置当前矩阵为矩阵[page:Matrix4 a] x 矩阵[page:Matrix4 b]。</p>
  714. <h3>[method:this multiplyScalar]( [param:Float s] )</h3>
  715. <p>当前矩阵所有的元素乘以该缩放值*s*</p>
  716. <h3>[method:this premultiply]( [param:Matrix4 m] )</h3>
  717. <p>将矩阵[page:Matrix4 m]乘以当前矩阵。</p>
  718. <h3>[method:this scale]( [param:Vector3 v] )</h3>
  719. <p>将该矩阵的列向量乘以对应向量[page:Vector3 v]的分量。</p>
  720. <h3>[method:this set]( [param:Float n11], [param:Float n12], [param:Float n13], [param:Float n14], [param:Float n21], [param:Float n22], [param:Float n23], [param:Float n24], [param:Float n31], [param:Float n32], [param:Float n33], [param:Float n34], [param:Float n41], [param:Float n42], [param:Float n43], [param:Float n44] )</h3>
  721. <p>
  722. 以行优先的格式将传入的数值设置给该矩阵中的元素[page:.elements elements]。
  723. </p>
  724. <h3>[method:this setFromMatrix3]( [param:Matrix3 m] )</h3>
  725. <p>根据参数 [page:Matrix3 m] 的值,设置当前矩阵左上 3x3 的矩阵值。</p>
  726. <h3>[method:this setPosition]( [param:Vector3 v] )</h3>
  727. <h3>[method:this setPosition]( [param:Float x], [param:Float y], [param:Float z] ) // optional API</h3>
  728. <p>
  729. 取传入参数[param:Vector3 v]中值设置该矩阵的位置分量,不影响该矩阵的其余部分——即,如果该矩阵当前为:
  730. </p>
  731. <math display="block">
  732. <mrow>
  733. <mo>[</mo>
  734. <mtable>
  735. <mtr>
  736. <mtd><mi>a</mi></mtd>
  737. <mtd><mi>b</mi></mtd>
  738. <mtd><mi>c</mi></mtd>
  739. <mtd><mi>d</mi></mtd>
  740. </mtr>
  741. <mtr>
  742. <mtd><mi>e</mi></mtd>
  743. <mtd><mi>f</mi></mtd>
  744. <mtd><mi>g</mi></mtd>
  745. <mtd><mi>h</mi></mtd>
  746. </mtr>
  747. <mtr>
  748. <mtd><mi>i</mi></mtd>
  749. <mtd><mi>j</mi></mtd>
  750. <mtd><mi>k</mi></mtd>
  751. <mtd><mi>l</mi></mtd>
  752. </mtr>
  753. <mtr>
  754. <mtd><mi>m</mi></mtd>
  755. <mtd><mi>n</mi></mtd>
  756. <mtd><mi>o</mi></mtd>
  757. <mtd><mi>p</mi></mtd>
  758. </mtr>
  759. </mtable>
  760. <mo>]</mo>
  761. </mrow>
  762. </math>
  763. <p>变成:</p>
  764. <math display="block">
  765. <mrow>
  766. <mo>[</mo>
  767. <mtable>
  768. <mtr>
  769. <mtd><mi>a</mi></mtd>
  770. <mtd><mi>b</mi></mtd>
  771. <mtd><mi>c</mi></mtd>
  772. <mtd><mi>v.x</mi></mtd>
  773. </mtr>
  774. <mtr>
  775. <mtd><mi>e</mi></mtd>
  776. <mtd><mi>f</mi></mtd>
  777. <mtd><mi>g</mi></mtd>
  778. <mtd><mi>v.y</mi></mtd>
  779. </mtr>
  780. <mtr>
  781. <mtd><mi>i</mi></mtd>
  782. <mtd><mi>j</mi></mtd>
  783. <mtd><mi>k</mi></mtd>
  784. <mtd><mi>v.z</mi></mtd>
  785. </mtr>
  786. <mtr>
  787. <mtd><mi>m</mi></mtd>
  788. <mtd><mi>n</mi></mtd>
  789. <mtd><mi>o</mi></mtd>
  790. <mtd><mi>p</mi></mtd>
  791. </mtr>
  792. </mtable>
  793. <mo>]</mo>
  794. </mrow>
  795. </math>
  796. <h3>[method:Array toArray]( [param:Array array], [param:Integer offset] )</h3>
  797. <p>
  798. [page:Array array] - (可选参数) 存储矩阵元素的数组,如果未指定会创建一个新的数组。<br />
  799. [page:Integer offset] - (可选参数) 存放矩阵元素数组的偏移量。<br /><br />
  800. 使用列优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]格式将此矩阵的元素写入数组中。
  801. </p>
  802. <h3>[method:this transpose]()</h3>
  803. <p>将该矩阵转置[link:https://en.wikipedia.org/wiki/Transpose Transposes]。</p>
  804. <h2>源码(Source)</h2>
  805. <p>
  806. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  807. </p>
  808. </body>
  809. </html>