参考 applyMatrix()

applyMatrix()

将转换矩阵应用于坐标系。

translate()rotate()scale() 之类的转换在幕后使用矩阵-向量乘法。名为矩阵的数字表对每个转换进行编码。然后矩阵中的值会与画布上的每个点相乘,这些点由向量表示。

applyMatrix() 允许一次应用多个转换。查看 WikipediaMDN 以获取有关转换的更多详细信息。

applyMatrix() 可以在二维和三维两种场景中调用 。

在二维模式下,参数 abcdef 对应于以下转换矩阵中的元素:

The transformation matrix used when applyMatrix is called in 2D
  mode.

数字可以个别传递,如 applyMatrix(2, 0, 0, 0, 2, 0)。也可以作为数组传递,如 applyMatrix([2, 0, 0, 0, 2, 0])

在三维模式下,参数 abcdefghijklmnop 对应于以下转换矩阵中的元素:

The transformation matrix used when applyMatrix is called in 3D
  mode.

数字可以个别传递,如 applyMatrix(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1)。也可以作为数组传递,如 applyMatrix([2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1])

默认情况下,转换会累积。可以使用push()pop() 函数将转换隔离到不同的绘图组中。

注意:转换会在绘制循环的开始处重置。在 draw() 函数中调用 applyMatrix() 不会导致形状连续变换。

示例

语法

applyMatrix(arr)
applyMatrix(a, b, c, d, e, f)
applyMatrix(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)

参数

arr
Array:

一个包含转换矩阵元素的数组。其长度应为 6(2D)或 16(3D)。

a
数字:

转换矩阵的一个元素。

b
数字:

转换矩阵的一个元素。

c
数字:

转换矩阵的一个元素。

d
数字:

转换矩阵的一个元素。

e
数字:

转换矩阵的一个元素。

f
数字:

转换矩阵的一个元素。

g
数字:

转换矩阵的一个元素。

h
数字:

转换矩阵的一个元素。

i
数字:

转换矩阵的一个元素。

j
数字:

转换矩阵的一个元素。

k
数字:

转换矩阵的一个元素。

l
数字:

转换矩阵的一个元素。

m
数字:

转换矩阵的一个元素。

n
数字:

转换矩阵的一个元素。

o
数字:

转换矩阵的一个元素。

p
数字:

转换矩阵的一个元素。

Notice any errors or typos? Please let us know. Please feel free to edit src/core/transform.js and open a pull request!

相关参考