⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mobjfile.h

📁 一個簡單的游戲設計...好好玩的
💻 H
字号:
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <map>
#include <vector>
#include <string>
using namespace std;

struct Vertex3f
{
	float x, y, z;
};

struct Vertex2f
{
	float u,v;
};

struct Material4f
{
	float Ka[4];
	float Kd[4];
	float Ks[4];
	float Ns;
};

class MObjFile
{
protected:
	class Material
	{
	public:
		float Ka[4];
		float Kd[4];
		float Ks[4];
		float Ns;
		float d;

		Material()
		{ 
			for (int i=0;i<4;i++)
				Ka[i] = Kd[i] = Ks[i] = 1;
			Ns = 0;
			d = 1;
		}
	};

	class Vertex	
	{
	public:
		int IndexOfVertex;			// vertex (index of vList)
		int IndexOfNormal;			// normal (index of nList)
		int IndexOfTexture;		    // texture (index of tList)
		int IndexOfMaterial;		// material (index of material)
		Vertex() {};
		Vertex(int V_Index, int N_Index, int T_Index=0, int M_Index=0)
		{
			IndexOfVertex   = V_Index;
			IndexOfNormal   = N_Index;
			IndexOfTexture  = T_Index;
			IndexOfMaterial = M_Index;
		}
	};

	class Point3
	{
	public:
		GLfloat P[3];
		Point3 () 
		{
			for (int i=0;i<3;i++) P[i] = 0;
		}
		void Set (GLfloat *V)
		{
			for (int i=0;i<3;i++) P[i] = V[i];
		}
		GLfloat& operator[](int Index)
		{
			return P[Index];
		}
	};

	class FACE		// faceList 
	{
	public:	
		Vertex V[3];		// 3 vertex for each face
	
		FACE () {}
		void Set (Vertex &V1, Vertex &V2, Vertex &V3) 
		{
			V[0] = V1; 
			V[1] = V2;
			V[2] = V3;
		}
	
		Vertex& operator[](int Index)
		{
			return V[Index];
		}
	};

	int NumOfVertex,
	    NumOfNormal,
	    NumOfTexture,
	    NumOfFace;

	Point3 *vList,
		   *nList,
		   *tList;

	FACE *fList;

	int NumOfMaterial,MaxSupport;
	map <string,int> MaterialMap;
	Material *mList;

	void CountTokens(FILE *objFile);
	void AllocateArrays();
	void LoadMesh(FILE *objFile);
	void LoadTex(const char *texName);

public:
	MObjFile(void);
	~MObjFile(void);
	bool LoadFile(const char *fileName);
	int GetNumOfMaterial() { return NumOfMaterial; }
	int GetNumOfNormal()  { return NumOfNormal; }
	int GetNumOfTexture() { return NumOfTexture; }
	int GetNumOfVertex() { return NumOfVertex; }
	int GetNumOfFace() { return NumOfFace; }
	void GetFaceVertex(const int face,const int vertex, Vertex3f &V);
	void GetFaceNormal(const int face,const int vertex, Vertex3f &N);
	void GetFaceTexture(const int face,const int vertex, Vertex2f &T);
	void GetFaceMaterial(const int face,const int vertex, Material4f &M);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -