所以我正在学习在 JavaScript 中使用 WebGL 进行编程,突然出现了两个看起来非常相似的术语。
modelMatrix.setTranslate(0,0,0);
modelMatrix.translate(0,0,0);
放入零只是为了举例,modelMatrix 是一个建模矩阵。
设置翻译和翻译有什么区别?
提前谢谢您
最佳答案
setTranslate
的工作方式类似于 setter。它根据参数创建一个新的平移矩阵并将其存储到 modelMatrix 中。例如,假设 modelMatrix
的值为
1 0 0 2
0 1 0 2
0 0 1 2
0 0 0 1
当您应用此代码modelMatrix.setTranslate(0,0,0);
时,它将变成
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
相反,translate
将已存储在 modelMatrix
中的矩阵乘以根据参数创建的矩阵,并将结果存储到 modelMatrix
中。
例如 modelMatrix
的值为
1 0 0 2
0 1 0 2
0 0 1 2
0 0 0 1
当您应用此代码时 modelMatrix.translate(0,0,0);
它将变成
1 0 0 2 1 0 0 0 1 0 0 2
0 1 0 2 x 0 1 0 0 = 0 1 0 2
0 0 1 2 0 0 1 0 0 0 1 2
0 0 0 1 0 0 0 1 0 0 0 1
关于javascript - WebGL 中 modelMatrix.setTranslate() 和 modelMatrix.translate() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35924253/