123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <base href="../../" />
- <script src="list.js"></script>
- <script src="page.js"></script>
- <link type="text/css" rel="stylesheet" href="page.css" />
- </head>
- <body>
- <h1>[name]</h1>
- <div class="desc">
- A class representing a 4x4 [link:https://en.wikipedia.org/wiki/Matrix_(mathematics) matrix].<br /><br />
- The most common use of a 4x4 matrix in 3D computer graphics is as a
- [link:https://en.wikipedia.org/wiki/Transformation_matrix Transformation Matrix].
- For an introduction to transformation matrices as used in WebGL, check out
- [link:http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices this tutorial].<br /><br />
- This allows a [page:Vector3] representing a point in 3D space to undergo transformations
- such as translation, rotation, shear, scale, reflection, orthogonal or perspective projection
- and so on, by being multiplied by the matrix. This is known as <em>applying</em>
- the matrix to the vector.<br /><br />
- Every [page:Object3D] has three associated Matrix4s:
- <ul>
- <li>
- [page:Object3D.matrix]: This stores the local transform of the object.
- </li>
- <li>
- [page:Object3D.matrixWorld]: The global or world transform of the object. This is the objects transformation relative to its parent.
- If the object has no parent, then this is identical to the local transform.
- </li>
- <li>
- [page:Object3D.modelViewMatrix]:
- </li>
- </ul>
- [page:Camera Cameras] have two additional matrix4s:
- <ul>
- <li>
- [page:Object3D.matrixWorldInverse]: The inverse of the [page:Object3D.matrixWorld] described above.
- </li>
- <li>
- [page:Object3D.projectionMatrix]:
- </li>
- </ul>
- </div>
- <h2>A Note on Row-Major and Column-Major Ordering</h2>
- <div>
- The [page:set]() method takes arguments in [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order row-major]
- order, while internally they are stored in the [page:.elements elements] array in column-major order.<br /><br />
- This means that calling
- <code>
- var m = new Matrix4();
- m.set( 11, 12, 13, 14,
- 21, 22, 23, 24,
- 31, 32, 33, 34,
- 41, 42, 43, 44 );
- </code>
- will result in the [page:.elements elements] array containing:
- <code>
- m.elements = [ 11, 21, 31, 41,
- 12, 22, 32, 42,
- 13, 23, 33, 43,
- 14, 24, 34, 44 ];
- </code>
- and internally all calculations are performed using column-major ordering. However, as the actual ordering
- makes no difference mathematically and most people are used to thinking about matrices in row-major order,
- the three.js documentation shows matrices in row-major order. Just bear in mind that if you are reading the source
- code, you'll have to take the [link: https://en.wikipedia.org/wiki/Transpose transpose] of any matrices outlined here to make sense of the calculations.
- </div>
- <h2>Constructor</h2>
- <h3>[name]()</h3>
- <div>
- Creates and initializes the [name] to the 4x4
- [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
- </div>
- <h2>Properties</h2>
- <h3>[property:Float32Array elements]</h3>
- <div>
- A [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]
- list of matrix values.
- </div>
- <h3>[property:Boolean isMatrix4]</h3>
- <div>
- Used to check whether this or derived classes are Matrix4s. Default is *true*.<br /><br />
- You should not change this, as it used internally for optimisation.
- </div>
- <h2>Methods</h2>
- <h3>[method:Array applyToBufferAttribute]( [page:BufferAttribute attribute] )</h3>
- <div>
- [page:BufferAttribute attribute] - An attribute of floats that represent 3D vectors.<br /><br />
- Multiplies (applies) this matrix to every 3D vector in the [page:BufferAttribute attribute].
- </div>
- <h3>[method:Matrix4 clone]()</h3>
- <div>Creates a new Matrix4 with identical [page:.elements elements] to this one.</div>
- <h3>[method:Matrix4 compose]( [page:Vector3 position], [page:Quaternion quaternion], [page:Vector3 scale] )</h3>
- <div>
- Sets this matrix to the transformation composed of [page:Vector3 position],
- [page:Quaternion quaternion] and [page:Vector3 scale]. Internally this calls
- [page:.makeRotationFromQuaternion makeRotationFromQuaternion]( [page:Quaternion quaternion] )
- followed by [page:.scale scale]( [page:Vector3 scale] ), then finally
- [page:.setPosition setPosition]( [page:Vector3 position] ).
- </div>
- <h3>[method:Matrix4 copy]( [page:Matrix4 m] )</h3>
- <div>Copies the [page:.elements elements] of matrix [page:Matrix4 m] into this matrix.</div>
- <h3>[method:Matrix4 copyPosition]( [page:Matrix4 m] )</h3>
- <div>
- Copies the translation component of the supplied matrix [page:Matrix4 m] into this
- matrix's translation component.
- </div>
- <h3>[method:null decompose]( [page:Vector3 position], [page:Quaternion quaternion], [page:Vector3 scale] )</h3>
- <div>
- Decomposes this matrix into it's [page:Vector3 position], [page:Quaternion quaternion] and
- [page:Vector3 scale] components.
- </div>
- <h3>[method:Float determinant]()</h3>
- <div>
- Computes and returns the
- [link:https://en.wikipedia.org/wiki/Determinant determinant] of this matrix.<br /><br />
- Based on the method outlined [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm here].
- </div>
- <h3>[method:Boolean equals]( [page:Matrix4 m] )</h3>
- <div>Return true if this matrix and [page:Matrix4 m] are equal.</div>
- <h3>[method:Matrix4 extractBasis]( [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis] )</h3>
- <div>
- Extracts the [link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis] of this
- matrix into the three axis vectors provided. If this matrix is:
- <code>
- a, b, c, d,
- e, f, g, h,
- i, j, k, l,
- m, n, o, p
- </code>
- then the [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis] will be set to:
- <code>
- xAxis = (a, e, i)
- yAxis = (d, f, j)
- zAxis = (c, g, k)
- </code>
- </div>
- <h3>[method:Matrix4 extractRotation]( [page:Matrix4 m] )</h3>
- <div>
- Extracts the rotation component of the supplied matrix [page:Matrix4 m] into this matrix's
- rotation component.
- </div>
- <h3>[method:Matrix4 fromArray]( [page:Array array], [page:Integer offset] )</h3>
- <div>
- [page:Array array] - the array to read the elements from.<br />
- [page:Integer offset] - ( optional ) offset into the array. Default is 0.<br /><br />
- Sets the elements of this matrix based on an [page:Array array] in
- [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
- </div>
- <h3>[method:Matrix4 getInverse]( [page:Matrix4 m], [page:Boolean throwOnDegenerate] )</h3>
- <div>
- [page:Matrix4 m] - the matrix to take the inverse of.<br />
- [page:Boolean throwOnDegenerate] - (optional) If true, throw an error if the matrix is degenerate (not invertible).<br /><br />
- Set this matrix to the [link:https://en.wikipedia.org/wiki/Invertible_matrix inverse] of the passed matrix [page:Matrix4 m],
- using the method outlined [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm here].
- If [page:Boolean throwOnDegenerate] is not set and the matrix is not invertible, set this to the 4x4 identity matrix.
- </div>
- <h3>[method:Float getMaxScaleOnAxis]()</h3>
- <div>Gets the maximum scale value of the 3 axes.</div>
- <h3>[method:Matrix4 identity]()</h3>
- <div>Resets this matrix to the [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].</div>
- <h3>[method:Matrix4 lookAt]( [page:Vector3 eye], [page:Vector3 center], [page:Vector3 up], )</h3>
- <div>
- Constructs a rotation matrix, looking from [page:Vector3 eye] towards [page:Vector3 center]
- oriented by the [page:Vector3 up] vector.
- </div>
- <h3>[method:Matrix4 makeRotationAxis]( [page:Vector3 axis], [page:Float theta] )</h3>
- <div>
- [page:Vector3 axis] — Rotation axis, should be normalized.<br />
- [page:Float theta] — Rotation angle in radians.<br /><br />
- Sets this matrix as rotation transform around [page:Vector3 axis] by [page:Float theta] radians.<br />
- This is a somewhat controversial but mathematically sound alternative to rotating via [page:Quaternions].
- See the discussion [link:http://www.gamedev.net/reference/articles/article1199.asp here].
- </div>
- <h3>[method:Matrix4 makeBasis]( [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis] )</h3>
- <div>
- Set this to the [link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis] matrix consisting
- of the three provided basis vectors:
- <code>
- xAxis.x, yAxis.x, zAxis.x, 0,
- xAxis.y, yAxis.y, zAxis.y, 0,
- xAxis.z, yAxis.z, zAxis.z, 0,
- 0, 0, 0, 1
- </code>
- </div>
- <h3>[method:Matrix4 makePerspective]( [page:Float left], [page:Float right], [page:Float top], [page:Float bottom], [page:Float near], [page:Float far] )</h3>
- <div>
- Creates a [link:https://en.wikipedia.org/wiki/3D_projection#Perspective_projection perspective projection] matrix.
- This is used internally by [page:PerspectiveCamera.updateProjectionMatrix]()
- </div>
- <h3>[method:Matrix4 makeOrthographic]( [page:Float left], [page:Float right], [page:Float top], [page:Float bottom], [page:Float near], [page:Float far] )</h3>
- <div>
- Creates an [link:https://en.wikipedia.org/wiki/Orthographic_projection orthographic projection] matrix.
- This is used internally by [page:OrthographicCamera.updateProjectionMatrix]().
- </div>
- <h3>[method:Matrix4 makeRotationFromEuler]( [page:Euler euler] )</h3>
- <div>
- Sets the rotation component (the upper left 3x3 matrix) of this matrix to the rotation specified by the given [page:Euler Euler Angle].
- The rest of the matrix is set to the identity. Depending on the [page:Euler.order order] of the [page:Euler euler], there are six possible outcomes.
- See [link:https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix this page] for a complete list.
- </div>
- <h3>[method:Matrix4 makeRotationFromQuaternion]( [page:Quaternion q] )</h3>
- <div>
- Sets the rotation component of this matrix to the rotation specified by [page:Quaternion q], as outlined
- [link:https://en.wikipedia.org/wiki/Rotation_matrix#Quaternion here].
- The rest of the matrix is set to the identity. So, given [page:Quaternion q] = w + xi + yj + zk, the resulting matrix will be:
- <code>
- 1-2y²-2z² 2xy-2zw 2xz-2yw 0
- 2xy+2zw 1-2x²-2z² 2yz-2xw 0
- 2xz-2yw 2yz+2xw 1-2x²-2y² 0
- 0 0 0 1
- </code>
- </div>
- <h3>[method:Matrix4 makeRotationX]( [page:Float theta] )</h3>
- <div>
- [page:Float theta] — Rotation angle in radians.<br /><br />
- Sets this matrix as a rotational transformation around the X axis by [page:Float theta] (θ) radians.
- The resulting matrix will be:
- <code>
- 1 0 0 0
- 0 cos(θ) -sin(θ) 0
- 0 sin(θ) cos(θ) 0
- 0 0 0 1
- </code>
- </div>
- <h3>[method:Matrix4 makeRotationY]( [page:Float theta] )</h3>
- <div>
- [page:Float theta] — Rotation angle in radians.<br /><br />
- Sets this matrix as a rotational transformation around the Y axis by [page:Float theta] (θ) radians.
- The resulting matrix will be:
- <code>
- cos(θ) 0 sin(θ) 0
- 0 1 0 0
- -sin(θ) 0 cos(θ) 0
- 0 0 0 1
- </code>
- </div>
- <h3>[method:Matrix4 makeRotationZ]( [page:Float theta] )</h3>
- <div>
- [page:Float theta] — Rotation angle in radians.<br /><br />
- Sets this matrix as a rotational transformation around the Z axis by [page:Float theta] (θ) radians.
- The resulting matrix will be:
- <code>
- cos(θ) -sin(θ) 0 0
- sin(θ) cos(θ) 0 0
- 0 0 1 0
- 0 0 0 1
- </code>
- </div>
- <h3>[method:Matrix4 makeScale]( [page:Float x], [page:Float y], [page:Float z] )</h3>
- <div>
- [page:Float x] - the amount to scale in the X axis.<br />
- [page:Float y] - the amount to scale in the Y axis.<br />
- [page:Float z] - the amount to scale in the Z axis.<br /><br />
- Sets this matrix as scale transform:
- <code>
- x, 0, 0, 0,
- 0, y, 0, 0,
- 0, 0, z, 0,
- 0, 0, 0, 1
- </code>
- </div>
- <h3>[method:Matrix4 makeShear]( [page:Float x], [page:Float y], [page:Float z] )</h3>
- <div>
- [page:Float x] - the amount to shear in the X axis.<br />
- [page:Float y] - the amount to shear in the Y axis.<br />
- [page:Float z] - the amount to shear in the Z axis.<br /><br />
- Sets this matrix as a shear transform:
- <code>
- 1, y, z, 0,
- x, 1, z, 0,
- x, y, 1, 0,
- 0, 0, 0, 1
- </code>
- </div>
- <h3>[method:Matrix4 makeTranslation]( [page:Float x], [page:Float y], [page:Float z] )</h3>
- <div>
- [page:Float x] - the amount to translate in the X axis.<br />
- [page:Float y] - the amount to translate in the Y axis.<br />
- [page:Float z] - the amount to translate in the Z axis.<br /><br />
- Sets this matrix as a translation transform:
- <code>
- 1, 0, 0, x,
- 0, 1, 0, y,
- 0, 0, 1, z,
- 0, 0, 0, 1
- </code>
- </div>
- <h3>[method:Matrix4 multiply]( [page:Matrix4 m] )</h3>
- <div>Post-multiplies this matrix by [page:Matrix4 m].</div>
- <h3>[method:Matrix4 multiplyMatrices]( [page:Matrix4 a], [page:Matrix4 b] )</h3>
- <div>Sets this matrix to [page:Matrix4 a] x [page:Matrix4 b].</div>
- <h3>[method:Matrix4 multiplyScalar]( [page:Float s] )</h3>
- <div>Multiplies every component of the matrix by a scalar value [page:Float s].</div>
- <h3>[method:Matrix4 multiplyToArray]( [page:Matrix4 a], [page:Matrix4 b], [page:Array r] )</h3>
- <div>
- Sets this matrix to [page:Matrix4 a] x [page:Matrix4 b] and stores the result into the flat array [page:Array r],
- in [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] order.
- [page:Array r] can be either a regular Array or a [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays TypedArray].
- </div>
- <h3>[method:Matrix4 premultiply]( [page:Matrix4 m] )</h3>
- <div>Pre-multiplies this matrix by [page:Matrix4 m].</div>
- <h3>[method:Matrix4 scale]( [page:Vector3 v] )</h3>
- <div>Multiplies the columns of this matrix by vector [page:Vector3 v].</div>
- <h3>[method:Matrix4 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] )</h3>
- <div>
- Set the [page:.elements elements] of this matrix to the supplied row-major values [page:Float n11],
- [page:Float n12], ... [page:Float n44].
- </div>
- <h3>[method:Matrix4 setPosition]( [page:Vector3 v] )</h3>
- <div>
- Sets the position component for this matrix from vector [page:Vector3 v], without affecting the
- rest of the matrix - i.e. if the matrix is currently:
- <code>
- a, b, c, d,
- e, f, g, h,
- i, j, k, l,
- m, n, o, p
- </code>
- This becomes:
- <code>
- a, b, c, v.x,
- e, f, g, v.y,
- i, j, k, v.z,
- m, n, o, p
- </code>
- </div>
- <h3>[method:Array toArray]( [page:Array array], [page:Integer offset] )</h3>
- <div>
- [page:Array array] - (optional) array to store the resulting vector in.<br />
- [page:Integer offset] - (optional) offset in the array at which to put the result.<br /><br />
- Writes the elements of this matrix to an array in
- [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
- </div>
- <h3>[method:Matrix4 transpose]()</h3>
- <div>[link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix.</div>
- <h2>Source</h2>
- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
- </body>
- </html>
|