A 3D game engine from scratch.
1// (c) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
2
3#pragma once
4
5#include "types.hpp"
6#include "entities.hpp"
7
8class spatial {
9public:
10 struct Obb {
11 v3 center;
12 v3 x_axis;
13 v3 y_axis; // We can get the z axis with a cross product
14 v3 extents;
15 };
16
17 struct Face {
18 v3 vertices[4];
19 };
20
21 struct Ray {
22 v3 origin;
23 v3 direction;
24 };
25
26
27 struct Component {
28 entities::Handle entity_handle;
29 v3 position;
30 quat rotation;
31 v3 scale;
32 entities::Handle parent_entity_handle;
33 };
34
35
36 struct ModelMatrixCache {
37 m4 last_model_matrix;
38 Component *last_model_matrix_spatial_component;
39 };
40
41 struct State {
42 Array<Component> components;
43 };
44
45
46 static void print_spatial_component(Component *spatial_component);
47 static bool does_spatial_component_have_dimensions(Component *spatial_component);
48 static bool is_spatial_component_valid(Component *spatial_component);
49 static m4 make_model_matrix(
50 Component *spatial_component,
51 ModelMatrixCache *cache
52 );
53 static Array<spatial::Component> * get_components();
54 static spatial::Component * get_component(entities::Handle entity_handle);
55 static void init(spatial::State *spatial_state, memory::Pool *asset_memory_pool);
56
57private:
58 static spatial::State *state;
59};