亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? md2.cpp

?? Quake中的MD2模型導(dǎo)入
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
//***********************************************************************//
//																		 //
//		- "Talk to me like I'm a 3 year old!" Programming Lessons -		 //
//                                                                       //
//		$Author:		DigiBen		digiben@gametutorials.com			 //
//																		 //
//		$Program:		MD2 Loader										 //
//																		 //
//		$Description:	Demonstrates how to load a Quake2 MD2 Model		 //
//																		 //
//		$Date:			2/6/02											 //
//																		 //
//***********************************************************************//


#include "main.h"
#include "Md2.h"


/////////////////////////////////////////////////////////////////////////
//
// This file holds the code to load the Quake2 models from a .Md2 format.
// The .Md2 file is usually stored in a .zip file (don't let the extension
// fool you, just rename it to .zip), depending on where you get the models
// from.  The CLoadMD2 class handles the loading, but we draw the model
// externally on our own in main.cpp.  I created a converter function
// to convert to our already used model and object structures.  This way
// eventually we can create a model library that can load any type of
// model that we support, as well as use inheritance to create a new class
// for each file format for the small things that each model format needs differently.
// Like the other loading tutorials, we calculate our own vertex normals.
// The .Md2 format is REALLY simple to load.  That is why I chose it.  The
// next tutorial will show how to load and animate Md2 files.  Next, we
// will move from key frame animation to skeletal animation with the Quake3
// .Md3 files.  This is also a wonderfuly easy format to load and use.
//
//


///////////////////////////////// CLOAD MD2 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	This constructor initializes the md2 structures
/////
///////////////////////////////// CLOAD MD2 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

CLoadMD2::CLoadMD2()
{
	// Here we initialize our structures to 0
	memset(&m_Header, 0, sizeof(tMd2Header));

	// Set the pointers to null
	m_pSkins=NULL;
	m_pTexCoords=NULL;
	m_pTriangles=NULL;
	m_pFrames=NULL;
}


///////////////////////////////// IMPORT MD2 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	This is called by the client to open the .Md2 file, read it, then clean up
/////
///////////////////////////////// IMPORT MD2 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

bool CLoadMD2::ImportMD2(t3DModel *pModel, char *strFileName, char *strTexture)
{
	char strMessage[255] = {0};

	// Open the MD2 file in binary
	m_FilePointer = fopen(strFileName, "rb");

	// Make sure we have a valid file pointer (we found the file)
	if(!m_FilePointer) 
	{
		// Display an error message and don't load anything if no file was found
		sprintf(strMessage, "Unable to find the file: %s!", strFileName);
		MessageBox(NULL, strMessage, "Error", MB_OK);
		return false;
	}
	
	// Just like most file formats, there is a header that needs to be read
	// from the .Md2 format.  If you look at the tMd2Header structure you will
	// find all the data that will be read in.  It's nice to know up front about
	// the data that we will be reading.  This makes it easy to just to large
	// binary reads using fread, instead of counting and reading chunks.

	// Read the header data and store it in our m_Header member variable
	fread(&m_Header, 1, sizeof(tMd2Header), m_FilePointer);

	// For some reason, .Md2 files MUST have a version of 8.  I am not sure why,
	// but if it doesn't there is something wrong and the header was read in
	// incorrectly, or perhaps the file format is bad.
	if(m_Header.version != 8)
	{
		// Display an error message for bad file format, then stop loading
		sprintf(strMessage, "Invalid file format (Version not 8): %s!", strFileName);
		MessageBox(NULL, strMessage, "Error", MB_OK);
		return false;
	}

	// Now that we made sure the header had correct data, we want to read in the
	// rest of the data.  Once the data is read in, we need to convert it to our structures.
	// Since we are only reading in the first frame of animation, there will only
	// be ONE object in our t3DObject structure, held within our pModel variable.
	ReadMD2Data();
	
	// Here we pass in our model structure to it can store the read Quake data
	// in our own model and object structure data
	ConvertDataStructures(pModel);

	// After we have read the whole MD2 file, we want to calculate our own vertex normals.
	ComputeNormals(pModel);

	// If there is a valid texture name passed in, we want to set the texture data
	if(strTexture)
	{
		// Create a local material info structure
		tMaterialInfo texture;

		// Copy the name of the file into our texture file name variable
		strcpy(texture.strFile, strTexture);

		// Since there is only one texture for a .Md2 file, the ID is always 0
		texture.texureId = 0;

		// The tile or scale for the UV's is 1 to 1 (but Quake saves off a 0-256 ratio)
		texture.uTile = texture.uTile = 1;

		// We only have 1 material for a model
		pModel->numOfMaterials = 1;

		// Add the local material info to our model's material list
		pModel->pMaterials.push_back(texture);
	}

	// Clean up after everything
	CleanUp();

	// Return a success
	return true;
}


///////////////////////////////// READ MD2 DATA \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	This function reads in all of the model's data, except the animation frames
/////
///////////////////////////////// READ MD2 DATA \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void CLoadMD2::ReadMD2Data()
{
	// Create a larger buffer for the frames of animation (not fully used yet)
	unsigned char buffer[MD2_MAX_FRAMESIZE];
	int j = 0;

	// Here we allocate all of our memory from the header's information
	m_pSkins     = new tMd2Skin [m_Header.numSkins];
	m_pTexCoords = new tMd2TexCoord [m_Header.numTexCoords];
	m_pTriangles = new tMd2Face [m_Header.numTriangles];
	m_pFrames    = new tMd2Frame [m_Header.numFrames];

	// Next, we start reading in the data by seeking to our skin names offset
	fseek(m_FilePointer, m_Header.offsetSkins, SEEK_SET);
	
	// Depending on the skin count, we read in each skin for this model
	fread(m_pSkins, sizeof(tMd2Skin), m_Header.numSkins, m_FilePointer);
	
	// Move the file pointer to the position in the file for texture coordinates
	fseek(m_FilePointer, m_Header.offsetTexCoords, SEEK_SET);
	
	// Read in all the texture coordinates in one fell swoop
	fread(m_pTexCoords, sizeof(tMd2TexCoord), m_Header.numTexCoords, m_FilePointer);

	// Move the file pointer to the triangles/face data offset
	fseek(m_FilePointer, m_Header.offsetTriangles, SEEK_SET);
	
	// Read in the face data for each triangle (vertex and texCoord indices)
	fread(m_pTriangles, sizeof(tMd2Face), m_Header.numTriangles, m_FilePointer);
			
	// Move the file pointer to the vertices (frames)
	fseek(m_FilePointer, m_Header.offsetFrames, SEEK_SET);

	// Assign our alias frame to our buffer memory
	tMd2AliasFrame *pFrame = (tMd2AliasFrame *) buffer;

	// Allocate the memory for the first frame of animation's vertices
	m_pFrames[0].pVertices = new tMd2Triangle [m_Header.numVertices];

	// Read in the first frame of animation
	fread(pFrame, 1, m_Header.frameSize, m_FilePointer);

	// Copy the name of the animation to our frames array
	strcpy(m_pFrames[0].strName, pFrame->name);
			
	// After we have read in the data for the model, since there is animation,
	// This means that there are scale and translation values to be dealt with.
	// To apply the scale and translation values, we simply multiply the scale (x, y, z)
	// by the current vertex (x, y, z).  Also notice that we switch the Y and Z values
	// so that Y is faces up, NOT Z.
	
	// Store off a vertex array pointer to cut down large lines of code
	tMd2Triangle *pVertices = m_pFrames[0].pVertices;

	// Go through all of the number of vertices and assign the scale and translations.
	// Store the vertices in our current frame's vertex list array, while swapping Y and Z.
	// Notice we also negate the Z axis as well to make the swap correctly.
	for (j=0; j < m_Header.numVertices; j++)
	{
		pVertices[j].vertex[0] = pFrame->aliasVertices[j].vertex[0] * pFrame->scale[0] + pFrame->translate[0];
		pVertices[j].vertex[2] = -1 * (pFrame->aliasVertices[j].vertex[1] * pFrame->scale[1] + pFrame->translate[1]);
		pVertices[j].vertex[1] = pFrame->aliasVertices[j].vertex[2] * pFrame->scale[2] + pFrame->translate[2];
	}
}


///////////////////////////////// CONVERT DATA STRUCTURES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	This function converts the .md2 structures to our own model and object structures
/////
///////////////////////////////// CONVERT DATA STRUCTURES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void CLoadMD2::ConvertDataStructures(t3DModel *pModel)
{
	int j = 0, i = 0;
	
	// Assign the number of objects, which is 1 since we only want 1 frame
	// of animation.  In the next tutorial each object will be a key frame
	// to interpolate between.
	pModel->numOfObjects = 1;

	// Create a local object to store the first frame of animation's data
	t3DObject currentFrame = {0};

	// Assign the vertex, texture coord and face count to our new structure
	currentFrame.numOfVerts   = m_Header.numVertices;
	currentFrame.numTexVertex = m_Header.numTexCoords;
	currentFrame.numOfFaces   = m_Header.numTriangles;

	// Allocate memory for the vertices, texture coordinates and face data.
	currentFrame.pVerts    = new CVector3 [currentFrame.numOfVerts];
	currentFrame.pTexVerts = new CVector2 [currentFrame.numTexVertex];
	currentFrame.pFaces    = new tFace [currentFrame.numOfFaces];

	// Go through all of the vertices and assign them over to our structure
	for (j=0; j < currentFrame.numOfVerts; j++)
	{
		currentFrame.pVerts[j].x = m_pFrames[0].pVertices[j].vertex[0];
		currentFrame.pVerts[j].y = m_pFrames[0].pVertices[j].vertex[1];
		currentFrame.pVerts[j].z = m_pFrames[0].pVertices[j].vertex[2];
	}

	// We can now free the old vertices stored in this frame of animation
	delete m_pFrames[0].pVertices;

	// Go through all of the uv coordinates and assign them over to our structure.
	// The UV coordinates are not normal uv coordinates, they have a pixel ratio of
	// 0 to 256.  We want it to be a 0 to 1 ratio, so we divide the u value by the
	// skin width and the v value by the skin height.  This gives us our 0 to 1 ratio.
	// For some reason also, the v coodinate is flipped upside down.  We just subtract
	// the v coordinate from 1 to remedy this problem.
	for (j=0; j < currentFrame.numTexVertex; j++)
	{

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91麻豆精品国产自产在线| 欧美视频一区二区在线观看| 亚洲电影你懂得| 国产嫩草影院久久久久| 91极品美女在线| 国产精品2024| 青青草原综合久久大伊人精品优势| 国产精品无遮挡| 日韩欧美一级片| 欧美视频在线一区二区三区| 风流少妇一区二区| 另类专区欧美蜜桃臀第一页| 亚洲国产精品一区二区久久| 国产精品亚洲午夜一区二区三区 | 色天天综合久久久久综合片| 精品一区二区免费视频| 亚洲国产你懂的| 国产精品久久久久aaaa樱花| wwwwxxxxx欧美| 欧美一级艳片视频免费观看| 91理论电影在线观看| 国产成人精品亚洲777人妖| 久久精品国产免费看久久精品| 一区二区三区在线播放| 国产精品天美传媒| 久久精品日韩一区二区三区| 日韩视频永久免费| 666欧美在线视频| 欧美四级电影在线观看| 一本大道久久a久久综合| 国产91高潮流白浆在线麻豆| 韩国av一区二区| 久久精品国产亚洲a| 日本成人在线不卡视频| 亚洲一区二区视频| 亚洲毛片av在线| 亚洲私人黄色宅男| 亚洲欧洲精品一区二区三区| 国产精品另类一区| 国产精品白丝在线| 中文字幕亚洲精品在线观看 | 欧美午夜电影一区| 成人精品免费网站| 丁香六月综合激情| 国产成人精品亚洲午夜麻豆| 大美女一区二区三区| 国产成人午夜视频| 成人免费av资源| 成人精品视频.| 色综合色综合色综合色综合色综合| 成人av影院在线| www.欧美精品一二区| 国产精品一二三| 99re热这里只有精品免费视频| av亚洲精华国产精华精| 色一情一乱一乱一91av| 欧美午夜在线观看| 欧美日本国产一区| 欧美va亚洲va| 欧美激情一区二区| 亚洲女子a中天字幕| 亚洲国产精品一区二区尤物区| 亚洲与欧洲av电影| 日韩av电影一区| 激情小说亚洲一区| av在线一区二区| 欧美日韩免费在线视频| 91精品国产日韩91久久久久久| xfplay精品久久| 成人欧美一区二区三区小说| 一区二区三区精品| 日韩中文字幕区一区有砖一区| 国产精品综合久久| 91蜜桃婷婷狠狠久久综合9色| 欧美日韩综合在线免费观看| 日韩一级片网站| 欧美激情一区二区三区四区| 伊人夜夜躁av伊人久久| 日韩高清一级片| 成人午夜视频在线| 欧美在线观看视频在线| 精品久久久久久无| 亚洲天堂免费在线观看视频| 日av在线不卡| 99麻豆久久久国产精品免费优播| 欧美日韩精品一区二区三区| 26uuu色噜噜精品一区二区| 亚洲色欲色欲www在线观看| 日韩影视精彩在线| 成人av午夜电影| 91精品免费观看| 综合av第一页| 极品少妇一区二区| 99精品视频一区二区三区| 7799精品视频| **网站欧美大片在线观看| 日本欧美一区二区三区| 99re这里只有精品首页| 亚洲精品在线三区| 一区二区三区四区av| 国产一区二区三区精品欧美日韩一区二区三区 | 亚洲超碰97人人做人人爱| 国产精品一区二区三区乱码| 欧美午夜理伦三级在线观看| 久久久亚洲午夜电影| 亚洲国产精品久久久久婷婷884| 国产精品影音先锋| 91精品福利在线一区二区三区| 中文字幕永久在线不卡| 韩国v欧美v亚洲v日本v| 在线成人小视频| 亚洲欧美日韩一区二区 | 午夜精品久久一牛影视| 成人激情视频网站| 精品久久久久久久久久久久久久久久久 | 国产欧美久久久精品影院| 丝袜美腿高跟呻吟高潮一区| 97久久超碰国产精品| 国产亚洲婷婷免费| 另类调教123区| 欧美一区二区三区在线看| 一区二区三区产品免费精品久久75| 国产一区999| 久久综合久久综合久久| 免费成人你懂的| 91精品国产黑色紧身裤美女| 亚洲国产中文字幕| 色嗨嗨av一区二区三区| 专区另类欧美日韩| 国产成人免费在线| 久久精品网站免费观看| 国产精品亚洲一区二区三区在线 | 久久精品国产久精国产爱| 3d成人动漫网站| 日本女优在线视频一区二区| 在线播放一区二区三区| 亚洲chinese男男1069| 日本乱码高清不卡字幕| 一区二区三国产精华液| 日本国产一区二区| 一区二区在线电影| 在线观看免费视频综合| 亚洲免费在线观看视频| 色综合一区二区三区| 一区二区三区四区亚洲| 色哟哟精品一区| 香蕉影视欧美成人| 777精品伊人久久久久大香线蕉| 日韩精品免费专区| 日韩精品一区二区在线| 精品在线你懂的| 久久精品在线免费观看| 国产宾馆实践打屁股91| 中文字幕免费不卡| 96av麻豆蜜桃一区二区| 一二三区精品福利视频| 欧美日韩精品一区二区在线播放| 日韩国产在线一| 日韩欧美精品三级| 激情伊人五月天久久综合| 国产欧美日韩综合| 91色综合久久久久婷婷| 亚洲成人综合视频| 欧美一区二区三区喷汁尤物| 久久97超碰国产精品超碰| 国产日韩欧美在线一区| 91美女片黄在线观看91美女| 午夜精品久久久久久久久久久| 精品日韩欧美一区二区| 国产91综合一区在线观看| 日韩毛片在线免费观看| 欧美日韩在线不卡| 精品在线视频一区| 亚洲免费毛片网站| 91精品国产一区二区| 国产a区久久久| 亚洲国产一区视频| 国产日韩欧美在线一区| 欧美色手机在线观看| 精品国产伦一区二区三区观看体验 | 久久精品网站免费观看| 日本韩国欧美三级| 久久99热这里只有精品| 亚洲欧美综合另类在线卡通| 日韩亚洲国产中文字幕欧美| 成人aaaa免费全部观看| 日日摸夜夜添夜夜添精品视频| 国产精品网站在线| 日韩一区二区免费在线观看| 成人黄色在线视频| 美女mm1313爽爽久久久蜜臀| 亚洲视频图片小说| 精品1区2区在线观看| 欧美三区免费完整视频在线观看| 国产精品一区二区在线观看不卡| 视频在线观看国产精品| 国产精品看片你懂得| 久久午夜国产精品| 51精品秘密在线观看| 色综合咪咪久久|