senc2d_sXd_helper.h (2808B)
1 /* Copyright (C) 2018-2021, 2023, 2024 |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 SENC2D_S2D_WRAPPER_H 17 #define SENC2D_S2D_WRAPPER_H 18 19 #include "senc2d.h" 20 21 #include <rsys/rsys.h> 22 23 /* Get vertex indices for the iseg_th segment. 24 * Suitable for use as get_indice callback in s2d_mesh_setup_indexed_vertices 25 * calls. */ 26 static FINLINE void 27 senc2d_sXd_scene_get_indices 28 (const unsigned iseg, 29 unsigned indices[SENC2D_GEOMETRY_DIMENSION], 30 void* ctx) 31 { 32 const struct senc2d_scene* scene = ctx; 33 ASSERT(indices && scene); 34 SENC2D(scene_get_segment(scene, iseg, indices)); 35 } 36 37 /* Get coordinates for the ivert_th vertex. 38 * Suitable for use as s2d_vertex_data getter for S2D_POSITION s2d_attrib_usage 39 * in s2d_mesh_setup_indexed_vertices calls. */ 40 static FINLINE void 41 senc2d_sXd_scene_get_position 42 (const unsigned ivert, 43 float coord[SENC2D_GEOMETRY_DIMENSION], 44 void* ctx) 45 { 46 const struct senc2d_scene* scene = ctx; 47 double tmp[SENC2D_GEOMETRY_DIMENSION]; 48 int i; 49 ASSERT(coord && scene); 50 SENC2D(scene_get_vertex(scene, ivert, tmp)); 51 FOR_EACH(i, 0, SENC2D_GEOMETRY_DIMENSION) coord[i] = (float)tmp[i]; 52 } 53 54 /* Get vertex indices for the iseg_th segment of the enclosure. 55 * Suitable for use as get_indice callback in s2d_mesh_setup_indexed_vertices 56 * calls. */ 57 static FINLINE void 58 senc2d_sXd_enclosure_get_indices 59 (const unsigned iseg, 60 unsigned indices[SENC2D_GEOMETRY_DIMENSION], 61 void* ctx) 62 { 63 const struct senc2d_enclosure* enclosure = ctx; 64 ASSERT(indices && ctx); 65 SENC2D(enclosure_get_segment(enclosure, iseg, indices)); 66 } 67 68 /* Get coordinates for the ivert_th vertex of the enclosure. 69 * Suitable for use as s2d_vertex_data getter for S2D_POSITION s2d_attrib_usage 70 * in s2d_mesh_setup_indexed_vertices calls. */ 71 static FINLINE void 72 senc2d_sXd_enclosure_get_position 73 (const unsigned ivert, 74 float coord[SENC2D_GEOMETRY_DIMENSION], 75 void* ctx) 76 { 77 const struct senc2d_enclosure* enclosure = ctx; 78 double tmp[SENC2D_GEOMETRY_DIMENSION]; 79 int i; 80 ASSERT(coord && ctx); 81 SENC2D(enclosure_get_vertex(enclosure, ivert, tmp)); 82 FOR_EACH(i, 0, SENC2D_GEOMETRY_DIMENSION) coord[i] = (float)tmp[i]; 83 } 84 85 #endif /* SENC2D_S2D_WRAPPER_H */