solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

ssol_shape_c.h (4011B)


      1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2016, 2018 CNRS
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #ifndef SSOL_SHAPE_C_H
     18 #define SSOL_SHAPE_C_H
     19 
     20 #include "ssol.h"
     21 
     22 #include <rsys/ref_count.h>
     23 
     24 enum shape_type {
     25   SHAPE_MESH,
     26   SHAPE_PUNCHED,
     27   SHAPE_TYPES_COUNT__
     28 };
     29 
     30 struct priv_parabol_data {
     31   double focal;
     32   double one_over_4focal;
     33 };
     34 
     35 struct priv_hyperbol_data {
     36   double g_square;
     37   double a_square_over_b_square;
     38   double one_over_a_square;
     39   double abs_b;
     40 };
     41 
     42 struct priv_pcylinder_data {
     43   double focal;
     44   double one_over_4focal;
     45 };
     46 
     47 struct priv_hemisphere_data {
     48   double radius;
     49   double sqr_radius;
     50 };
     51 
     52 union private_data {
     53   struct priv_hyperbol_data hyperbol;
     54   struct priv_parabol_data parabol;
     55   struct priv_pcylinder_data pcylinder;
     56   struct priv_hemisphere_data hemisphere;
     57 };
     58 
     59 struct ssol_shape {
     60   enum shape_type type;
     61   enum ssol_quadric_type quadric_type; /* Defined if type is SHAPE_PUNCHED */
     62 
     63   struct s3d_shape* shape_rt; /* Star-3D shape to ray-trace */
     64   struct s3d_shape* shape_samp; /* Star-3D shape to sample */
     65   union private_data private_data;
     66   double transform[12];
     67   double shape_rt_area, shape_samp_area;
     68 
     69   struct ssol_device* dev;
     70   ref_T ref;
     71 };
     72 
     73 typedef int(*intersect_local_fn)
     74   (const struct ssol_shape* shape,
     75    const double org[3],
     76    const double dir[3],
     77    const double hint,
     78    double pt[3],
     79    double N[3],
     80    double* dist);
     81 
     82 /* Project pos onto the punched surface and retrieve its associated normal */
     83 extern LOCAL_SYM void
     84 punched_shape_project_point
     85   (struct ssol_shape* shape,
     86    const double transform[12], /* Shape to world space transformation */
     87    const double pos[3], /* World space position near of the quadric */
     88    double pos_quadric[3], /* World space position onto the quadric */
     89    double N_quadric[3]); /* World space normal onto the quadric */
     90 
     91 /* Return the hit distance of the ray wrt the punched surface. >= FLT_MAX if
     92  * the ray does not intersect the quadric */
     93 extern LOCAL_SYM double
     94 punched_shape_trace_ray
     95   (struct ssol_shape* shape,
     96    const double transform[12], /* Shape to world space transformation */
     97    const double org[3], /* Ray origin in world space */
     98    const double dir[3], /* Ray direction in world space */
     99    const double hint_dst, /* Hint on the hit distance */
    100    double N_quadric[3]); /* World space normal onto the quadric */
    101 
    102 /* Fetch vertex attrib without any post treatment, i.e. the position and the
    103  * normal are not transformed */
    104 extern LOCAL_SYM res_T
    105 shape_fetched_raw_vertex_attrib
    106   (const struct ssol_shape* shape,
    107    const unsigned ivert,
    108    const enum ssol_attrib_usage usage,
    109    double value[3]);
    110 
    111 /* Compute ray/punched shape intersection */
    112 extern LOCAL_SYM int punched_shape_intersect_local
    113   (const struct ssol_shape* shape,
    114    const double org[3],
    115    const double dir[3],
    116    const double hint,
    117    double pt[3],
    118    double N[3],
    119    double* dist);
    120 
    121 /* Compute ray/shape intersection */
    122 extern LOCAL_SYM double
    123 shape_trace_ray
    124   (struct ssol_shape* shape,
    125    const double transform[12], /* Shape to world space transformation */
    126    const double org[3], /* World space position near of the ray origin */
    127    const double dir[3], /* World space ray direction */
    128    const double hint_dst, /* Hint on the hit distance */
    129    double N_quadric[3], /* World space normal onto the quadric */
    130    intersect_local_fn local);
    131 
    132 #endif /* SSOL_SHAPE_C_H */
    133