LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
|
=== Scene graph implementation ===
LG_SceneNode* lg_scenenode_new | ( | int | id, |
const char * | name, | ||
lg_scenenode_type | type | ||
) |
Create a new LG_SceneNode instance
local_matrix and world_matrix are initialized as id matrix
id | Node's id |
name | Node's name |
type | One of ROOT, MESH, LINES3D, GRID, LANDSCAPE, SKYBOX, LIGHT, SHADER_ONLY, UNDEFINED |
scene | A pointer to a LG_Scene |
void lg_scenenode_add_child | ( | LG_SceneNode * | node, |
LG_SceneNode * | child | ||
) |
Add child node
node | A pointer to a LG_SceneNode |
child | A pointer to a LG_SceneNode |
void lg_scenenode_remove_child | ( | LG_SceneNode * | node, |
LG_SceneNode * | child | ||
) |
Find and remove child by id (but doesn't free)
node | A pointer to a LG_SceneNode |
child | A pointer to a LG_SceneNode |
void lg_scenenode_free | ( | LG_SceneNode * | node | ) |
Free a node and all allocated resources
You can also use lg_scenenode_free2() experimental macro, defined in lg_scenegraph.h
node | A pointer to a LG_SceneNode |
LG_SceneNode* lg_scenenode_get_root | ( | LG_SceneNode * | node | ) |
Get the root node
node | A pointer to a LG_SceneNode |
int lg_scenenode_remove_and_free_leaf | ( | LG_SceneNode * | node | ) |
Remove and free a leaf node
node | A pointer to a LG_SceneNode |
void lg_scenenode_remove_and_free_all | ( | LG_SceneNode * | node | ) |
Remove and free all nodes but root
node | A pointer to a LG_SceneNode |
void lg_traverse_scene_graph | ( | LG_SceneNode * | node, |
int(*)(LG_SceneNode *) | func | ||
) |
Go from top to bottom, starting at node (may be different from the top node) - unsuitable (don't) to remove all nodes
Call (*func)(node) for each node
node | A pointer to a LG_SceneNode |
func | Func pointer |
void lg_traverse_scene_graph_2 | ( | LG_SceneNode * | node, |
int(*)(LG_SceneNode *, LG_Scene *) | func, | ||
LG_Scene * | scene | ||
) |
Same as above but with different func signature and extra scene arg
LG_SceneNode* lg_scenenode_find_by_id | ( | LG_SceneNode * | node, |
int | id | ||
) |
Find (first ?) occurence of node by id (traversing the graph top to bottom from provided node)
node | Node |
id | Node's id |
LG_SceneNode* lg_scenenode_find_by_name | ( | LG_SceneNode * | node, |
const char * | name | ||
) |
Find (first ?) occurence of node by name (traversing the graph top to bottom from provided node)
node | Node |
name | Node's name |
void lg_scenenode_reset_local_matrix | ( | LG_SceneNode * | node | ) |
=== Scene graph matrix ops ===
Reset node's local_matrix to id matrix
node | A pointer to a LG_SceneNode |
void lg_scenenode_set_local_matrix | ( | LG_SceneNode * | node, |
vec3_t | scaling, | ||
vec3_t | transl, | ||
LG_Quat | rot | ||
) |
Set node's local matrix
Order is always scaling / transl. / rot.
node | A pointer to a LG_SceneNode |
scaling | Scaling vec3_t vector |
transl | Translation vec3_t vector |
rot | Rotation LG_Quat quaternion |
void lg_scenenode_update_local_matrix | ( | LG_SceneNode * | node, |
vec3_t | scaling, | ||
vec3_t | transl, | ||
LG_Quat | rot | ||
) |
Update node's local matrix
Order is always scaling / transl. / rot.
node | A pointer to a LG_SceneNode |
scaling | Scaling vec3_t vector |
transl | Translation vec3_t vector |
rot | Rotation LG_Quat quaternion |
void lg_scenenode_update_world_matrix_tree | ( | LG_SceneNode * | node, |
mat4_t * | parent_world_matrix | ||
) |
Update (compute from local_matrix) world matrix of node (if transf matrix != NULL) AND children, recursively
node | A pointer to a LG_SceneNode |
parent_world_matrix | A pointer to a mat4_t transformation matrix |
void lg_scenenode_set_world_matrix | ( | LG_SceneNode * | node, |
vec3_t | scaling, | ||
vec3_t | transl, | ||
LG_Quat | rot | ||
) |
Set world matrix of node (only this one) from local_matrix and 3 transfomation vectors
Order is always scaling / transl. / rot.
For special case uses, like attaching a node to a cam
node | A pointer to a LG_SceneNode |
scaling | Scaling vec3_t vector |
transl | Translation vec3_t vector |
rot | Rotation LG_Quat quaternion |
void lg_scenenode_attach_to_camera | ( | LG_SceneNode * | node, |
const LG_Camera * | cam, | ||
vec3_t | transl | ||
) |
Attach node to camera
Modify node's world_matrix to locate it relatively to the camera
Easier to use than lg_scenenode_set_world_matrix()
lg_scenenode_set_world_matrix(node, vec3(1.0, 1.0, 1.0), cam->position, cam->orientation); // vs lg_scenenode_attach_to_camera(node, cam, {0.0, 1.0, -1.0});
node | A pointer to a LG_SceneNode |
cam | A pointer to a LG_Camera |
transl | Translation relatively to the cam position |
int lg_scenenode_clone_worldm_l3dvb | ( | LG_SceneNode * | dest_node, |
LG_SceneNode * | src_node | ||
) |
'Clone' node's draw_stuff
This line:
makes this func convenient to draw a mesh bounding cuboid
dest_node | Pointer to dest node |
src_node | Pointer to src node |
void lg_traverse_printout_scene_graph | ( | LG_SceneNode * | node, |
zboolean | extra_info | ||
) |
Go from top to bottom
Print out tree structure (quite nicely) -> node->name (node->id)
node | A pointer to a LG_SceneNode |
extra_info | If TRUE, print out extra info (node->id so far) |
void lg_scenenode_info | ( | LG_SceneNode * | node | ) |
Print out LG_SceneNode info
node | A pointer to a LG_SceneNode |
int lg_scenenode_info2 | ( | LG_SceneNode * | node | ) |
Print out LG_SceneNode info
Same as above func but returns (int)0, so suitable to use with lg_traverse_scene_graph()
node | A pointer to a LG_SceneNode |
const char* lg_scenenode_type_string | ( | int | type | ) |
Return string for scenenode type (enum)
type | Scenenode type as an int (lg_scenenode_type enum) |