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