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


C++ Triangle::SetVertex方法代码示例

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


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

示例1: Vertex

Mesh::Mesh(const char* filename)
:_vertices()
,_triangles()
{
	fstream fileStream;
	fileStream.open(filename, fstream::in | iostream::binary);

	if( fileStream.is_open() )
	{
		unsigned short chunkId;
		unsigned long chunkLength;
		unsigned short chunkQuantity;

		// Get file length
		fileStream.seekg(0, ios::end);
		int fileLength = fileStream.tellg();
		fileStream.seekg(0, ios::beg);

		// Loop through chunk structure
		while( fileStream.tellg() < fileLength )
		{
			fileStream.read((char*)&chunkId, 2);
			fileStream.read((char*)&chunkLength, 4);

			switch( chunkId )
			{
			case 0x4d4d: // Main chunk
				break;

			case 0x3d3d: // 3D editor chunk
				break;

			case 0x4000: // Object block
				{
					char name[20];

					// Read object name
					for( int count = 0; count < 20; ++count )
					{
						fileStream.read(&name[count], 1);
						if( name[count] == '\0' )
						{
							break;
						}
					}
				}
				break;

			case 0x4100: // Triangular mesh
				break;

			case 0x4110: // Vertices list
				fileStream.read((char*)&chunkQuantity, 2);
				for( unsigned short i = 0; i < chunkQuantity; ++i )
				{
					Vertex* vertex = new Vertex();
					if( vertex )
					{
						Vector3f nativePos;
						this->_vertices.push_back(vertex);
						for( int j = 0; j < 3; ++j )
						{
							fileStream.read((char*)(&nativePos[j]), 4);
						}

						// Convert from 3ds coordinates to opengl coordinates.
						vertex->SetPosition(nativePos.x, nativePos.z, -nativePos.y);
					}
				}
				break;

			case 0x4120: // Faces description
				fileStream.read((char*)&chunkQuantity, 2);
				for( unsigned short i = 0; i < chunkQuantity; ++i )
				{
					Triangle* triangle = new Triangle();
					if( triangle )
					{
						this->_triangles.push_back(triangle);
						unsigned short vertIndex;
						for( int j = 0; j < 3; ++j )
						{
							fileStream.read((char*)&vertIndex, 2);
							triangle->SetVertex(j, this->_vertices.at((unsigned int)vertIndex));
						}
						fileStream.read((char*)&vertIndex, 2); // Extra data
					}
				}
				break;

			case 0x4140: // Mapping coordinates list
				fileStream.read((char*)&chunkQuantity, 2);
				for( unsigned short i = 0; i < chunkQuantity; ++i )
				{
					Vertex* vertex = this->_vertices.at((unsigned int)i);
					if( vertex )
					{
						for( int j = 0; j < 2; ++j )
						{
							fileStream.read((char*)(&vertex->TextureCoords()[j]), 4);
//.........这里部分代码省略.........
开发者ID:vietjtnguyen,项目名称:ucla-winter09-cs174a-opengl-engine,代码行数:101,代码来源:Mesh.cpp


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