diff options
-rw-r--r-- | src/transform_hierarchy.c | 41 | ||||
-rw-r--r-- | src/transform_hierarchy.h | 9 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/transform_hierarchy.c b/src/transform_hierarchy.c index 0a4e592..25ace6c 100644 --- a/src/transform_hierarchy.c +++ b/src/transform_hierarchy.c @@ -1,15 +1,15 @@ /** * @file transform_hierarchy.h -*/ + */ #pragma once #include "transform_hierarchy.h" #include <stdlib.h> #include <string.h> #include "log.h" -#include "maths_types.h" #include "maths.h" +#include "maths_types.h" #include "render_types.h" struct transform_hierarchy { @@ -19,22 +19,20 @@ struct transform_hierarchy { transform_hierarchy* transform_hierarchy_create() { transform_hierarchy* tfh = malloc(sizeof(transform_hierarchy)); - tfh->root =(transform_node){ - .model = ABSENT_MODEL_HANDLE, - .tf = TRANSFORM_DEFAULT, - .local_matrix_tf = mat4_ident(), - .world_matrix_tf = mat4_ident(), - .parent = NULL, - .children = {0}, - .n_children = 0, - .tfh = tfh - }; + tfh->root = (transform_node){ .model = { ABSENT_MODEL_HANDLE }, + .tf = TRANSFORM_DEFAULT, + .local_matrix_tf = mat4_ident(), + .world_matrix_tf = mat4_ident(), + .parent = NULL, + .children = { 0 }, + .n_children = 0, + .tfh = tfh }; return tfh; } bool free_node(transform_node* node, void* _ctx_data) { - if (!node) return true; // leaf node + if (!node) return true; // leaf node if (node == &node->tfh->root) { WARN("You can't free the root node!"); return false; @@ -50,9 +48,7 @@ void transform_hierarchy_free(transform_hierarchy* tfh) { free(tfh); } -transform_node* transform_hierarchy_root_node(transform_hierarchy* tfh) { - return &tfh->root; -} +transform_node* transform_hierarchy_root_node(transform_hierarchy* tfh) { return &tfh->root; } void transform_hierarchy_add_node(transform_node* parent, model_handle model, transform tf) { if (!parent) { @@ -89,17 +85,20 @@ void transform_hierarchy_delete_node(transform_node* node) { if (node->parent) { for (u32 i = 0; i < node->parent->n_children; i++) { - transform_node* child = node->parent->children[i]; - if (child == node) { - node->parent->children[i] = NULL; // HACK: this will leave behind empty slots in the children array of the parent. oh well. - } + transform_node* child = node->parent->children[i]; + if (child == node) { + node->parent->children[i] = NULL; // HACK: this will leave behind empty slots in the + // children array of the parent. oh well. + } } } free(node); } -void transform_hierarchy_dfs(transform_node* start_node, bool (*visit_node)(transform_node* node, void* ctx_data), bool is_pre_order, void* ctx_data) { +void transform_hierarchy_dfs(transform_node* start_node, + bool (*visit_node)(transform_node* node, void* ctx_data), + bool is_pre_order, void* ctx_data) { if (!start_node) return; bool continue_traversal = true; diff --git a/src/transform_hierarchy.h b/src/transform_hierarchy.h index 91b0559..703baa8 100644 --- a/src/transform_hierarchy.h +++ b/src/transform_hierarchy.h @@ -36,11 +36,12 @@ void transform_hierarchy_free(transform_hierarchy* tfh); // --- Main usecase +/** @brief Updates matrices of any invalidated nodes based on the `is_dirty` flag inside `transform` */ void transform_hierarchy_propagate_transforms(transform_hierarchy* tfh); // --- Queries -/** Get a pointer to the root node */ +/** @brief Get a pointer to the root node */ transform_node* transform_hierarchy_root_node(transform_hierarchy* tfh); // --- Mutations @@ -57,8 +58,8 @@ void transform_hierarchy_delete_node(transform_node* node); * @param ctx_data An optional pointer to data that is be passed on each call to `visit_node`. Can be used to carry additional information or context. * * @note The main use-cases are: - 1. traversing the whole tree to update cached 4x4 affine transform matrices - 2. freeing child nodes after deleting a node in the tree - 3. debug pretty printing the whole tree + 1. traversing the whole tree to update cached 4x4 affine transform matrices (pre-order) + 2. freeing child nodes after deleting a node in the tree (post-order) + 3. debug pretty printing the whole tree (post-order) */ void transform_hierarchy_dfs(transform_node* start_node, bool (*visit_node)(transform_node* node, void* ctx_data), bool is_pre_order, void* ctx_data);
\ No newline at end of file |