solstice-anim

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

test_sanim_node_transform.c (5453B)


      1 /* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2016-2018 CNRS
      3 *
      4 * This program is free software: you can redistribute it and/or modify
      5 * it under the terms of the GNU General Public License as published by
      6 * the Free Software Foundation, either version 3 of the License, or
      7 * (at your option) any later version.
      8 *
      9 * This program is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #include "sanim.h"
     18 #include "test_sanim_utils.h"
     19 
     20 #include <rsys/double33.h>
     21 
     22 int
     23 main(int argc, char** argv)
     24 {
     25   struct mem_allocator allocator;
     26   struct my_type *t1, *t2, *t3, *t, *ptr;
     27   double transl[3], rot[3];
     28   double transform[12], transform_[12];
     29   (void) argc, (void) argv;
     30 
     31   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     32   
     33   /* test a typical use in my_type */
     34   CHK(my_type_create(&allocator, &t1) == RES_OK);
     35   CHK(my_type_create(&allocator, &t2) == RES_OK);
     36 
     37   CHK(my_type_add_child(t1, t2) == RES_OK);
     38 
     39   d3_splat(transl, +1);
     40   CHK(my_type_set_translation(t1, transl) == RES_OK);
     41 
     42   d3_splat(transl, -1);
     43   CHK(my_type_set_translation(t2, transl) == RES_OK);
     44 
     45   CHK(my_type_get_transform(t2, transform) == RES_OK);
     46   CHK(d33_is_identity(transform) == 1);
     47   CHK(d3_is_zero(transform + 9) == 1);
     48 
     49   d3(rot, PI, 0, 0);
     50   CHK(my_type_set_rotations(NULL, rot) == RES_BAD_ARG);
     51   CHK(my_type_set_rotations(t1, NULL) == RES_BAD_ARG);
     52   CHK(my_type_set_rotations(t1, rot) == RES_OK);
     53   CHK(my_type_set_rotations(t2, rot) == RES_OK);
     54   d3(transl, 0, +1, 0);
     55   CHK(my_type_set_translation(t1, transl) == RES_OK);
     56   CHK(my_type_set_translation(t2, transl) == RES_OK);
     57 
     58   CHK(my_type_get_transform(t2, transform) == RES_OK);
     59   CHK(d33_is_identity_eps(transform, 1e-7) == 1);
     60   CHK(d3_is_zero_eps(transform + 9, 1e-7) == 1);
     61 
     62   /* check translation & 1 rotation in a single node VS in 2 chained nodes */
     63   d3(rot, 0.17, 0, 0);
     64   d3(transl, 0.3, 2, -1);
     65   CHK(my_type_create(&allocator, &t) == RES_OK);
     66   CHK(my_type_set_translation(t, transl) == RES_OK);
     67   CHK(my_type_set_rotations(t, rot) == RES_OK);
     68   CHK(my_type_get_transform(t, transform) == RES_OK);
     69   CHK(my_type_create(&allocator, &t3) == RES_OK);
     70   CHK(my_type_add_child(t2, t3) == RES_OK);
     71   d3(rot, 0, 0, 0);
     72   CHK(my_type_set_translation(t1, transl) == RES_OK);
     73   CHK(my_type_set_rotations(t1, rot) == RES_OK);
     74   d3(transl, 0, 0, 0);
     75   d3(rot, 0.17, 0, 0);
     76   CHK(my_type_set_translation(t2, transl) == RES_OK);
     77   CHK(my_type_set_rotations(t2, rot) == RES_OK);
     78   CHK(my_type_get_transform(t2, transform_) == RES_OK);
     79   CHK(d33_eq_eps(transform, transform_, 1e-7) == 1);
     80   CHK(d3_eq_eps(transform + 9, transform_ + 9, 1e-7) == 1);
     81 
     82   /* check translation & 2 rotations in a single node VS in 2 chained nodes */
     83   d3(rot, 0.17, -0.52, 0);
     84   d3(transl, 0.3, 2, -1);
     85   CHK(my_type_set_translation(t, transl) == RES_OK);
     86   CHK(my_type_set_rotations(t, rot) == RES_OK);
     87   CHK(my_type_get_transform(t, transform) == RES_OK);
     88   d3(rot, 0, 0, 0);
     89   CHK(my_type_set_translation(t1, transl) == RES_OK);
     90   CHK(my_type_set_rotations(t1, rot) == RES_OK);
     91   d3(transl, 0, 0, 0);
     92   d3(rot, 0.17, 0, 0);
     93   CHK(my_type_set_translation(t2, transl) == RES_OK);
     94   CHK(my_type_set_rotations(t2, rot) == RES_OK);
     95   d3(rot, 0, -0.52, 0);
     96   CHK(my_type_set_translation(t3, transl) == RES_OK);
     97   CHK(my_type_set_rotations(t3, rot) == RES_OK);
     98   CHK(my_type_get_transform(t3, transform_) == RES_OK);
     99   CHK(d33_eq_eps(transform, transform_, 1e-7) == 1);
    100   CHK(d3_eq_eps(transform + 9, transform_ + 9, 1e-7) == 1);
    101 
    102   /* check 1 node with 3 rotations VS 3 chained nodes with 1 rotation each */
    103   d3(rot, 0.17, -0.52, 0.31);
    104   d3(transl, 0.3, 2, -1);
    105   CHK(my_type_set_translation(t, transl) == RES_OK);
    106   CHK(my_type_set_rotations(t, rot) == RES_OK);
    107   CHK(my_type_get_transform(t, transform) == RES_OK);
    108   d3(rot, 0.17, 0, 0);
    109   CHK(my_type_set_translation(t1, transl) == RES_OK);
    110   CHK(my_type_set_rotations(t1, rot) == RES_OK);
    111   d3(transl, 0, 0, 0);
    112   d3(rot, 0, -0.52, 0);
    113   CHK(my_type_set_translation(t2, transl) == RES_OK);
    114   CHK(my_type_set_rotations(t2, rot) == RES_OK);
    115   d3(rot, 0, 0, 0.31);
    116   CHK(my_type_set_translation(t3, transl) == RES_OK);
    117   CHK(my_type_set_rotations(t3, rot) == RES_OK);
    118   CHK(my_type_get_transform(t3, transform_) == RES_OK);
    119   CHK(d33_eq_eps(transform, transform_, 1e-7) == 1);
    120   CHK(d3_eq_eps(transform + 9, transform_ + 9, 1e-7) == 1);
    121 
    122   /* check 3 chained nodes with 1 rotation each VS a copy */
    123   CHK(my_type_ref_put(t) == RES_OK);
    124   CHK(my_type_recursive_copy(&allocator, t1, &t) == RES_OK);
    125   CHK(my_type_get_transform(t3, transform) == RES_OK);
    126   CHK(my_type_get_child(t, 0, &ptr) == RES_OK);
    127   CHK(my_type_get_child(ptr, 0, &ptr) == RES_OK);
    128   CHK(my_type_get_transform(ptr, transform_) == RES_OK);
    129   CHK(d33_eq_eps(transform, transform_, 1e-7) == 1);
    130   CHK(d3_eq_eps(transform + 9, transform_ + 9, 1e-7) == 1);
    131 
    132   /* release memory */
    133   CHK(my_type_ref_put(t1) == RES_OK);
    134   CHK(my_type_ref_put(t2) == RES_OK);
    135   CHK(my_type_ref_put(t3) == RES_OK);
    136   CHK(my_type_ref_put(t) == RES_OK);
    137 
    138   check_memory_allocator(&allocator);
    139   mem_shutdown_proxy_allocator(&allocator);
    140   CHK(mem_allocated_size() == 0);
    141   return 0;
    142 }