star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

test_s3d_cbox.h (3730B)


      1 /* Copyright (C) 2015-2023 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #ifndef TEST_S3D_CBOX_H
     17 #define TEST_S3D_CBOX_H
     18 
     19 #include <rsys/rsys.h>
     20 #include <stdint.h>
     21 
     22 struct cbox_desc {
     23   const float* vertices;
     24   const unsigned* indices;
     25 };
     26 
     27 /*******************************************************************************
     28  * Box
     29  ******************************************************************************/
     30 static const float cbox_walls[] = {
     31   552.f, 0.f,   0.f,
     32   0.f,   0.f,   0.f,
     33   0.f,   559.f, 0.f,
     34   552.f, 559.f, 0.f,
     35   552.f, 0.f,   548.f,
     36   0.f,   0.f,   548.f,
     37   0.f,   559.f, 548.f,
     38   552.f, 559.f, 548.f
     39 };
     40 const unsigned cbox_walls_nverts = sizeof(cbox_walls) / (sizeof(float)*3);
     41 
     42 const unsigned cbox_walls_ids[] = {
     43   0, 1, 2, 2, 3, 0, /* Bottom */
     44   4, 5, 6, 6, 7, 4, /* Top */
     45   1, 2, 6, 6, 5, 1, /* Left */
     46   0, 3, 7, 7, 4, 0, /* Right */
     47   2, 3, 7, 7, 6, 2  /* Back */
     48 };
     49 const unsigned cbox_walls_ntris = sizeof(cbox_walls_ids) / (sizeof(unsigned)*3);
     50 
     51 static const struct cbox_desc cbox_walls_desc = { cbox_walls, cbox_walls_ids };
     52 
     53 /*******************************************************************************
     54  * Short/tall blocks
     55  ******************************************************************************/
     56 static const float cbox_short_block[] = {
     57   130.f, 65.f,  0.f,
     58   82.f,  225.f, 0.f,
     59   240.f, 272.f, 0.f,
     60   290.f, 114.f, 0.f,
     61   130.f, 65.f,  165.f,
     62   82.f,  225.f, 165.f,
     63   240.f, 272.f, 165.f,
     64   290.f, 114.f, 165.f
     65 };
     66 
     67 static const float cbox_tall_block[] = {
     68   423.0f, 247.0f, 0.f,
     69   265.0f, 296.0f, 0.f,
     70   314.0f, 456.0f, 0.f,
     71   472.0f, 406.0f, 0.f,
     72   423.0f, 247.0f, 330.f,
     73   265.0f, 296.0f, 330.f,
     74   314.0f, 456.0f, 330.f,
     75   472.0f, 406.0f, 330.f
     76 };
     77 
     78 static const unsigned cbox_block_ids[] = {
     79   4, 5, 6, 6, 7, 4,
     80   1, 2, 6, 6, 5, 1,
     81   0, 3, 7, 7, 4, 0,
     82   2, 3, 7, 7, 6, 2,
     83   0, 1, 5, 5, 4, 0
     84 };
     85 
     86 const unsigned cbox_block_nverts = sizeof(cbox_short_block) / (sizeof(float)*3);
     87 const unsigned cbox_block_ntris = sizeof(cbox_block_ids) / (sizeof(unsigned)*3);
     88 
     89 /*******************************************************************************
     90  * Callbacks
     91  ******************************************************************************/
     92 static INLINE void
     93 cbox_get_ids(const unsigned itri, unsigned ids[3], void* data)
     94 {
     95   const unsigned id = itri * 3;
     96   struct cbox_desc* desc = data;
     97   CHK(desc != NULL);
     98   ids[0] = desc->indices[id + 0];
     99   ids[1] = desc->indices[id + 1];
    100   ids[2] = desc->indices[id + 2];
    101 }
    102 
    103 static INLINE void
    104 cbox_get_position(const unsigned ivert, float position[3], void* data)
    105 {
    106   struct cbox_desc* desc = data;
    107   CHK(desc != NULL);
    108   position[0] = desc->vertices[ivert*3 + 0];
    109   position[1] = desc->vertices[ivert*3 + 1];
    110   position[2] = desc->vertices[ivert*3 + 2];
    111 }
    112 
    113 static INLINE void
    114 cbox_get_normal(const unsigned ivert, float normal[3], void* data)
    115 {
    116   (void)ivert, (void)data;
    117   normal[0] = 1.f;
    118   normal[1] = 0.f;
    119   normal[2] = 0.f;
    120 }
    121 
    122 static INLINE void
    123 cbox_get_uv(const unsigned ivert, float uv[2], void* data)
    124 {
    125   (void)ivert, (void)data;
    126   uv[0] = -1.f;
    127   uv[1] = 1.f;
    128 }
    129 
    130 #endif /* TEST_S3D_CBOX_H */
    131