ray.rst 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. .. default-domain:: C
  2. ray
  3. ====
  4. Header: cglm/ray.h
  5. This is for collision-checks used by ray-tracers and the like.
  6. Table of contents (click to go):
  7. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. Functions:
  9. 1. :c:func:`glm_ray_triangle`
  10. #. :c:func:`glm_ray_sphere`
  11. #. :c:func:`glm_ray_at`
  12. Functions documentation
  13. ~~~~~~~~~~~~~~~~~~~~~~~
  14. .. c:function:: bool glm_ray_triangle(vec3 origin, vec3 direction, vec3 v0, vec3 v1, vec3 v2, float *d)
  15. Möller–Trumbore ray-triangle intersection algorithm
  16. Parameters:
  17. | *[in]* **origin** origin of ray
  18. | *[in]* **direction** direction of ray
  19. | *[in]* **v0** first vertex of triangle
  20. | *[in]* **v1** second vertex of triangle
  21. | *[in]* **v2** third vertex of triangle
  22. | *[in, out]* **d** float pointer to save distance to intersection
  23. | *[out]* **intersection** whether there is intersection
  24. .. c:function:: bool glm_ray_sphere(vec3 origin, vec3 dir, vec4 s, float * __restrict t1, float * __restrict t2)
  25. ray sphere intersection
  26. returns false if there is no intersection if true:
  27. - t1 > 0, t2 > 0: ray intersects the sphere at t1 and t2 both ahead of the origin
  28. - t1 < 0, t2 > 0: ray starts inside the sphere, exits at t2
  29. - t1 < 0, t2 < 0: no intersection ahead of the ray ( returns false )
  30. - the caller can check if the intersection points (t1 and t2) fall within a
  31. specific range (for example, tmin < t1, t2 < tmax) to determine if the
  32. intersections are within a desired segment of the ray
  33. Parameters:
  34. | *[in]* **origin** ray origin
  35. | *[in]* **dir** normalized ray direction
  36. | *[in]* **s** sphere [center.x, center.y, center.z, radii]
  37. | *[out]* **t1** near point1 (closer to origin)
  38. | *[out]* **t2** far point2 (farther from origin)
  39. Return:
  40. | whether there is intersection
  41. .. c:function:: bool glm_ray_at(vec3 orig, vec3 dir, float t, vec3 point)
  42. point using t by 𝐏(𝑡)=𝐀+𝑡𝐛
  43. Parameters:
  44. | *[in]* **origin** ray origin
  45. | *[in]* **dir** ray direction
  46. | *[out]* **t** parameter
  47. | *[out]* **point** point at t
  48. Return:
  49. | point at t