mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
ray: ray sphere intersection
This commit is contained in:
59
include/cglm/struct/ray.h
Normal file
59
include/cglm/struct/ray.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#ifndef cglms_ray_h
|
||||
#define cglms_ray_h
|
||||
|
||||
#include "../common.h"
|
||||
#include "../types-struct.h"
|
||||
#include "../ray.h"
|
||||
|
||||
/* api definition */
|
||||
#define glms_ray_(NAME) CGLM_STRUCTAPI(ray, NAME)
|
||||
|
||||
/*!
|
||||
* @brief Möller–Trumbore ray-triangle intersection algorithm
|
||||
*
|
||||
* @param[in] origin origin of ray
|
||||
* @param[in] direction direction of ray
|
||||
* @param[in] v0 first vertex of triangle
|
||||
* @param[in] v1 second vertex of triangle
|
||||
* @param[in] v2 third vertex of triangle
|
||||
* @param[in, out] d distance to intersection
|
||||
* @return whether there is intersection
|
||||
*/
|
||||
CGLM_INLINE
|
||||
bool
|
||||
glms_ray_(triangle)(vec3s origin,
|
||||
vec3s direction,
|
||||
vec3s v0,
|
||||
vec3s v1,
|
||||
vec3s v2,
|
||||
float *d) {
|
||||
return glm_ray_triangle(origin.raw, direction.raw, v0.raw, v1.raw, v2.raw, d);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief ray sphere intersection
|
||||
*
|
||||
* @param[in] origin ray origin
|
||||
* @param[out] dir normalized ray direction
|
||||
* @param[in] s sphere [center.x, center.y, center.z, radii]
|
||||
* @param[in] t1 near point1 (closer to origin)
|
||||
* @param[in] t2 far point2 (farther from origin)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
bool
|
||||
glms_ray_(sphere)(vec3s origin,
|
||||
vec3s dir,
|
||||
vec4s s,
|
||||
float * __restrict t1,
|
||||
float * __restrict t2) {
|
||||
return glm_ray_sphere(origin.raw, dir.raw, s.raw, t1, t2);
|
||||
}
|
||||
|
||||
#endif /* cglms_ray_h */
|
||||
Reference in New Issue
Block a user