LCOV - code coverage report
Current view: top level - engine/model - model.h (source / functions) Coverage Total Hit
Test: Libprimis Test Coverage Lines: 100.0 % 22 22
Test Date: 2025-02-18 06:21:28 Functions: 66.7 % 3 2

            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 int intersect(int, int, int, const vec &, float, float, float, dynent *, modelattach *, float, const vec &, const vec &) const = 0;
      84              :         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;
      85              :         virtual bool load() = 0;
      86              :         virtual int type() const = 0;
      87              :         virtual void setBIH() = 0;
      88              : 
      89              :         //true if the derived model type supports skeletal animation, false otherwise
      90              :         virtual bool skeletal() const = 0;
      91              :         //true if the model will move itself in any way (including translation/rotation)
      92              :         //dynamic models require different rendering handling
      93              :         virtual bool animated() const = 0;
      94              :         //true if any of the model's parts have a pitchscale set
      95              :         virtual bool pitched() const = 0;
      96              :         //true if any of the model's skin textures are alpha (see-through)
      97              :         virtual bool alphatested() const = 0;
      98              : 
      99              :         virtual void setshader(Shader *) = 0;
     100              :         virtual void setspec(float) = 0;
     101              :         virtual void setgloss(int) = 0;
     102              :         virtual void setglow(float, float, float) = 0;
     103              :         virtual void setalphatest(float) = 0;
     104              :         virtual void setfullbright(float) = 0;
     105              :         virtual void setcullface(int) = 0;
     106              :         virtual void setcolor(const vec &) = 0;
     107              :         virtual void settransformation(const std::optional<vec>,
     108              :                                        const std::optional<vec>,
     109              :                                        const std::optional<vec>,
     110              :                                        const std::optional<float>) = 0;
     111              :         //returns the location and size of the model
     112              :         virtual vec4<float> locationsize() const = 0;
     113              :         virtual void genshadowmesh(std::vector<triangle> &, const matrix4x3 &) const = 0;
     114              : 
     115              :         virtual void preloadBIH() = 0;
     116              :         virtual void preloadshaders() = 0;
     117              :         virtual void preloadmeshes() = 0;
     118              :         virtual void cleanup() = 0;
     119              :         virtual void startrender() const = 0;
     120              :         virtual void endrender() const = 0;
     121              :         virtual void boundbox(vec &center, vec &radius) = 0;
     122              :         virtual float collisionbox(vec &center, vec &radius) = 0;
     123              :         virtual const std::string &modelname() const = 0;
     124              : 
     125              :     protected:
     126              :         vec translate,
     127              :             spin;
     128              :         float scale;
     129              :         std::string name;
     130              :         vec bbcenter, bbradius, collidecenter, collideradius;
     131              :         float rejectradius;
     132              : 
     133              :         /**
     134              :          * @brief Constructs a new model object.
     135              :          *
     136              :          * The string passed will be consumed by the constructor.
     137              :          */
     138           20 :         model(std::string name) : orientation(0, 0, 0),
     139           20 :                                   shadow(true),
     140           20 :                                   alphashadow(true),
     141           20 :                                   depthoffset(false),
     142           20 :                                   bbextend(0, 0, 0),
     143           20 :                                   eyeheight(0.9f),
     144           20 :                                   collidexyradius(0),
     145           20 :                                   collideheight(0),
     146           40 :                                   collidemodel(""),
     147           20 :                                   collide(Collide_OrientedBoundingBox),
     148           20 :                                   batch(-1),
     149           20 :                                   translate(0, 0, 0),
     150           20 :                                   spin(0, 0, 0),
     151           20 :                                   scale(1.0f),
     152           20 :                                   name(std::move(name)),
     153           20 :                                   bbcenter(0, 0, 0),
     154           20 :                                   bbradius(-1, -1, -1),
     155           20 :                                   collidecenter(0, 0, 0),
     156           20 :                                   collideradius(-1, -1, -1),
     157           20 :                                   rejectradius(-1)
     158           20 :                                   {}
     159              : };
     160              : 
     161              : #endif
        

Generated by: LCOV version 2.0-1