diff --git a/include/cglm/call/ray.h b/include/cglm/call/ray.h index 02fe632..e529fdf 100644 --- a/include/cglm/call/ray.h +++ b/include/cglm/call/ray.h @@ -29,6 +29,10 @@ glmc_ray_sphere(vec3 origin, float * __restrict t1, float * __restrict t2); +CGLM_EXPORT +void +glmc_ray_at(vec3 orig, vec3 dir, float t, vec3 point); + #ifdef __cplusplus } #endif diff --git a/include/cglm/ray.h b/include/cglm/ray.h index ec993c6..d815166 100644 --- a/include/cglm/ray.h +++ b/include/cglm/ray.h @@ -18,6 +18,7 @@ vec4 s, float * __restrict t1, float * __restrict t2) + CGLM_INLINE void glm_ray_at(vec3 orig, vec3 dir, float t, vec3 point); */ #ifndef cglm_ray_h @@ -144,4 +145,20 @@ glm_ray_sphere(vec3 origin, return true; } +/*! + * @brief point using t by 𝐏(𝑡)=𝐀+𝑡𝐛 + * + * @param[in] orig origin of ray + * @param[in] dir direction of ray + * @param[in] t parameter + * @param[out] point point at t + */ +CGLM_INLINE +void +glm_ray_at(vec3 orig, vec3 dir, float t, vec3 point) { + vec3 dst; + glm_vec3_scale(dir, t, dst); + glm_vec3_add(orig, dst, point); +} + #endif diff --git a/include/cglm/struct/ray.h b/include/cglm/struct/ray.h index 4eea68d..ca0e037 100644 --- a/include/cglm/struct/ray.h +++ b/include/cglm/struct/ray.h @@ -56,4 +56,20 @@ glms_ray_(sphere)(vec3s origin, return glm_ray_sphere(origin.raw, dir.raw, s.raw, t1, t2); } +/*! + * @brief point using t by 𝐏(𝑡)=𝐀+𝑡𝐛 + * + * @param[in] orig origin of ray + * @param[in] dir direction of ray + * @param[in] t parameter + * @returns point point at t + */ +CGLM_INLINE +vec3s +glms_ray_(at)(vec3s orig, vec3s dir, float t) { + vec3s r; + glm_ray_at(orig.raw, orig.raw, t, r.raw); + return r; +} + #endif /* cglms_ray_h */