-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd2.h
200 lines (162 loc) · 5.16 KB
/
md2.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// -----------------------------------------------------------------
// Learning Team B
// Members:
// Adam LeMmon
// Faith Satterthwaite
// Tom Fletcher
// Justin Ball
// CS 4280 – 11:30 am
// Final Project
// Dr. Rague
// Due: 12/06/12
// Version: 2.4
// -----------------------------------------------------------------
// We made five major improvements to this game
// 1) New controls
// 2) Enemy attack
// 3) HUD (heads up display)
// 4) Enemy health bars
// 5) New Weapon
// -----------------------------------------------------------------
#ifndef __MD2_H
#define __MD2_H
/*
MD2.H
The CMD2Model class
Author: Kevin Hawkins
Date: 3/29/2001
Description: The CMD2Model class loads, animates, and displays
Quake 2 (TM id Software) .MD2 model files.
*/
#include <windows.h> // standard Windows app include
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gl/gl.h> // standard OpenGL include
#include <gl/glu.h> // OpenGL utilties
#include "object.h"
#include "texture.h"
#include "vector.h"
#define MAX_FRAMES 512
// model animation states
enum modelState_t
{
MODEL_IDLE, // idle animation
MODEL_CROUCH, // crouch animation
MODEL_RUN, // running animation
MODEL_JUMP, // jumping animation
MODEL_FIRE, // model shooting gun
MODEL_DIE, // model dying
/*********************Faith Satterthwaite 12/1/2012**************************/
MODEL_WALK
/****************************************************************************/
};
/*
Vector Functionality
*/
// a single vertex
typedef struct
{
float point[3];
} vector_t;
vector_t operator-(vector_t a, vector_t b);
vector_t operator*(float f, vector_t b);
vector_t operator/(vector_t a, vector_t b);
vector_t operator+(vector_t a, vector_t b);
void CalculateNormal( float *p1, float *p2, float *p3 );
/*
MD2 Model Functionality
*/
// texture coordinate
typedef struct
{
float s;
float t;
} texCoord_t;
// texture coordinate index
typedef struct
{
short s;
short t;
} stIndex_t;
// info for a single frame point
typedef struct
{
unsigned char v[3];
unsigned char normalIndex; // not used
} framePoint_t;
// information for a single frame
typedef struct
{
float scale[3];
float translate[3];
char name[16];
framePoint_t fp[1];
} frame_t;
// data for a single triangle
typedef struct
{
unsigned short meshIndex[3]; // vertex indices
unsigned short stIndex[3]; // texture coordinate indices
} mesh_t;
typedef struct
{
int ident; // identifies as MD2 file "IDP2"
int version; // mine is 8
int skinwidth; // width of texture
int skinheight; // height of texture
int framesize; // number of bytes per frame
int numSkins; // number of textures
int numXYZ; // number of points
int numST; // number of texture
int numTris; // number of triangles
int numGLcmds;
int numFrames; // total number of frames
int offsetSkins; // offset to skin names (64 bytes each)
int offsetST; // offset of texture s-t values
int offsetTris; // offset of triangle mesh
int offsetFrames; // offset of frame data (points)
int offsetGLcmds; // type of OpenGL commands to use
int offsetEnd; // end of file
} modelHeader_t;
class CMD2Model : public CObject
{
private:
int numFrames; // number of model frames
int numVertices; // number of vertices
int numTriangles; // number of triangles
int numST; // number of skins
int frameSize; // size of each frame in bytes
mesh_t *triIndex; // triangle list
texCoord_t *st; // texture coordinate list
vector_t *vertexList; // vertex list
CTexture *modelTex; // texture data
void SetupSkin(CTexture *thisTexture);
protected:
modelState_t modelState; // current model animation state
int currentFrame; // current frame # in animation
int nextFrame; // next frame # in animation
public:
float interpol; // percent through current frame
CMD2Model(); // constructor
~CMD2Model(); // destructor
// load model and skin/texture at the same time
int Load(char *modelFile, char *skinFile);
// load model only
int LoadModel(char *modelFile);
// load skin only
int LoadSkin(char *skinFile);
// set model's texture/skin
int SetTexture(CTexture *texture);
// render model with interpolation to get animation
int AnimateModel(int startFrame, int endFrame, float percent);
// render a single frame
int RenderFrame(int keyFrame);
// free memory of model
void Unload();
// set animation state of model
void SetState(modelState_t state);
// retrieve animation state of model
modelState_t GetState();
};
#endif