summaryrefslogtreecommitdiff
path: root/src/engine/M_object.h
blob: ca87f0ae8460426320ed61d0aca9008e58fdf1cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once

#include <cglm/cglm.h>
#include <cglm/mat4.h>
#include <cglm/vec3.h>

#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/mesh.h>
#include <assimp/postprocess.h>

//#include "M_game.h"
#include "M_shader.h"

//Temporary type for storing M_Object rotation information,
//will get replaced in later revisions.
typedef struct {
	float angle;
	vec3 direction;
} M_Rotation;

//Stores information about a 3D model loaded in VRAM
typedef struct {
	int num_indices;

	unsigned int VAO, VBO, EBO;
} M_ViewModel;

//Type meant for handling 3D models in a scene,
//stores additional information like a model's position, size and rotation.
typedef struct {
	M_ViewModel *model;
	M_ShaderProgram *shader;

	vec3 pos, size;

	M_Rotation rotation;

	mat4 transform;
} M_Object;

//Creates a M_ViewModel out of vertices and indices manually
void M_createViewModel(M_ViewModel *model, int num_vertices, float *vert, int num_indices, unsigned int *indices);

//Unloads M_ViewModel from memory when no longer needed
void M_killViewModel(M_ViewModel *model);

//Loads and creates a M_ViewModel from a 3D object file like .obj
M_ViewModel M_loadViewModel(const char* filename);

//Creates a M_Object
void M_createObject(M_Object *obj, M_ViewModel *model);


//Functions for moving, scaling and rotating M_Object
void M_moveObject(M_Object *obj, vec3 pos);
void M_scaleObject(M_Object *obj, vec3 scale);
void M_rotateObject(M_Object *obj, float angle, vec3 direction);

//Updates M_Object transform matrix manually
void M_updateObjectTransform(M_Object *obj);

//Binds M_ViewModel for drawing
void M_bindViewModel(M_ViewModel *model);