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

📄 3dsload.h

📁 这是书上的代码
💻 H
字号:
///////////////////////////////////////////////////////////////////////////////////////////////
//		3dsload.h	2001,12.13 Edited by JiangZibin
//		Boxes Rendering Engine//		3D Studio object reader///////////////////////////////////////////////////////////////////////////////////////////////#ifndef __3DSLOAD_H#define __3DSLOAD_H//typedef char  byte;                  // 8-bit
typedef short word;                  // 16-bit
typedef unsigned short uword;         // 16-bit
typedef int   dword;                 // 32-bit
typedef float float32;               // 32-bit float#define MAXNAMESIZE 50

#include "gl\gl.h"
#include "gl\glu.h"
typedef struct {	uword p0,p1,p2;	word flags;}H3dsFace;typedef struct {	float32 x;	float32 y;	float32 z;}H3dsVert;typedef struct {	float32 u;	float32 v;}H3dsMap;// Material structurestypedef struct {	char name[MAXNAMESIZE];	uword  NumFaces;	word *faces;}H3dsMatList;typedef struct {	float32 red;	float32 green;	float32 blue;} H3dsRGBColor;typedef struct {	char texturename[MAXNAMESIZE];	word options;} H3dsTexture;typedef struct {	char name[MAXNAMESIZE];	H3dsRGBColor ambient;	H3dsRGBColor diffuse;	H3dsRGBColor specular;	word mat_type;	int doublesided;	H3dsTexture texture;	int offset;
	float32 alpha;} H3dsMat;// Object and scene structurestypedef struct {	char name[MAXNAMESIZE]; // object name, zero terminated	uword NumFaces;           // number of faces in face list	uword NumVerts;           // number of vertices in vertex list	uword NumMaps;            // number of mapping coordinates in map list	int matrix;             // 1 if transformation matrix is loaded	uword NumBindings;        // number of binding materials	H3dsFace *facelist;     // array of face indices	H3dsVert *vertlist;     // array of vertices	H3dsMap  *maplist;      // array of texture coordinates	float32 TraMatrix[3*4]; // 3*4 rotation matrix, 3*1 translation matrix	H3dsMatList *bindings;  // Binds faces to materials	int offset;             // Our starting index into outgl's vertex list}H3dsMeshObj;typedef struct {	uword meshobjs;              // Mumber of meshobjects in meshobjlist	H3dsMeshObj *meshobjlist;  // array of meshobjects	uword NumMaterials;          // Number of materials in the scene	H3dsMat *material;         // array of materials} H3dsScene;// Each 3DS data-chunk starts with a 6 byte header.// The first item in the header is a 2 byte (word) id-number.// After that follows a dword wich gives the size of// the data-chunk including the header. The size can be used// as an relative offset to the next chunk.enum {  CHUNK_RGB1      	= 0x0010,	// 3 floats of RGB  CHUNK_RGB2      	= 0x0011,	// 3 bytes of RGB  CHUNK_RGB3        = 0x0012,	// Rgb (byte) gamma corrected
  CHUNK_RGB4        = 0x0013,	// Rgb (float) gamma corrected  CHUNK_AMOUNT      = 0x0030,  CHUNK_MAIN      	= 0x4D4D,	//MAIN3DS--Primary chunk  CHUNK_OBJMESH     = 0x3D3D,	//EDIT3DS--this is the start of the editor config  CHUNK_BKGCOLOR    = 0x1200,	//EDIT_BACKGR  CHUNK_AMBCOLOR  	= 0x2100,	//EDIT_AMBIENT  CHUNK_OBJBLOCK  	= 0x4000,	//EDIT_OBJECT  CHUNK_TRIMESH   	= 0x4100,	//OBJ_TRIMESH  CHUNK_VERTLIST    = 0x4110,	  CHUNK_FACELIST    = 0x4120,  CHUNK_FACEMAT     = 0x4130,  CHUNK_MAPLIST     = 0x4140,  CHUNK_SMOOLIST    = 0x4150,  CHUNK_TRMATRIX    = 0x4160,  CHUNK_LIGHT     	= 0x4600,  CHUNK_SPOTLIGHT   = 0x4610,  CHUNK_CAMERA    	= 0x4700,  CHUNK_MATERIAL  	= 0xAFFF,	//EDIT_MATERIAL  CHUNK_MATNAME   	= 0xA000,  CHUNK_AMBIENT   	= 0xA010,  CHUNK_DIFFUSE   	= 0xA020,  CHUNK_SPECULAR  	= 0xA030,  CHUNK_SHININESS		= 0xA040,  CHUNK_SHINE_STRENGTH  = 0xA041,
  CHUNK_TRANSPARENCY    = 0xA050,  CHUNK_DOUBLESIDED     = 0xA081,  CHUNK_TEXTURE   	= 0xA200,  CHUNK_BUMPMAP   	= 0xA230,  CHUNK_MAPFILENAME = 0xA300,  CHUNK_MAPOPTIONS  = 0xA351,  CHUNK_KEYFRAMER 	= 0xB000,		//KEYF3DS--this is the start of the keyframer config  CHUNK_FRAMES      = 0xB008};
//颜色结构
typedef struct {
	GLfloat red;
	GLfloat green;
	GLfloat blue;
	GLfloat alpha;
}OUTGL_RGB;
//顶点结构(顶点纹理,法向量,顶点坐标)
typedef struct {
	GLfloat u,v;                     // Texture Coordinates
	GLfloat nx, ny, nz;              // Normal Vector
	GLfloat x, y, z;                 // XYZ coordinates for vertex
}OUTGL_VERTEX;
//三角形法向量结构
typedef struct {
	GLfloat n0, n1, n2;              // Triangle's normal
}OUTGL_NORMAL;
//三角形结构  
typedef struct {
	GLuint p0, p1, p2;               // Indices into OUTGL's vertex array
}OUTGL_TRIANGLE;
//三角形面结构
typedef struct {                     // A surface is a TRIANGLE but with a
	GLuint p0, p1, p2;               // normal for the triangle attached
	GLfloat n0, n1, n2;
}OUTGL_SURFACE;
//三角形列表结点
struct OUTGL_TRIANGLENODE {               // LList used to keep track of which
	OUTGL_SURFACE *triangle;                 // triangles touch which vertices. Links
	struct OUTGL_TRIANGLENODE *next;        // the vertices back to the triangles.
};
typedef struct OUTGL_TRIANGLENODE TRIANGLENODE;
//
typedef struct {
	char name[50];						// Material name
	OUTGL_RGB ambient;						// 漫反射颜色
	OUTGL_RGB diffuse;						//
	OUTGL_RGB specular;
	int doublesided;
	GLuint NumTriangles;                  // # of triangles of this material
	OUTGL_SURFACE *TriangleIndexList;        // array of 3-tuple ints which are indexes into VertexList[]
	OUTGL_TRIANGLE *CrunchedTriangleIndexList;
	char texturename[50];
	GLuint textureID;

	GLuint NumStrips;                     // Number of different triangle strips
	GLuint *StripStart;                // Index into StripPoint of each strip's starting point
	GLuint *StripLength;               // The number of points in each strip
	GLuint NumStripPoints;                // Number of points
	GLuint *StripPoint;                // Indexes into the global vertex list
}POLYGONLIST;

typedef struct
{
	GLuint NumVertex;
	OUTGL_VERTEX *VertexLists;
	GLuint NumPolygon;
	GLuint strip;
	POLYGONLIST	 *PolygonLists;
}M3DSObject;

M3DSObject* Load3DSObject(char *filename);	//读取3DS文件void Draw3DSObject(M3DSObject *object);
void Free3DSObject(M3DSObject *object);
void Unitize3DSObject(M3DSObject *object);
void GetMinMax3DS(float min[3], float max[3], float *scaleFactor);
#endif

⌨️ 快捷键说明

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