docs for new ray functions

This commit is contained in:
Recep Aslantas
2024-03-22 22:30:22 +03:00
parent 6ad0aca7e0
commit da57558078
6 changed files with 132 additions and 2 deletions

View File

@@ -13,6 +13,8 @@ Table of contents (click to go):
Functions: Functions:
1. :c:func:`glm_ray_triangle` 1. :c:func:`glm_ray_triangle`
#. :c:func:`glm_ray_sphere`
#. :c:func:`glm_ray_at`
Functions documentation Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
@@ -29,3 +31,37 @@ Functions documentation
| *[in]* **v2** third vertex of triangle | *[in]* **v2** third vertex of triangle
| *[in, out]* **d** float pointer to save distance to intersection | *[in, out]* **d** float pointer to save distance to intersection
| *[out]* **intersection** whether there is intersection | *[out]* **intersection** whether there is intersection
.. c:function:: bool glm_ray_sphere(vec3 origin, vec3 dir, vec4 s, float * __restrict t1, float * __restrict t2)
ray sphere intersection
- t1 > 0, t2 > 0: ray intersects the sphere at t1 and t2 both ahead of the origin
- t1 < 0, t2 > 0: ray starts inside the sphere, exits at t2
- t1 < 0, t2 < 0: no intersection ahead of the ray
- the caller can check if the intersection points (t1 and t2) fall within a
specific range (for example, tmin < t1, t2 < tmax) to determine if the
intersections are within a desired segment of the ray
Parameters:
| *[in]* **origin** ray origin
| *[in]* **dir** normalized ray direction
| *[in]* **s** sphere [center.x, center.y, center.z, radii]
| *[out]* **t1** near point1 (closer to origin)
| *[out]* **t2** far point2 (farther from origin)
Return:
| whether there is intersection
.. c:function:: bool glm_ray_at(vec3 orig, vec3 dir, float t, vec3 point)
point using t by 𝐏(𝑡)=𝐀+𝑡𝐛
Parameters:
| *[in]* **origin** ray origin
| *[in]* **dir** ray direction
| *[out]* **t** parameter
| *[out]* **point** point at t
Return:
| point at t

View File

@@ -53,6 +53,8 @@ Functions:
#. :c:func:`glm_vec2_clamp` #. :c:func:`glm_vec2_clamp`
#. :c:func:`glm_vec2_lerp` #. :c:func:`glm_vec2_lerp`
#. :c:func:`glm_vec2_make` #. :c:func:`glm_vec2_make`
#. :c:func:`glm_vec2_reflect`
#. :c:func:`glm_vec2_refract`
Functions documentation Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
@@ -394,3 +396,25 @@ Functions documentation
Parameters: Parameters:
| *[in]* **src** pointer to an array of floats | *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec2_reflect(vec2 I, vec2 N, vec2 dest)
Reflection vector using an incident ray and a surface normal
Parameters:
| *[in]* **I** incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector
| *[out]* **dest** destination: reflection result
.. c:function:: void glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest)
Refraction vector using entering ray, surface normal and refraction index
If the angle between the entering ray I and the surface normal N is too
great for a given refraction index, the return value is zero
Parameters:
| *[in]* **I** *❗️ normalized ❗️* incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector
| *[in]* **eta** ratio of indices of refraction ( η )
| *[out]* **dest** destination: refraction result

View File

@@ -80,6 +80,9 @@ Functions:
#. :c:func:`glm_vec3_clamp` #. :c:func:`glm_vec3_clamp`
#. :c:func:`glm_vec3_lerp` #. :c:func:`glm_vec3_lerp`
#. :c:func:`glm_vec3_make` #. :c:func:`glm_vec3_make`
#. :c:func:`glm_vec3_faceforward`
#. :c:func:`glm_vec3_reflect`
#. :c:func:`glm_vec3_refract`
Functions documentation Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
@@ -512,3 +515,35 @@ Functions documentation
Parameters: Parameters:
| *[in]* **src** pointer to an array of floats | *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec3_faceforward(vec3 N, vec3 I, vec3 Nref, vec3 dest)
A vector pointing in the same direction as another
Parameters:
| *[in]* **N** vector to orient
| *[in]* **I** incident vector
| *[in]* **Nref** reference vector
| *[out]* **dest** destination: oriented vector, pointing away from the surface.
.. c:function:: void glm_vec3_reflect(vec3 I, vec3 N, vec3 dest)
Reflection vector using an incident ray and a surface normal
Parameters:
| *[in]* **I** incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector
| *[out]* **dest** destination: reflection result
.. c:function:: void glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest)
Refraction vector using entering ray, surface normal and refraction index
If the angle between the entering ray I and the surface normal N is too
great for a given refraction index, the return value is zero
Parameters:
| *[in]* **I** *❗️ normalized ❗️* incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector
| *[in]* **eta** ratio of indices of refraction ( η )
| *[out]* **dest** destination: refraction result

View File

@@ -60,6 +60,8 @@ Functions:
#. :c:func:`glm_vec4_lerp` #. :c:func:`glm_vec4_lerp`
#. :c:func:`glm_vec4_cubic` #. :c:func:`glm_vec4_cubic`
#. :c:func:`glm_vec4_make` #. :c:func:`glm_vec4_make`
#. :c:func:`glm_vec4_reflect`
#. :c:func:`glm_vec4_refract`
Functions documentation Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
@@ -424,3 +426,29 @@ Functions documentation
Parameters: Parameters:
| *[in]* **src** pointer to an array of floats | *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec4_reflect(vec4 I, vec4 N, vec4 dest)
Reflection vector using an incident ray and a surface normal
Parameters:
| *[in]* **I** incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector
| *[out]* **dest** destination: reflection result
.. c:function:: void glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest)
Refraction vector using entering ray, surface normal and refraction index
If the angle between the entering ray I and the surface normal N is too
great for a given refraction index, the return value is zero
this implementation does not explicitly preserve the 'w' component of the
incident vector 'I' in the output 'dest', users requiring the preservation of
the 'w' component should manually adjust 'dest' after calling this function.
Parameters:
| *[in]* **I** *❗️ normalized ❗️* incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector
| *[in]* **eta** ratio of indices of refraction ( η )
| *[out]* **dest** destination: refraction result

View File

@@ -82,6 +82,13 @@ glm_ray_triangle(vec3 origin,
/*! /*!
* @brief ray sphere intersection * @brief ray sphere intersection
* *
* - t1 > 0, t2 > 0: ray intersects the sphere at t1 and t2 both ahead of the origin
* - t1 < 0, t2 > 0: ray starts inside the sphere, exits at t2
* - t1 < 0, t2 < 0: no intersection ahead of the ray
* - the caller can check if the intersection points (t1 and t2) fall within a
* specific range (for example, tmin < t1, t2 < tmax) to determine if the
* intersections are within a desired segment of the ray
*
* @param[in] origin ray origin * @param[in] origin ray origin
* @param[out] dir normalized ray direction * @param[out] dir normalized ray direction
* @param[in] s sphere [center.x, center.y, center.z, radii] * @param[in] s sphere [center.x, center.y, center.z, radii]

View File

@@ -1210,10 +1210,10 @@ glm_vec3_make(const float * __restrict src, vec3 dest) {
* *
* orients a vector to point away from a surface as defined by its normal * orients a vector to point away from a surface as defined by its normal
* *
* @param[in] N vector to orient. * @param[in] N vector to orient
* @param[in] I incident vector * @param[in] I incident vector
* @param[in] Nref reference vector * @param[in] Nref reference vector
* @param[out] dest oriented vector, pointing away from the surface. * @param[out] dest oriented vector, pointing away from the surface
*/ */
CGLM_INLINE CGLM_INLINE
void void