]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/object.h
a5152d28c79f5de238aa28f7ba3bd06cb4da3df6
[dragonblocks_alpha.git] / src / client / object.h
1 #ifndef _OBJECT_H_
2 #define _OBJECT_H_
3
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include <GL/glew.h>
7 #include <GL/gl.h>
8 #include <linmath.h/linmath.h>
9 #include <dragonstd/array.h>
10 #include "client/mesh.h"
11 #include "client/texture.h"
12 #include "client/vertex.h"
13 #include "types.h"
14
15 typedef struct {
16         GLfloat x, y, z;
17 } __attribute__((packed)) Vertex3DPosition;
18
19 typedef struct {
20         GLfloat x, y, z;
21 } __attribute__((packed)) Vertex3DNormal;
22
23 typedef GLfloat Vertex3DTextureIndex;
24
25 typedef struct {
26         GLfloat s, t;
27 } __attribute__((packed)) Vertex3DTextureCoordinates;
28
29 typedef struct {
30         GLfloat r, g, b;
31 } __attribute__((packed)) Vertex3DColor;
32
33 typedef struct
34 {
35         Vertex3DPosition position;
36         Vertex3DNormal normal;
37         Vertex3DTextureIndex textureIndex;
38         Vertex3DTextureCoordinates textureCoordinates;
39         Vertex3DColor color;
40 } __attribute__((packed)) Vertex3D;
41
42 typedef struct
43 {
44         GLuint texture;
45         Array vertices;
46 } ObjectFace;
47
48 typedef struct Object
49 {
50         v3f32 pos, rot, scale;
51         f32 angle;
52         bool remove;
53         Mesh **meshes;
54         size_t meshes_count;
55         mat4x4 transform;
56         bool visible;
57         bool wireframe;
58         bool frustum_culling;
59         bool transparent;
60         aabb3f32 box;
61         ObjectFace *current_face;
62         Array faces;
63         void (*on_render)(struct Object *obj, f64 dtime);
64         void *extra;
65 } Object;
66
67 Object *object_create();
68 void object_delete(Object *obj);
69 void object_set_texture(Object *obj, Texture *texture);
70 void object_add_vertex(Object *obj, Vertex3D *vertex);
71 bool object_add_to_scene(Object *obj);
72 void object_transform(Object *obj);
73 bool object_before_render(Object *obj, f64 dtime);
74 void object_render(Object *obj);
75
76 #endif