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


C++ Model3D::SetNormalMapTexture方法代码示例

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


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

示例1: sizeof

bool MD2Loader::LoadModel(const char* filename, Model3D& model, const char* textureFilename, const char* normalMapTextureFilename)
{
	ifstream   file;           

	// Try to open MD2 file
	file.open( filename, ios::in | ios::binary );
	if(file.fail())
	{
		return false;
	}
	// Read file header
	Md2Header header;         
	file.read( reinterpret_cast<char*>(&header), sizeof( Md2Header ) );
		
	// Verify that this is a MD2 file (check for the magic number and version number)
	if( (header.indent != MD2_IDENT) && (header.version != MD2_VERSION) )
	{
		// This is not a MD2 model
		file.close();
		return false;
	}

	// Allocate the memory we need
	Md2Triangle* triangles = new Md2Triangle[header.numTriangles];
	// We are only interested in the first frame 
	BYTE* frameBuffer = new BYTE[ header.frameSize ];
	Md2Frame* frame = reinterpret_cast<Md2Frame*>(frameBuffer);
	Md2TexCoord* texCoords = new Md2TexCoord[header.numTexCoords];

	// Read polygon data...
	file.seekg( header.offsetTriangles, ios::beg );
	file.read( reinterpret_cast<char*>(triangles), sizeof(Md2Triangle) * header.numTriangles );	
		
	// Read frame data...
	file.seekg( header.offsetFrames, ios::beg );
	file.read( reinterpret_cast<char*>(frame), header.frameSize );	

	// Read texture coordinate data
	file.seekg( header.offsetTexCoords, std::ios::beg );
	file.read( reinterpret_cast<char*>(texCoords), sizeof(Md2TexCoord) * header.numTexCoords );

	// Close the file 2.0517745e-038
	file.close();

	//----------------------------------------------------------------------------------------------

	// Initialize model textures.
	bool bHasTexture = false;

	// Attempt to load texture
	if ( textureFilename != 0 )
	{
		BYTE* pTexture = new BYTE[header.skinWidth * header.skinHeight];
		Gdiplus::Color* pPalette = new Gdiplus::Color[256];
		
		bHasTexture = LoadPCX(textureFilename, pTexture, pPalette, &header);
		if ( !bHasTexture )
		{
			delete(pTexture);
			delete(pPalette);
		}
		else
		{
			model.SetTexture(pTexture, pPalette, header.skinWidth);
		}
	}

	// Attempt to load normal map texture
	if ( normalMapTextureFilename != 0 )
	{
		BYTE* pTexture = new BYTE[header.skinWidth * header.skinHeight];
		Gdiplus::Color* pPalette = new Gdiplus::Color[256];
		
		bool valid = LoadPCX(normalMapTextureFilename, pTexture, pPalette, &header);
		if (!valid)
		{
			delete(pTexture);
			delete(pPalette);
		}
		else
		{
			model.SetNormalMapTexture(pTexture, pPalette, header.skinWidth);
		}
	}

	// Polygon array initialization
	for ( int i = 0; i < header.numTriangles; ++i )
	{
		// TODO - Put your own code here to create a new Polygon and store it in your list
		//
		// The following are the expressions you need to access each of the indexes into the list of vertices:
		//
		// Index 0:  triangles[i].vertexIndex[0]
		// Index 1:  triangles[i].vertexIndex[1]
		// Index 2:  triangles[i].vertexIndex[2]

		Polygon3D newPoly = Polygon3D(triangles[i].vertexIndex[0],
									  triangles[i].vertexIndex[1],
									  triangles[i].vertexIndex[2]);
		newPoly.SetUVIndex(0, triangles[i].uvIndex[0]);
//.........这里部分代码省略.........
开发者ID:HampsterEater,项目名称:DirectXFramework,代码行数:101,代码来源:MD2Loader.cpp


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