senc3d_sXd_helper.h (2812B)
1 /* Copyright (C) 2018-2020, 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 SENC3D_S3D_WRAPPER_H 17 #define SENC3D_S3D_WRAPPER_H 18 19 #include "senc3d.h" 20 21 #include <rsys/rsys.h> 22 23 /* Get vertex indices for the itri_th triangle. 24 * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices 25 * calls. */ 26 static FINLINE void 27 senc3d_sXd_scene_get_indices 28 (const unsigned itri, 29 unsigned indices[SENC3D_GEOMETRY_DIMENSION], 30 void* ctx) 31 { 32 const struct senc3d_scene* scene = ctx; 33 ASSERT(indices && scene); 34 SENC3D(scene_get_triangle(scene, itri, indices)); 35 } 36 37 /* Get coordinates for the ivert_th vertex. 38 * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage 39 * in s3d_mesh_setup_indexed_vertices calls. */ 40 static FINLINE void 41 senc3d_sXd_scene_get_position 42 (const unsigned ivert, 43 float coord[SENC3D_GEOMETRY_DIMENSION], 44 void* ctx) 45 { 46 const struct senc3d_scene* scene = ctx; 47 double tmp[SENC3D_GEOMETRY_DIMENSION]; 48 int i; 49 ASSERT(coord && scene); 50 SENC3D(scene_get_vertex(scene, ivert, tmp)); 51 FOR_EACH(i, 0, SENC3D_GEOMETRY_DIMENSION) coord[i] = (float)tmp[i]; 52 } 53 54 /* Get vertex indices for the itri_th triangle of the enclosure. 55 * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices 56 * calls. */ 57 static FINLINE void 58 senc3d_sXd_enclosure_get_indices 59 (const unsigned itri, 60 unsigned indices[SENC3D_GEOMETRY_DIMENSION], 61 void* ctx) 62 { 63 const struct senc3d_enclosure* enclosure = ctx; 64 ASSERT(indices && ctx); 65 SENC3D(enclosure_get_triangle(enclosure, itri, indices)); 66 } 67 68 /* Get coordinates for the ivert_th vertex of the enclosure. 69 * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage 70 * in s3d_mesh_setup_indexed_vertices calls. */ 71 static FINLINE void 72 senc3d_sXd_enclosure_get_position 73 (const unsigned ivert, 74 float coord[SENC3D_GEOMETRY_DIMENSION], 75 void* ctx) 76 { 77 const struct senc3d_enclosure* enclosure = ctx; 78 double tmp[SENC3D_GEOMETRY_DIMENSION]; 79 int i; 80 ASSERT(coord && ctx); 81 SENC3D(enclosure_get_vertex(enclosure, ivert, tmp)); 82 FOR_EACH(i, 0, SENC3D_GEOMETRY_DIMENSION) coord[i] = (float)tmp[i]; 83 } 84 85 #endif /* SENC3D_S3D_WRAPPER_H */