-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodelmanager.h
83 lines (72 loc) · 2.08 KB
/
modelmanager.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
#ifndef _MODELMANAGER_H_
#define _MODELMANAGER_H_
#include <vector>
#include <string>
#include <map>
#include <list>
using namespace std;
#include "globals.h"
#include "texturemanager.h"
struct JointState{
float theta;
VertexF n;
JointState* next;
};
struct Animation{
vector<JointState*> keyFrames;
vector<JointState*> frameDeltas; // these are the rotational velocities that are added to keyframe thetas (keyLength times) to move onto the next state
vector<int> keyLengths;
};
class AnimationInstance{
public:
AnimationInstance();
AnimationInstance(Animation* animation);
~AnimationInstance();
void AdvanceFrames(int frames);
private:
unsigned int key;
int frame;
JointState* currentDelta;
Animation* animation;
friend class ModelManager;
};
struct Triangle{
int v[3];
int vt[3];
int vn[3];
};
struct ModelPiece{
string name;
vector<Triangle> triangles;
bool textured;
bool teamColored; // are we coloring this piece the teams color?
TextureRef texture;
vector<ModelPiece*> children;
VertexF joint;
GLuint displayList;
};
struct Model{
vector<VertexF> vertices;
vector<PointF> tex_coords;
vector<VertexF> normals;
vector<ModelPiece*> pieces;
map<string,Animation*> animations;
};
typedef unsigned int ModelRef;
class ModelManager{
public:
ModelManager();
~ModelManager();
ModelRef LoadModel(string filename, TextureManager* textureManager);
void DrawModel(ModelRef ref, TextureManager* textureManager, float cr = 1, float cg = 1, float cb = 1, AnimationInstance *animationInstance = NULL, bool textured = true);
AnimationInstance* GetAnimationInstance(ModelRef modelRef, string animationName);
private:
vector<ModelPiece*> LoadObj(string filename, Model* model, TextureManager* textureManager);
void DrawPiece(Model* model, ModelPiece* piece, TextureManager* textureManager, float cr, float cg, float cb, JointState** initials, JointState** vels, bool textured);
Animation* MakeAnimation(vector<vector<VertexF> > frames, vector<int> frameLengths);
map<ModelRef,Model*> models;
map<string,ModelRef> filenames;
ModelRef next_unused_ref;
TextureRef lastTexture;
};
#endif