Line data Source code
1 : #ifndef MODEL_H_
2 : #define MODEL_H_
3 :
4 : enum
5 : {
6 : MDL_MD5 = 0,
7 : MDL_OBJ,
8 : MDL_GLTF,
9 : MDL_NumMDLTypes
10 : };
11 :
12 : /* model: the base class for an ingame model, with only pure virtual methods,
13 : * all methods are defined in animmodel or one of its defined classes
14 : *
15 : * extended by animmodel (animated model) which is itself extended by skelmodel
16 : * and vertmodel
17 : *
18 : * a model format loader (e.g. md5 or obj) extends model or one of its children
19 : * and assigns the data from the file format into the object (by setting its
20 : * fields and overriding its methods)
21 : *
22 : * model class hierarchy (all are objects except bottom gvars)
23 : *
24 : * /-------\
25 : * | model |
26 : * \-------/
27 : * |
28 : * v
29 : * /-----------\
30 : * | animmodel |
31 : * \-----------/
32 : * | \__________
33 : * v \
34 : * /-----------\ v
35 : * | skelmodel | /-----------\
36 : * \-----------/ | vertmodel |
37 : * | \-----------/
38 : * | /-------------\ |
39 : * | | modelloader | |
40 : * | \-------------/ |
41 : * | | |
42 : * \__________/ \_____________/ <-- multiple inheritance via template class
43 : * | |
44 : * v v
45 : * /------------\ /------------\
46 : * | skelloader | | vertloader |
47 : * \------------/ \------------/
48 : * _______| | |
49 : * | v /---------------\ v
50 : * /----\ /-----\ | modelcommands | /-----\
51 : * |gltf| -->| md5 | \---------------/ | obj |<-
52 : * \----/ | \-----/ | | \-----/ |
53 : * ^ | | | v v | |
54 : * | | | | /--------------\ /--------------\ | |
55 : * | | | | | skelcommands | | vertcommands | | |
56 : * | | | | \--------------/ \--------------/ | |
57 : * | | | | | | | | |
58 : * | | | v v | v v |
59 : * | | /-------------------\ | /-------------------\
60 : * | | | skelcommands<md5> | | | vertcommands<obj> |
61 : * | | | md5::md5commands | | | obj::objcommands |
62 : * | | \---static field----/ | \---static field----/
63 : * | v /
64 : * /--------------------\ /
65 : * | skelcommands<gltf> |<-/
66 : * | gltf::gltfcommands |
67 : * \----static field----/
68 : */
69 : class model
70 : {
71 : public:
72 : //for spin, orientation: x = yaw, y = pitch, z = roll
73 : vec orientation;
74 : bool shadow, alphashadow, depthoffset;
75 : std::unique_ptr<BIH> bih;
76 : vec bbextend;
77 : float eyeheight, collidexyradius, collideheight;
78 : std::string collidemodel;
79 : int collide, batch;
80 :
81 20 : virtual ~model() = default;
82 : virtual void calcbb(vec &, vec &) const = 0;
83 : virtual void calctransform(matrix4x3 &) const = 0;
84 : virtual int intersect(int, int, int, const vec &, float, float, float, dynent *, modelattach *, float, const vec &, const vec &, float &) const = 0;
85 : virtual void render(int, int, int, const vec&, float, float, float , dynent *, modelattach * = nullptr, float = 1, const vec4<float>& = vec4<float>(1, 1, 1, 1)) const = 0;
86 : virtual bool load() = 0;
87 : virtual int type() const = 0;
88 : virtual bool setBIH() = 0;
89 : virtual bool skeletal() const = 0;
90 : virtual bool animated() const = 0;
91 : virtual bool pitched() const = 0;
92 : virtual bool alphatested() const = 0;
93 :
94 : virtual void setshader(Shader *) = 0;
95 : virtual void setspec(float) = 0;
96 : virtual void setgloss(int) = 0;
97 : virtual void setglow(float, float, float) = 0;
98 : virtual void setalphatest(float) = 0;
99 : virtual void setfullbright(float) = 0;
100 : virtual void setcullface(int) = 0;
101 : virtual void setcolor(const vec &) = 0;
102 : virtual void settransformation(const std::optional<vec>,
103 : const std::optional<vec>,
104 : const std::optional<vec>,
105 : const std::optional<float>) = 0;
106 : //returns the location and size of the model
107 : virtual vec4<float> locationsize() const = 0;
108 : virtual void genshadowmesh(std::vector<triangle> &, const matrix4x3 &) = 0;
109 :
110 : virtual void preloadBIH() = 0;
111 : virtual void preloadshaders() = 0;
112 : virtual void preloadmeshes() = 0;
113 : virtual void cleanup() = 0;
114 : virtual void startrender() const = 0;
115 : virtual void endrender() const = 0;
116 : virtual void boundbox(vec ¢er, vec &radius) = 0;
117 : virtual float collisionbox(vec ¢er, vec &radius) = 0;
118 : virtual float above() = 0;
119 : virtual const std::string &modelname() const = 0;
120 :
121 : protected:
122 : vec translate,
123 : spin;
124 : float scale;
125 : std::string name;
126 : vec bbcenter, bbradius, collidecenter, collideradius;
127 : float rejectradius;
128 :
129 20 : model(std::string name) : orientation(0, 0, 0),
130 20 : shadow(true),
131 20 : alphashadow(true),
132 20 : depthoffset(false),
133 20 : bbextend(0, 0, 0),
134 20 : eyeheight(0.9f),
135 20 : collidexyradius(0),
136 20 : collideheight(0),
137 20 : collidemodel(""),
138 20 : collide(Collide_OrientedBoundingBox),
139 20 : batch(-1),
140 20 : translate(0, 0, 0),
141 20 : spin(0, 0, 0),
142 20 : scale(1.0f),
143 20 : name(name),
144 20 : bbcenter(0, 0, 0),
145 20 : bbradius(-1, -1, -1),
146 20 : collidecenter(0, 0, 0),
147 20 : collideradius(-1, -1, -1),
148 20 : rejectradius(-1)
149 20 : {}
150 : };
151 :
152 : #endif
|