LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_scene_graph.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2024
3  * All rights reserved
4  */
5 
6 #ifndef LG_SCENE_GRAPH_H
7 #define LG_SCENE_GRAPH_H
8 
9 #define SCENENODE_NAME_MAX_LEN (64 - 1)
10 #define SCENENODE_CHILD_MAX_NUM 256
11 
12 #define SCENE_GRAPH_MAX_DEPTH 32
13 #define SCENEGRAPH_PRINTOUT_MAX_DEPTH 8
14 
15 typedef enum {
16  ROOT,
17  MESH,
18  LINES3D,
19  GRID, /* Means lines3d_vb is dynamic */
20  LANDSCAPE, /* = Landscape root */
21  SKYBOX,
22  LIGHT,
23  SHADER_ONLY,
24  UNDEFINED
25 } lg_scenenode_type;
26 
27 typedef struct LG_SceneNode LG_SceneNode;
28 
29 struct LG_SceneNode {
30  int id; /* User-defined - not unique */
31  char name[SCENENODE_NAME_MAX_LEN + 1]; /* User-defined - not unique */
32  lg_scenenode_type type;
33  LG_SceneNode *parent;
34  LG_SceneNode *child[SCENENODE_CHILD_MAX_NUM];
35  unsigned int n_child;
36  LG_Mesh *mesh;
37  Lines3D_VB lines3d_vb; /* Line set vertex buffer and num of vertices */
38  mat4_t local_matrix0; /* 'Private' member - how to 'hide' this stuff */
39  mat4_t world_matrix0; /* 'Private' member - how to 'hide' this stuff */
40  mat4_t *local_matrix; /* Adjust (S-T-R) the mesh/lines3d_vb in its local space */
41  mat4_t *world_matrix; /* Put (S-T-R) the mesh/lines3d_vb in world space */
42  LG_ShaderProg shader_prog;
43  LG_ShaderULocs shader_u_loc; /* Shader uniforms locations */
44  LG_VAO vao; /* Vertex Array Object */
45  LG_Texture *tex_1; /* For textures other than thoses from mesh mtl file */
46 };
47 
48 typedef struct {
49  LG_Camera *cam1;
50  LG_Light light1;
51  Vertex_rgba *h_grid;
52  int grid_n_vertices;
53  Vertex_rgba *xyz_arrows;
54  Rec2Df landscape_rec;
55  LG_SceneNode *root_node;
56 } LG_Scene;
57 
58 LG_SceneNode *lg_scenenode_new(int, const char *, lg_scenenode_type);
59 
61 
63 
65 
66 /* Any good ? */
67 #define lg_scenenode_free2(s_node) {lg_scenenode_free(s_node); s_node = NULL;}
68 
70 
71 int lg_remove_and_free_leaf_node(LG_SceneNode *);
72 
74 
76 
78 
80 
82 
84 
86 
88 
90 
92 
94 
96 
98 
100 
102 
103 const char *lg_scenenode_type_string(int);
104 
105 #endif /* LG_SCENE_GRAPH_H */
LG_Mesh
Definition: lg_mesh.h:68
Rec2Df
Definition: lg_gr_func.h:54
LG_Quat
Definition: lg_quaternions.h:29
LG_ShaderProg
Definition: lg_shader_progs.h:11
lg_scenenode_new
LG_SceneNode * lg_scenenode_new(int id, const char *name, lg_scenenode_type type)
Definition: lg_scene_graph.c:31
LG_ShaderULocs
Definition: lg_shader_progs.h:16
lg_scenenode_remove_and_free_all
void lg_scenenode_remove_and_free_all(LG_SceneNode *node)
Definition: lg_scene_graph.c:206
LG_SceneNode
Definition: lg_scene_graph.h:29
LG_Scene
Definition: lg_scene_graph.h:48
lg_scenenode_find_by_name
LG_SceneNode * lg_scenenode_find_by_name(LG_SceneNode *node, const char *name)
Definition: lg_scene_graph.c:339
lg_scenenode_clone_worldm_l3dvb
int lg_scenenode_clone_worldm_l3dvb(LG_SceneNode *dest_node, LG_SceneNode *src_node)
Definition: lg_scene_graph.c:515
LG_VAO
Definition: lg_vbo.h:52
LG_Light
Definition: lg_light.h:26
lg_scenenode_info2
int lg_scenenode_info2(LG_SceneNode *node)
Definition: lg_scene_graph.c:668
Lines3D_VB
Definition: lg_3d_primitives.h:53
lg_scenenode_remove_child
void lg_scenenode_remove_child(LG_SceneNode *node, LG_SceneNode *child)
Definition: lg_scene_graph.c:112
lg_scenenode_add_child
void lg_scenenode_add_child(LG_SceneNode *node, LG_SceneNode *child)
Definition: lg_scene_graph.c:91
lg_scenenode_reset_local_matrix
void lg_scenenode_reset_local_matrix(LG_SceneNode *node)
Definition: lg_scene_graph.c:356
lg_traverse_scene_graph
void lg_traverse_scene_graph(LG_SceneNode *node, int(*func)(LG_SceneNode *))
Definition: lg_scene_graph.c:249
vec3_t
Definition: math_3d.h:111
lg_scenenode_update_world_matrix_tree
void lg_scenenode_update_world_matrix_tree(LG_SceneNode *node, mat4_t *parent_world_matrix)
Definition: lg_scene_graph.c:423
LG_Camera
Definition: lg_camera.h:19
lg_traverse_printout_scene_graph
void lg_traverse_printout_scene_graph(LG_SceneNode *node, zboolean extra_info)
Definition: lg_scene_graph.c:590
lg_scenenode_set_world_matrix
void lg_scenenode_set_world_matrix(LG_SceneNode *node, vec3_t scaling, vec3_t transl, LG_Quat rot)
Definition: lg_scene_graph.c:454
lg_scenenode_type_string
const char * lg_scenenode_type_string(int type)
Definition: lg_scene_graph.c:680
lg_scenenode_info
void lg_scenenode_info(LG_SceneNode *node)
Definition: lg_scene_graph.c:601
lg_scenenode_get_root
LG_SceneNode * lg_scenenode_get_root(LG_SceneNode *node)
Definition: lg_scene_graph.c:159
lg_scenenode_free
void lg_scenenode_free(LG_SceneNode *node)
Definition: lg_scene_graph.c:144
lg_scenenode_update_local_matrix
void lg_scenenode_update_local_matrix(LG_SceneNode *node, vec3_t scaling, vec3_t transl, LG_Quat rot)
Definition: lg_scene_graph.c:403
LG_Texture
Definition: lg_textures.h:42
lg_traverse_scene_graph_2
void lg_traverse_scene_graph_2(LG_SceneNode *node, int(*func)(LG_SceneNode *, LG_Scene *), LG_Scene *scene)
Definition: lg_scene_graph.c:283
lg_scenenode_attach_to_camera
void lg_scenenode_attach_to_camera(LG_SceneNode *node, const LG_Camera *cam, vec3_t transl)
Definition: lg_scene_graph.c:483
Vertex_rgba
Definition: lg_vertex.h:60
lg_scenenode_set_local_matrix
void lg_scenenode_set_local_matrix(LG_SceneNode *node, vec3_t scaling, vec3_t transl, LG_Quat rot)
Definition: lg_scene_graph.c:379
lg_scenenode_find_by_id
LG_SceneNode * lg_scenenode_find_by_id(LG_SceneNode *node, int id)
Definition: lg_scene_graph.c:322
mat4_t
Definition: math_3d.h:167