plane.h 786 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c), Recep Aslantas.
  3. *
  4. * MIT License (MIT), http://opensource.org/licenses/MIT
  5. * Full license can be found in the LICENSE file
  6. */
  7. #ifndef cglm_plane_h
  8. #define cglm_plane_h
  9. #include "common.h"
  10. #include "vec3.h"
  11. #include "vec4.h"
  12. /*
  13. Plane equation: Ax + By + Cz + D = 0;
  14. It stored in vec4 as [A, B, C, D]. (A, B, C) is normal and D is distance
  15. */
  16. /*
  17. Functions:
  18. CGLM_INLINE void glm_plane_normalize(vec4 plane);
  19. */
  20. /*!
  21. * @brief normalizes a plane
  22. *
  23. * @param[in, out] plane plane to normalize
  24. */
  25. CGLM_INLINE
  26. void
  27. glm_plane_normalize(vec4 plane) {
  28. float norm;
  29. if (CGLM_UNLIKELY((norm = glm_vec3_norm(plane)) < FLT_EPSILON)) {
  30. glm_vec4_zero(plane);
  31. return;
  32. }
  33. glm_vec4_scale(plane, 1.0f / norm, plane);
  34. }
  35. #endif /* cglm_plane_h */