仍在弄清楚如何正确使用ofMesh
,我现在的目标是拥有一个点云,随机连接点(使用索引),并能够在点击时随机播放索引。我被指向使用Fisher-Yates Shuffle的方向,但在我找到指数之前,这种方法不会奏效。
目前我只是通过添加具有随机坐标的顶点来创建网格,但是没有明确定义任何索引。当我使用ofSetupIndicesAuto()
时,它会有条理地连接索引,ofClearIndices()
除非我实际以某种方式设置索引,否则不会做任何事情。
我不明白的是当我没有明确定义它们的索引时顶点是如何连接的。我假设索引是按顶点的顺序自动设置的,但我猜不是。
以下是我试图对指数执行的随机播放(放在ofApp::mousePressed()
中):
for (int i = numVerts - 1; i >= 0; i --) {
int index = (int)ofRandom(i);
int tempIndex = mesh.getIndex(index);
mesh.setIndex(index, mesh.getIndex(i));
mesh.setIndex(i, tempIndex);
}
答案 0 :(得分:0)
您可以使用混洗矢量来设置索引。例如:
vector<int> indices(numVerts);
// Init indices vector
int acc = 0;
for(vector<int>::iterator it = indices.begin(); it != indices.end(); ++it){
*it = acc;
++acc;
}
// Shuffle
random_shuffle(indices.begin(), indices.end());
// Update indices for the mesh
mesh.clearIndices();
mesh.addIndices(indices);
您可以看到here指数如何运作。基本上,它们可以帮助您告诉图形卡如何连接ofMesh
的顶点。