当前位置: 首页>>代码示例>>C++>>正文


C++ VertexData::addTriangle方法代码示例

本文整理汇总了C++中VertexData::addTriangle方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexData::addTriangle方法的具体用法?C++ VertexData::addTriangle怎么用?C++ VertexData::addTriangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VertexData的用法示例。


在下文中一共展示了VertexData::addTriangle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: create


//.........这里部分代码省略.........
    tmp_verts.push_back(Vec3(  z, -x,  0 ));
    tmp_verts.push_back(Vec3( -z, -x,  0 ));
	
	// triangle indices
	int idxs[] = { 
		1,4,0, 4,9,0, 4,5,9, 8,5,4, 1,8,4, 
		1,10,8, 10,3,8, 8,3,5, 3,2,5, 3,7,2, 
		3,10,7, 10,6,7, 6,11,7, 6,0,11, 6,1,0,
		10,1,6, 11,0,9, 2,11,9, 5,2,9, 11,2,7
	};
	
	int num = 4 * 5 * 3;
	for(int i = 0; i < num; ++i) {
		vertex_data.indices.push_back(idxs[i]);
	}
	
	if(detail > 8) {
		detail = 8;
	}
	else if (detail < 0) {
		detail = 0;
	}
	
	// iterator over the number of detail level and
	for(int i = 0; i < detail; ++i) {
		vector<int> indices2;
		vector<Vec3> tmp_verts2;
		for(int j = 0, idx = 0; j < vertex_data.indices.size(); j+=3) {
			
			// add triangle indices
			indices2.push_back(idx++); 
			indices2.push_back(idx++); 
			indices2.push_back(idx++);
						
			indices2.push_back(idx++); 
			indices2.push_back(idx++); 
			indices2.push_back(idx++);
			
			indices2.push_back(idx++); 
			indices2.push_back(idx++); 
			indices2.push_back(idx++);
			
			indices2.push_back(idx++); 
			indices2.push_back(idx++); 
			indices2.push_back(idx++);
						
			// split triangle.
			Vec3 v1 = tmp_verts[vertex_data.indices[j+0]]; 
			Vec3 v2 = tmp_verts[vertex_data.indices[j+1]]; 
			Vec3 v3 = tmp_verts[vertex_data.indices[j+2]]; 
		
			v1.normalize();
			v2.normalize();
			v3.normalize();
			
			Vec3 a = (v1 + v2) * 0.5f;
			Vec3 b = (v2 + v3) * 0.5f; 
			Vec3 c = (v3 + v1) * 0.5f; 
			
			a.normalize();
			b.normalize();
			c.normalize();
			
			tmp_verts2.push_back(v1); 
			tmp_verts2.push_back(a); 
			tmp_verts2.push_back(c);
			
			tmp_verts2.push_back(a); 
			tmp_verts2.push_back(v2); 
			tmp_verts2.push_back(b);
			
			tmp_verts2.push_back(a);
			tmp_verts2.push_back(b); 
			tmp_verts2.push_back(c);
			
			tmp_verts2.push_back(c); 
			tmp_verts2.push_back(b); 
			tmp_verts2.push_back(v3);
		}
		
		tmp_verts = tmp_verts2;
		vertex_data.indices = indices2;
	}
			
	vector<Vec3>::iterator it = tmp_verts.begin();
	while(it != tmp_verts.end()) {
		vertex_data.addVertex((*it) * radius);		
		++it;
	}
	
	// add the triangles
	size_t len = vertex_data.indices.size();
	for(int i = 0; i < len; i += 3) {
		vertex_data.addTriangle(
			vertex_data.indices[i]
			,vertex_data.indices[i+1]
			,vertex_data.indices[i+2]
		);
	}
}
开发者ID:arneboon,项目名称:roxlu,代码行数:101,代码来源:IcoSphere.cpp


注:本文中的VertexData::addTriangle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。