为什么我们使用矩阵而不是数组?
[如果我创建3D模型的顶点数组,并且想将每个顶点很好地向左移动
ArrayList<Vertex> vertex = fillVertecis();
for(Vertex vertex: vertices){
vertex.x += 2;
}
//or avoiding creating all those objects
float[] vertices = fillVertecis();
//asumming we arrange the array like so [x1,y1,z1,x2,y2,z2....]
int x = 0;
int y = 1;
int z = 2;
for(int i = 0; i < vertices.lenght/3; i+= 3){
vertices[i+x] += 1;
}
确保我遍历所有顶点,但是我们不必使用矩阵做同样的事情吗?
我们使用矩阵而不是数组有什么优势?
我们使用矩阵而不是数组有什么优势?
目的明确。
易于操纵。
实现的抽象。
...
尝试对顶点应用旋转或缩放,您将看到4x4矩阵和homogeneous transformations优于数组的好处。