star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

sg3d_sXd_helper.h (1848B)


      1 /* Copyright (C) 2019, 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 SG3D_S3D_HELPER_H__
     17 #define SG3D_S3D_HELPER_H__
     18 
     19 #include "sg3d.h"
     20 #include <star/senc3d.h>
     21 
     22 #include <rsys/rsys.h>
     23 
     24 /* Get vertex indices for the itri_th triangle.
     25  * Suitable for use as get_indice callback in s3d_mesh_setup_indexed_vertices
     26  * calls. */
     27 static FINLINE void
     28 sg3d_sXd_geometry_get_indices
     29   (const unsigned itri,
     30    unsigned indices[SG3D_GEOMETRY_DIMENSION],
     31    void* ctx)
     32 {
     33   const struct sg3d_geometry* geometry = ctx;
     34   ASSERT(indices && geometry);
     35   SG3D(geometry_get_unique_triangle_vertices(geometry, itri, indices));
     36 }
     37 
     38 /* Get coordinates for the ivert_th vertex.
     39  * Suitable for use as s3d_vertex_data getter for S3D_POSITION s3d_attrib_usage
     40  * in s3d_mesh_setup_indexed_vertices calls. */
     41 static FINLINE void
     42 sg3d_sXd_geometry_get_position
     43   (const unsigned ivert,
     44    float coord[SG3D_GEOMETRY_DIMENSION],
     45    void* ctx)
     46 {
     47   const struct sg3d_geometry* geometry = ctx;
     48   double tmp[3];
     49   int i;
     50   ASSERT(coord && geometry);
     51   SG3D(geometry_get_unique_vertex(geometry, ivert, tmp));
     52   FOR_EACH(i, 0, SG3D_GEOMETRY_DIMENSION) coord[i] = (float)tmp[i];
     53 }
     54 
     55 #endif /* SG3D_S3D_HELPER_H__ */