]> git.lizzy.rs Git - dragonblocks3d.git/blob - src/dragonblocks/mesh.hpp
b603bc9e9f5596c8059b33a8940939099cbe5388
[dragonblocks3d.git] / src / dragonblocks / mesh.hpp
1 #pragma once
2
3 #include <vector>
4 #include "gl.hpp"
5 #include "texture.hpp"
6
7 namespace dragonblocks
8 {
9         class Scene;
10         class ShaderProgram;
11         
12         class Mesh
13         {
14                 public:
15                 class Animation
16                 {
17                         public:
18                         static double grow_time;
19                         static double flyin_time;
20                         static double flyin_offset;
21                         static double rotate_speed;
22                         
23                         enum Type
24                         {
25                                 NONE,
26                                 FLYIN,
27                                 GROW,
28                                 ROTATE
29                         };
30                         
31                         glm::mat4 getModelMatrix(double, glm::vec3, glm::vec3, glm::vec3, float);
32                         
33                         Animation() = default;
34                         Animation(Type, void (*)(void *) = nullptr, void * = nullptr);
35                         Animation(const Animation &) = default;
36                         
37                         private:
38                         Type type = Type::NONE;
39                         double time_left;
40                         void (*on_finish)(void *);
41                         void *extra_data;
42                         bool expires;
43                 };
44                 
45                 int vertices_per_texture;
46                 glm::vec3 pos, size, rotation_axis;
47                 float rotation_angle = 0;
48                 std::vector<Texture> textures;  
49                 Animation animation;            
50                 
51                 void render(double dtime, ShaderProgram *);
52                 bool isRendering();
53                 void die();
54                 
55                 Mesh(Scene *, const GLvoid *, GLsizei);
56                 ~Mesh();
57
58                 private:
59                 GLuint VAO = 0, VBO = 0;
60                 Scene *scene;
61                 GLvoid *vertices = NULL;
62                 GLsizeiptr vertices_size;
63                 bool configured = false;
64                 bool rendering = false;
65                 bool prepare_death = false;
66                 bool do_delete = false;
67                 
68                 void configure();
69         };
70 }