操纵网格对象中的索引
Manipulating Indices in an ofMesh object
仍然想知道如何正确使用ofMesh
,我现在的目标是拥有一个点云,拥有随机连接的点(使用索引),并能够在点击时打乱索引。有人向我指出了使用费雪-耶茨洗牌的方向,但在我找到指数之前,这是行不通的。
目前,我只是通过添加具有随机坐标的顶点来创建网格,但没有明确定义任何索引。当我使用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);
}
您可以使用混洗向量来设置索引。例如:
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);
你可以在这里看到指数是如何工作的。基本上,它们可以帮助您告诉图形卡如何连接ofMesh
的顶点。
相关文章:
- 如何查找哪个类对象位于数组的特定索引上(多态性)
- 排序谓词没有传递对索引对象的引用?
- 重载运算符 [] 用于从对象数组中给出特定索引
- 如何检索由带通配符的字符串索引的对象
- 如何从 boost::container::vector<std::string>::iterator 访问索引和对象?
- 如何确保在 FATFS 中倒带目录对象的读取索引?
- 使用对象的索引从矢量中删除对象
- 在对象上运行,运算符重载 () 与索引
- 通过查找重复顶点从 vec3 对象的向量计算索引
- 从对象创建矢量包装器,该对象只允许使用索引访问向量
- 将指针分配给字符串对象的第一个也是最后一个索引
- 为对象指针数组的每个空索引创建新对象
- 如何获得具有多个索引的对象列表
- 具有成员变量的对象 Const 数组 = 先前索引成员变量的总和
- 通过索引从向量中删除对象
- 非冗余对列表中对象的索引
- 在带有智能指针的大量对象中创建多个索引
- C :通过索引从列表中获取对象无效
- 操纵网格对象中的索引
- 试图通过指针索引对象数组的数组时出现分段错误