bounds.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef BOUNDS_H_HEADER_GUARD
  6. #define BOUNDS_H_HEADER_GUARD
  7. struct Aabb
  8. {
  9. float m_min[3];
  10. float m_max[3];
  11. };
  12. struct Obb
  13. {
  14. float m_mtx[16];
  15. };
  16. struct Sphere
  17. {
  18. float m_center[3];
  19. float m_radius;
  20. };
  21. /// Convert axis aligned bounding box to oriented bounding box.
  22. void aabbToObb(Obb& _obb, const Aabb& _aabb);
  23. /// Convert sphere to axis aligned bounding box.
  24. void sphereToAabb(Aabb& _aabb, const Sphere& _sphere);
  25. /// Calculate surface area of axis aligned bounding box.
  26. float calcAabbArea(Aabb& _aabb);
  27. /// Calculate axis aligned bounding box.
  28. void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
  29. /// Transform vertices and calculate axis aligned bounding box.
  30. void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
  31. /// Expand AABB.
  32. void aabbExpand(Aabb& _aabb, float _factor);
  33. /// Returns 0 is two AABB don't overlap, otherwise returns flags of overlap
  34. /// test.
  35. uint32_t aabbOverlapTest(Aabb& _aabb0, Aabb& _aabb1);
  36. /// Calculate oriented bounding box.
  37. void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps = 17);
  38. /// Calculate maximum bounding sphere.
  39. void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
  40. /// Calculate minimum bounding sphere.
  41. void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride, float _step = 0.01f);
  42. #endif // BOUNDS_H_HEADER_GUARD