Matrix4.html 25 KB

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