commit ab8c88bb0a91d5b8132ea894fa56ae95d998561f
parent 7bcecdb74afe39e2a73ebaaf7c6fdcec0215b219
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 18 Sep 2017 16:23:42 +0200
Update the sanim_node_visit_tree API
The submitted direction may be NULL. In this case the pivots are not
resolved.
Diffstat:
3 files changed, 29 insertions(+), 30 deletions(-)
diff --git a/src/sanim.h b/src/sanim.h
@@ -170,14 +170,14 @@ sanim_node_solve_pivot
(struct sanim_node* node,
const double in_dir[3]);
-/* Visit the (sub)tree starting at node
- * Solve pivots if any (an ancestor pivot would not be solved/updated)
- * Call visitor on every node of the tree with its updated transform
- * Visit stops if a call to visitor return is not RES_OK */
+/* Visit the (sub)tree starting at `node'. Solve pivots if any (an ancestor
+ * pivot would not be solved/updated) and if `in_dir' is not NULL. Call
+ * `visitor' on every node of the tree with its updated transform Visit stops
+ * if a call to visitor return is not RES_OK */
SANIM_API res_T
sanim_node_visit_tree
(struct sanim_node* node,
- const double in_dir[3],
+ const double in_dir[3], /* May be NULL <=> do not solve pivot */
void* data,
res_T (*visitor)
(const struct sanim_node* n, const double transform[12], void* data));
diff --git a/src/sanim_node.c b/src/sanim_node.c
@@ -165,7 +165,7 @@ compose_pivot_transform_L(const struct pivot_data* pivot, double accum[12]) {
}
static double*
-get_pivot_transform(const struct pivot_data* pivot, double transform[12])
+get_pivot_transform(const struct pivot_data* pivot, double transform[12])
{
ASSERT(pivot && transform);
switch (pivot->pivot.type) {
@@ -862,10 +862,10 @@ visit_tree
struct sanim_node* const* children;
double transform[12];
res_T res = RES_OK;
- ASSERT(node && node->data && in_dir && visitor);
- ASSERT(d3_is_normalized(in_dir));
+ ASSERT(node && node->data && visitor);
+ ASSERT(!in_dir || d3_is_normalized(in_dir));
- if (node->data->pivot_data) {
+ if (in_dir && node->data->pivot_data) {
res = node_solve_pivot(node, in_dir);
if (res != RES_OK) return res;
}
@@ -1035,19 +1035,19 @@ sanim_node_visit_tree
(struct sanim_node* node,
const double in_dir[3],
void* data,
- res_T(*visitor)(
- const struct sanim_node* n, const double transform[12], void* data))
+ res_T(*visitor)
+ (const struct sanim_node* n, const double transform[12], void* data))
{
double dir[3];
double transform[12];
size_t count, i;
struct sanim_node* const* children;
res_T res = RES_OK;
- if (!node || !node->data || !in_dir || !visitor) return RES_BAD_ARG;
- if (!d3_normalize(dir, in_dir)) return RES_BAD_ARG;
+ if (!node || !node->data || !visitor) return RES_BAD_ARG;
+ if (in_dir && !d3_normalize(dir, in_dir)) return RES_BAD_ARG;
- if (node->data->pivot_data) {
- res = node_solve_pivot(node, in_dir);
+ if (in_dir && node->data->pivot_data) {
+ res = node_solve_pivot(node, dir);
if (res != RES_OK) return res;
}
@@ -1060,7 +1060,7 @@ sanim_node_visit_tree
children = darray_children_data_get(&node->data->children);
for (i = 0; i < count; i++) {
struct sanim_node* child = children[i];
- res = visit_tree(child, dir, data, visitor, transform);
+ res = visit_tree(child, in_dir ? dir : NULL, data, visitor, transform);
if (res != RES_OK) return res;
}
return RES_OK;
diff --git a/src/test_sanim_visit.c b/src/test_sanim_visit.c
@@ -1,18 +1,17 @@
-
/* Copyright (C) CNRS 2016
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "sanim.h"
#include "test_sanim_utils.h"