#ifndef rdo_raytrace_H #define rdo_raytrace_H /* Tracing rays in a scene. */ #define rdo_raytrace_H_COPYRIGHT "Copyright © 2008 Danillo Pereira and J. Stolfi, UNICAMP" /* Last edited on 2024-12-21 11:51:48 by stolfi */ #include #include #include #include #include #include #include #define RAY_ORIGIN_EPSILON (1.0e-8) /* The ray tracing routines apply a perturbation of this magnitude (in scene units) to ray endpoints, in the appropriate direction, in order to ensure that a ray cast from a point that should be on the surface of some object, in a direction that points outwards from the object, will not hit the same object right away. Note that the perturbation may cause the ray to go through very thin objects without noticing their presence. */ void rdo_raytrace_first_hit(solid_vec_t *sds, point3_t *eye, vector3_t *dir, double *distP, int *iobP); /* Places into {*distP} the parameter {t} of the ray {eye + t*dir} that corresponds to the first point where the ray enters some solid object in the list {sds}; and places into {*iobP} the index of that solid object. If the ray doesnot hit any object, stores {+INF} into {*distP} and {-1} into {*iobP}. If the point {eye} is in the interior of some solid object, stores {-1.0} into {*distP} and the index of that solid object into {*iobP}. */ double rdo_raytrace_hit_distance(solid_t *sd, point3_t *eye, vector3_t *dir); /* Determines the parameter {t} of the ray {eye + t*dir} that corresponds to the point where the ray enters the given solid object {sd}. Returns {+INF} if the ray doesn't intersect the solid object. Returns {-1.0} if the point {eye} is in the interior of the solid object. */ double rdo_raytrace_hit_distance_ovoid(point3_t corner[], point3_t *eye, vector3_t *dir); double rdo_raytrace_hit_distance_brick(point3_t corner[], point3_t *eye, vector3_t *dir); /* Similar to {rdo_raytrace_hit_distance}, but specialized for a single type of solid object. */ #define VISIBILITY_TOLERANCE (0.0000005) double rdo_raytrace_pt_pt_visibility(solid_vec_t *sds, point3_t *pA, point3_t *pB); /* Returns the visibbility factor between points {pA} and {pB} taking into account the opaque solid objects {sds}. Specifically, returns 0.0 (occlusion) if the straight line segment with endpoints {pA} and {pB}, shortened by {VISIBILITY_TOLERANCE} at both ends, intercepts any solid object in the list {sds}; otherwise returns 1.0 (free sight). */ double rdo_raytrace_pt_site_visibility(solid_vec_t *sds, point3_t *pA, point3_t *pB, vector3_t *nB); /* Determines the visibility between points {pA} and {pB} taking into account the opaque solid objects {sds}. Assumes that the surface normal at {pB} is {nB}. (This function is meant to be used when {pA} is a point of {R^3} which is not supposed to be on the scene's surface, e.g. the camera's eye point or a point light source.) The result is 0.0 (occlusion) if the point {pA} is below the surface's tangent plane at {pB}, ou if there is some solid object between {pA} and {pB}. Otherwise the result is 1.0 (fre sight). */ void rdo_raytrace_first_hit_site(solid_vec_t *sds, point3_t *eye, vector3_t *dir, site_t *sP, double *distP); /* Determines the first site where a given ray intercepts any of the solid objects {sds->e[0..sds->ne-1]}. The ray begins at the point {eye} and proceeds in the direction {dir}. Stores into {*distP} the distance from {eye} to the hit point, and into {*sP} the site corresponding to that point. If the {eye} is in the interior of any solid object, the distance {*distP} will be set to a negative value, and {*s} will be a site on that solid object, with position {eye} but normal {(0,0,0)}. If the ray does not hit any object, {*distP} will be set to {+INF}, and {*sP} will be an invalid site, com {.isd == -1}. !!! Criar the solid object `esfera celeste', para que todo ray intercepte algo. !!! */ int rdo_raytrace_find_nearest_visible(solid_vec_t *sds, point3_t *eye, vector3_t *dir, site_vec_t *sts); /* Computes the first site {sRef} where the ray {eye + t*dir} meets the solid list {sds}, and then returns the site {sts->e[i]} that is visible from {eye} and is closest to {sRef}. If the ray does not meet any solid, or if there is no visible site in {sts}, returns -1. */ #endif