solstice-anim

Geometry animation library of the solstice app
git clone git://git.meso-star.com/solstice-anim.git
Log | Files | Refs | README | LICENSE

commit 8fab1e25e39df3970e553021a590025684d60cac
parent c6424b5d931a5fbaa9e54e73fe146b33c7bc653c
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 12 Oct 2016 17:37:08 +0200

First commit for pivots/tracking; uncomplete.

Diffstat:
Msrc/sanim.h | 52++++++++++++++++++++++++++++++++++++++++++++++------
Msrc/sanim_node.c | 33+++++++++++++++++++++++----------
Msrc/sanim_node_c.h | 1+
Msrc/test_sanim_node_pivot.c | 52+++++++++++-----------------------------------------
Msrc/test_sanim_utils.c | 14++++++++++++++
Msrc/test_sanim_utils.h | 7+++++++
6 files changed, 102 insertions(+), 57 deletions(-)

diff --git a/src/sanim.h b/src/sanim.h @@ -56,28 +56,67 @@ struct sanim_node { /* types to describe pivots */ enum pivot_type { - SINGLE_AXIS, - TWO_AXIS, + PIVOT_SINGLE_AXIS, + PIVOT_TWO_AXIS, - PIVOT_TYPE_COUNT__ + PIVOT_TYPES_COUNT__ }; struct sanim_pivot_1 { - double angle; + double ref_point[3]; + double ref_normal[3]; }; struct sanim_pivot_2 { - double angle; + double spacing[3]; + double ref_point[3]; + /* ref_normal is <0,1,0> */ }; struct sanim_pivot { enum pivot_type type; - union data { + union { struct sanim_pivot_1 pivot1; struct sanim_pivot_2 pivot2; } data; }; +/* types to describe tracking policies */ +enum tracking_policy { + TRACKING_SUN, /* orient the device to face the sun */ + TRACKING_POINT, /* direct the output flux towards a point */ + TRACKING_LINE, /* direct the output flux on a line */ + TRACKING_OUT_DIR, /* direct the output flux towards a given dir */ + + TRACKING_TYPES_COUNT +}; + +struct sanim_policy_sun { + char unused; +}; + +struct sanim_policy_point { + double pos[3]; +}; + +struct sanim_policy_line { + double p1[3]; + double p2[3]; +}; + +struct sanim_policy_dir { + double u[3]; +}; + +struct sanim_tracking { + enum tracking_policy policy; + union { + struct sanim_policy_sun sun; + struct sanim_policy_point point; + struct sanim_policy_line line; + struct sanim_policy_dir dir; + } data; +}; BEGIN_DECLS /******************************************************************************* @@ -112,6 +151,7 @@ SANIM_API res_T sanim_node_initialize_pivot (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */ const struct sanim_pivot* pivot, + const struct sanim_tracking* tracking, struct sanim_node* node); SANIM_API res_T diff --git a/src/sanim_node.c b/src/sanim_node.c @@ -120,11 +120,7 @@ sanim_node_initialize } darray_children_init(alloc, &node->data->children); - node->data->father = NULL; node->data->allocator = alloc; - node->data->pivot = NULL; - d3_splat(node->data->translation, 0); - d3_splat(node->data->rotations, 0); exit: return res; @@ -140,23 +136,34 @@ res_T sanim_node_initialize_pivot (struct mem_allocator* allocator, const struct sanim_pivot* pivot, + const struct sanim_tracking* tracking, struct sanim_node* node) { - res_T res; + struct mem_allocator* alloc; + res_T res = RES_OK; - if (!pivot) return RES_BAD_ARG; + if (!node || !pivot || !tracking) return RES_BAD_ARG; res = sanim_node_initialize(allocator, node); if (res != RES_OK) goto error; + alloc = allocator ? allocator : &mem_default_allocator; + node->data->pivot = MEM_CALLOC(alloc, 1, sizeof(struct sanim_pivot)); + if (!node->data->pivot) { + res = RES_MEM_ERR; + goto error; + } + node->data->tracking = MEM_CALLOC(alloc, 1, sizeof(struct sanim_tracking)); + if (!node->data->tracking) { + res = RES_MEM_ERR; + goto error; + } *node->data->pivot = *pivot; + *node->data->tracking = *tracking; exit: return res; error: - if (node->data) { - darray_children_release(&node->data->children); - node->data = NULL; - } + sanim_node_release(node); goto exit; } @@ -167,6 +174,12 @@ sanim_node_release if (!node) return RES_BAD_ARG; if (node->data) { darray_children_release(&node->data->children); + if (node->data->pivot) { + MEM_RM(node->data->allocator, node->data->pivot); + } + if (node->data->tracking) { + MEM_RM(node->data->allocator, node->data->tracking); + } MEM_RM(node->data->allocator, node->data); } return RES_OK; diff --git a/src/sanim_node_c.h b/src/sanim_node_c.h @@ -33,6 +33,7 @@ struct sanim_node_data { struct darray_children children; struct mem_allocator* allocator; struct sanim_pivot* pivot; + struct sanim_tracking* tracking; }; diff --git a/src/test_sanim_node_pivot.c b/src/test_sanim_node_pivot.c @@ -22,44 +22,37 @@ int main(int argc, char** argv) { struct mem_allocator allocator; - struct my_type t1, t2, t3, t; - double transl[3], rot[3], transform[12], transform2[12]; + struct my_type t1, t2, t3; + struct sanim_pivot pivot; + struct sanim_tracking tracking; + double transl[3], rot[3], transform[12]; (void) argc, (void) argv; mem_init_proxy_allocator(&allocator, &mem_default_allocator); /* test a typical use in my_type */ - CHECK(my_type_init(NULL, &t1), RES_OK); - CHECK(my_type_release(NULL), RES_BAD_ARG); - CHECK(my_type_release(&t1), RES_OK); + tracking.policy = TRACKING_SUN; + pivot.type = PIVOT_SINGLE_AXIS; + d3_splat(pivot.data.pivot1.ref_point, 0); + d3(pivot.data.pivot1.ref_normal, 0, 1, 0); CHECK(my_type_init(&allocator, &t1), RES_OK); - CHECK(my_type_init(&allocator, NULL), RES_BAD_ARG); - CHECK(my_type_init(&allocator, &t2), RES_OK); + CHECK(my_type_init_pivot(&allocator, &pivot, &tracking, &t2), RES_OK); + CHECK(my_type_init(&allocator, &t3), RES_OK); - CHECK(my_type_add_child(NULL, &t1), RES_BAD_ARG); - CHECK(my_type_add_child(&t1, NULL), RES_BAD_ARG); - CHECK(my_type_add_child(&t1, &t1), RES_BAD_ARG); CHECK(my_type_add_child(&t1, &t2), RES_OK); - CHECK(my_type_add_child(&t1, &t2), RES_BAD_ARG); - CHECK(my_type_add_child(&t2, &t1), RES_BAD_ARG); + CHECK(my_type_add_child(&t2, &t3), RES_OK); d3_splat(transl, +1); - CHECK(my_type_set_translation(NULL, transl), RES_BAD_ARG); - CHECK(my_type_set_translation(&t1, NULL), RES_BAD_ARG); CHECK(my_type_set_translation(&t1, transl), RES_OK); d3_splat(transl, -1); CHECK(my_type_set_translation(&t2, transl), RES_OK); - CHECK(my_type_get_world_transform(NULL, transform), RES_BAD_ARG); - CHECK(my_type_get_world_transform(&t2, NULL), RES_BAD_ARG); CHECK(my_type_get_world_transform(&t2, transform), RES_OK); CHECK(d33_is_identity(transform), 1); CHECK(d3_is_zero(transform + 9), 1); d3(rot, PI, 0, 0); - CHECK(my_type_set_rotations(NULL, rot), RES_BAD_ARG); - CHECK(my_type_set_rotations(&t1, NULL), RES_BAD_ARG); CHECK(my_type_set_rotations(&t1, rot), RES_OK); CHECK(my_type_set_rotations(&t2, rot), RES_OK); d3(transl, 0, +1, 0); @@ -70,32 +63,9 @@ main(int argc, char** argv) CHECK(d33_is_identity_eps(transform, 1e-10), 1); CHECK(d3_is_zero_eps(transform + 9, 1e-10), 1); - /* check 1 node with 3 rotations VS 3 chained nodes with 1 rotation each */ - d3(rot, 0.17, -0.52, 0.31); - d3(transl, 0.3, 2, -1); - CHECK(my_type_init(&allocator, &t), RES_OK); - CHECK(my_type_set_translation(&t, transl), RES_OK); - CHECK(my_type_set_rotations(&t, rot), RES_OK); - CHECK(my_type_get_world_transform(&t, transform), RES_OK); - CHECK(my_type_init(&allocator, &t3), RES_OK); - CHECK(my_type_add_child(&t2, &t3), RES_OK); - d3(rot, 0.17, 0, 0); - CHECK(my_type_set_translation(&t1, transl), RES_OK); - CHECK(my_type_set_rotations(&t1, rot), RES_OK); - d3(transl, 0, 0, 0); - d3(rot, 0, -0.52, 0); - CHECK(my_type_set_translation(&t2, transl), RES_OK); - CHECK(my_type_set_rotations(&t2, rot), RES_OK); - d3(rot, 0, 0, 0.31); - CHECK(my_type_set_translation(&t3, transl), RES_OK); - CHECK(my_type_set_rotations(&t3, rot), RES_OK); - CHECK(my_type_get_world_transform(&t3, transform2), RES_OK); - CHECK(d33_eq_eps(transform, transform2, 1e-10), 1); - CHECK(my_type_release(&t1), RES_OK); CHECK(my_type_release(&t2), RES_OK); CHECK(my_type_release(&t3), RES_OK); - CHECK(my_type_release(&t), RES_OK); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator); diff --git a/src/test_sanim_utils.c b/src/test_sanim_utils.c @@ -30,6 +30,20 @@ my_type_init(struct mem_allocator *allocator, struct my_type* t) { } res_T +my_type_init_pivot + (struct mem_allocator *allocator, + const struct sanim_pivot* pivot, + const struct sanim_tracking* tracking, + struct my_type* t) +{ + if (!t) return RES_BAD_ARG; + /* init my stuff */ + t->my_data = 0; + /* init node stuff */ + return sanim_node_initialize_pivot(allocator, pivot, tracking, &t->node); +} + +res_T my_type_release(struct my_type* t) { if (!t) return RES_BAD_ARG; /* release my stuff */ diff --git a/src/test_sanim_utils.h b/src/test_sanim_utils.h @@ -35,6 +35,13 @@ res_T my_type_init(struct mem_allocator *allocator, struct my_type* t); res_T +my_type_init_pivot + (struct mem_allocator *allocator, + const struct sanim_pivot* pivot, + const struct sanim_tracking* tracking, + struct my_type* t); + +res_T my_type_release(struct my_type* t); res_T