This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MD2Model.h
125 lines (102 loc) · 3.27 KB
/
MD2Model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// MD2Model.h
// CelShader
//
// Created by Sebastian Gamboa on 08-09-08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#define IDP2 844121161
#define MD2_HEADER_VERSION 8
/* MD2 header */
typedef struct md2_header_t
{
long ident; /* magic number: "IDP2" */
long version; /* version: must be 8 */
long skinwidth; /* texture width */
long skinheight; /* texture height */
long framesize; /* size in bytes of a frame */
long num_skins; /* number of skins */
long num_vertices; /* number of vertices per frame */
long num_st; /* number of texture coordinates */
long num_tris; /* number of triangles */
long num_glcmds; /* number of opengl commands */
long num_frames; /* number of frames */
long offset_skins; /* offset skin data */
long offset_st; /* offset texture coordinate data */
long offset_tris; /* offset triangle data */
long offset_frames; /* offset frame data */
long offset_glcmds; /* offset OpenGL command data */
long offset_end; /* offset end of file */
} MD2Header;
/* Vector */
typedef float vec3_t[3];
/* Texture name */
typedef struct md2_skin_t
{
char name[64]; /* texture file name */
} MD2Skin;
/* Texture coords */
typedef struct md2_texCoord_t
{
short s;
short t;
} MD2TexCoord;
/* Triangle info */
typedef struct md2_triangle_t
{
unsigned short vertex[3]; /* vertex indices of the triangle */
unsigned short st[3]; /* tex. coord. indices */
} MD2Triangle;
/* Compressed vertex */
typedef struct md2_vertex_t
{
unsigned char v[3]; /* position */
unsigned char normalIndex; /* normal vector index */
} MD2Vertex;
/* Model frame */
typedef struct md2_frame_t
{
vec3_t scale; /* scale factor */
vec3_t translate; /* translation vector */
char name[16]; /* frame name */
MD2Vertex *verts; /* list of frame's vertices */
} MD2Frame;
typedef long MD2GLCmnd;
@interface MD2Model : NSObject {
NSString *modelFile;
NSString *textureFile;
NSString *shaderFile;
BOOL isCellShaded;
MD2Header *header;
MD2Skin *skins;
MD2TexCoord *texcoords;
MD2Triangle *triangles;
MD2Frame *frames;
MD2GLCmnd *glcmds;
GLfloat *vertex;
GLfloat *normals;
GLfloat *textures;
vec3_t lightAngle; // The Direction Of The Light
GLuint shaderTexture[1]; // Storage For One Texture
unsigned char shaderData[32][4]; // Storage For The 96 Shader Values
GLubyte *textureData;
GLuint texId;
}
- (MD2Model *)initWithModelPath:(NSString *)modelPath andTexturePath:(NSString *)texturePath cellShaded:(bool)cellShaded;
- (bool)load;
- (void)draw;
@end
typedef struct tagMATRIX // A Structure To Hold An OpenGL Matrix
{
float data[16]; // We Use [16] Due To OpenGL's Matrix Format
}
MATRIX;
typedef struct tagVECTOR // A Structure To Hold A Single Vector
{
float X, Y, Z; // The Components Of The Vector
}
VECTOR;