Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
model.hpp
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "inexor/physics/bih.hpp"
5 #include "inexor/shared/ents.hpp"
6 #include "inexor/shared/geom.hpp"
9 
10 
12 enum { MDL_CULL_VFC = 1<<0, MDL_CULL_DIST = 1<<1, MDL_CULL_OCCLUDED = 1<<2, MDL_CULL_QUERY = 1<<3, MDL_SHADOW = 1<<4, MDL_DYNSHADOW = 1<<5, MDL_LIGHT = 1<<6, MDL_DYNLIGHT = 1<<7, MDL_FULLBRIGHT = 1<<8, MDL_NORENDER = 1<<9, MDL_LIGHT_FAST = 1<<10, MDL_HUD = 1<<11, MDL_GHOST = 1<<12 };
13 
14 struct model;
16 {
17  const char *tag, *name;
18  int anim, basetime;
19  vec *pos;
20  model *m;
21 
22  modelattach() : tag(nullptr), name(nullptr), anim(-1), basetime(0), pos(nullptr), m(nullptr) {}
23  modelattach(const char *tag, const char *name, int anim = -1, int basetime = 0) : tag(tag), name(name), anim(anim), basetime(basetime), pos(nullptr), m(nullptr) {}
24  modelattach(const char *tag, vec *pos) : tag(tag), name(nullptr), anim(-1), basetime(0), pos(pos), m(nullptr) {}
25 };
26 
27 extern void startmodelbatches();
28 extern void endmodelbatches();
29 extern void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, float yaw = 0, float pitch = 0, int cull = MDL_CULL_VFC | MDL_CULL_DIST | MDL_CULL_OCCLUDED | MDL_LIGHT, dynent *d = nullptr, modelattach *a = nullptr, int basetime = 0, int basetime2 = 0, float trans = 1);
30 extern void abovemodel(vec &o, const char *mdl);
31 extern void rendershadow(dynent *d);
32 extern void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int hold, int attack, int attackdelay, int lastaction, int lastpain, float fade = 1, bool ragdoll = false);
33 extern void interpolateorientation(dynent *d, float &interpyaw, float &interppitch);
34 extern void setbbfrommodel(dynent *d, const char *mdl);
35 extern const char *mapmodelname(int i);
36 extern model *loadmodel(const char *name, int i = -1, bool msg = false);
37 extern void preloadmodel(const char *name);
38 extern void flushpreloadedmodels(bool msg = true);
39 
40 struct model
41 {
42  char *name;
45  float scale;
47  BIH *bih;
50  int batch;
51 
52  model(const char *name) : name(name ? newstring(name) : nullptr), spinyaw(0), spinpitch(0), offsetyaw(0), offsetpitch(0), collide(true), ellipsecollide(false), shadow(true), alphadepth(true), depthoffset(false), scale(1.0f), translate(0, 0, 0), bih(nullptr), bbcenter(0, 0, 0), bbradius(-1, -1, -1), bbextend(0, 0, 0), collidecenter(0, 0, 0), collideradius(-1, -1, -1), rejectradius(-1), eyeheight(0.9f), collidexyradius(0), collideheight(0), batch(-1) {}
53  virtual ~model()
54  {
55  delete[] name;
56  name = nullptr;
57  delete bih;
58  bih = nullptr;
59  }
60  virtual void calcbb(vec &center, vec &radius) = 0;
61  virtual void render(int anim, int basetime, int basetime2, const vec &o, float yaw, float pitch, dynent *d, modelattach *a = nullptr, const vec &color = vec(0, 0, 0), const vec &dir = vec(0, 0, 0), float transparent = 1) = 0;
62  virtual bool load() = 0;
63  virtual int type() const = 0;
64  virtual BIH *setBIH() { return nullptr; }
65  virtual bool envmapped() { return false; }
66  virtual bool skeletal() const { return false; }
67 
68  virtual void setshader(Shader *shader) {}
69  virtual void setenvmap(float envmapmin, float envmapmax, Texture *envmap) {}
70  virtual void setspec(float spec) {}
71  virtual void setambient(float ambient) {}
72  virtual void setglow(float glow, float glowdelta, float glowpulse) {}
73  virtual void setglare(float specglare, float glowglare) {}
74  virtual void setalphatest(float alpha) {}
75  virtual void setalphablend(bool blend) {}
76  virtual void setfullbright(float fullbright) {}
77  virtual void setcullface(bool cullface) {}
78 
79  virtual void preloadBIH() { if(!bih) setBIH(); }
80  virtual void preloadshaders(bool force = false) {}
81  virtual void preloadmeshes() {}
82  virtual void cleanup() {}
83 
84  virtual void startrender() {}
85  virtual void endrender() {}
86 
87  void boundbox(vec &center, vec &radius)
88  {
89  if(bbradius.x < 0)
90  {
93  }
94  center = bbcenter;
95  radius = bbradius;
96  }
97 
98  float collisionbox(vec &center, vec &radius)
99  {
100  if(collideradius.x < 0)
101  {
103  if(collidexyradius)
104  {
105  collidecenter.x = collidecenter.y = 0;
107  }
108  if(collideheight)
109  {
111  }
113  }
114  center = collidecenter;
115  radius = collideradius;
116  return rejectradius;
117  }
118 
119  float boundsphere(vec &center)
120  {
121  vec radius;
122  boundbox(center, radius);
123  return radius.magnitude();
124  }
125 
126  float above()
127  {
128  vec center, radius;
129  boundbox(center, radius);
130  return center.z+radius.z;
131  }
132 };
133 
Definition: model.hpp:11
vec translate
Definition: model.hpp:46
Definition: ents.hpp:82
virtual bool skeletal() const
Definition: model.hpp:66
virtual void render(int anim, int basetime, int basetime2, const vec &o, float yaw, float pitch, dynent *d, modelattach *a=nullptr, const vec &color=vec(0, 0, 0), const vec &dir=vec(0, 0, 0), float transparent=1)=0
Definition: model.hpp:12
void setbbfrommodel(dynent *d, const char *mdl)
Definition: rendermodel.cpp:1176
Definition: model.hpp:12
char * name
Definition: model.hpp:42
virtual void preloadBIH()
Definition: model.hpp:79
virtual void setalphablend(bool blend)
Definition: model.hpp:75
virtual void preloadmeshes()
Definition: model.hpp:81
int basetime
Definition: model.hpp:18
Header for the internal GLSL shader organisation.
Definition: model.hpp:12
Definition: model.hpp:11
Definition: bih.hpp:16
model * m
Definition: model.hpp:20
void abovemodel(vec &o, const char *mdl)
Definition: rendermodel.cpp:1034
float collisionbox(vec &center, vec &radius)
Definition: model.hpp:98
Definition: model.hpp:40
virtual bool load()=0
Definition: model.hpp:12
virtual ~model()
Definition: model.hpp:53
bool ellipsecollide
Definition: model.hpp:44
virtual void setfullbright(float fullbright)
Definition: model.hpp:76
Definition: cubemap.cpp:202
virtual void setcullface(bool cullface)
Definition: model.hpp:77
Definition: model.hpp:12
Definition: model.hpp:12
virtual bool envmapped()
Definition: model.hpp:65
float offsetpitch
Definition: model.hpp:43
float scale
Definition: model.hpp:45
model(const char *name)
Definition: model.hpp:52
Definition: model.hpp:12
bool depthoffset
Definition: model.hpp:44
void flushpreloadedmodels(bool msg=true)
Definition: rendermodel.cpp:423
virtual void setambient(float ambient)
Definition: model.hpp:71
vec collidecenter
Definition: model.hpp:48
ICOMMAND * f(float *a, float *b), floatret(*a **b)
bool shadow
Definition: model.hpp:44
Definition: model.hpp:12
vec collideradius
Definition: model.hpp:48
float magnitude() const
vector's magnitude in all 3 (XYZ) dimensions
Definition: geom.hpp:195
void interpolateorientation(dynent *d, float &interpyaw, float &interppitch)
float rejectradius
Definition: model.hpp:49
Definition: model.hpp:12
float collidexyradius
Definition: model.hpp:49
modelattach()
Definition: model.hpp:22
modelattach(const char *tag, const char *name, int anim=-1, int basetime=0)
Definition: model.hpp:23
virtual void startrender()
Definition: model.hpp:84
Definition: model.hpp:12
Definition: model.hpp:11
virtual void setalphatest(float alpha)
Definition: model.hpp:74
vector with 3 floats and some useful methods.
Definition: geom.hpp:110
model * loadmodel(const char *name, int i=-1, bool msg=false)
Definition: rendermodel.cpp:468
const char * mapmodelname(int i)
Definition: rendermodel.cpp:404
void shader(int *type, char *name, char *vs, char *ps)
Definition: shader.cpp:1060
float offsetyaw
Definition: model.hpp:43
void endmodelbatches()
Definition: rendermodel.cpp:663
void preloadmodel(const char *name)
Definition: rendermodel.cpp:417
internal texture loading and organizing routines + main texture structures.
bool collide
Definition: model.hpp:44
void rendershadow(dynent *d)
const char * tag
Definition: model.hpp:17
int d
Definition: octaedit.cpp:1749
Definition: ents.hpp:258
virtual void setspec(float spec)
Definition: model.hpp:70
Definition: shader.hpp:142
#define dir(name, v, d, s, os)
Definition: physics.cpp:2014
vec bbcenter
Definition: model.hpp:48
vec bbradius
Definition: model.hpp:48
Definition: model.hpp:11
float boundsphere(vec &center)
Definition: model.hpp:119
Definition: model.hpp:11
virtual int type() const =0
Definition: model.hpp:11
float above()
Definition: model.hpp:126
Definition: model.hpp:12
virtual void preloadshaders(bool force=false)
Definition: model.hpp:80
Definition: model.hpp:12
vec & add(const vec &o)
scalar sum
Definition: geom.hpp:174
void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int hold, int attack, int attackdelay, int lastaction, int lastpain, float fade=1, bool ragdoll=false)
Definition: rendermodel.cpp:1116
virtual void setenvmap(float envmapmin, float envmapmax, Texture *envmap)
Definition: model.hpp:69
float eyeheight
Definition: model.hpp:49
int anim
Definition: model.hpp:18
void mdlname()
Definition: rendermodel.cpp:293
virtual void setglare(float specglare, float glowglare)
Definition: model.hpp:73
virtual void cleanup()
Definition: model.hpp:82
virtual void setshader(Shader *shader)
Definition: model.hpp:68
float collideheight
Definition: model.hpp:49
virtual void setglow(float glow, float glowdelta, float glowpulse)
Definition: model.hpp:72
virtual void calcbb(vec &center, vec &radius)=0
static map entities ("entity") and dynamic entities (players/monsters, "dynent") the gamecode extends...
mathmatics for vectors, matrices, quaterions and more
virtual void endrender()
Definition: model.hpp:85
modelattach(const char *tag, vec *pos)
Definition: model.hpp:24
Definition: model.hpp:15
float spinyaw
Definition: model.hpp:43
virtual BIH * setBIH()
Definition: model.hpp:64
Definition: model.hpp:12
static void color(const bvec &v, uchar alpha=255)
Definition: glemu.hpp:71
void startmodelbatches()
Definition: rendermodel.cpp:606
const char * name
Definition: model.hpp:17
char * newstring(size_t l)
Definition: cube_tools.hpp:71
void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, float yaw=0, float pitch=0, int cull=MDL_CULL_VFC|MDL_CULL_DIST|MDL_CULL_OCCLUDED|MDL_LIGHT, dynent *d=nullptr, modelattach *a=nullptr, int basetime=0, int basetime2=0, float trans=1)
Definition: rendermodel.cpp:863
vec bbextend
Definition: model.hpp:48
bool alphadepth
Definition: model.hpp:44
int batch
Definition: model.hpp:50
void boundbox(vec &center, vec &radius)
Definition: model.hpp:87
BIH * bih
Definition: model.hpp:47
vec * pos
Definition: model.hpp:19
A Texture entry, holding info about a texture on the GPU.
Definition: texture.hpp:27
Definition: model.hpp:11
float spinpitch
Definition: model.hpp:43