IceLSS.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. /**
  3. * Contains code for line-swept spheres.
  4. * \file IceLSS.h
  5. * \author Pierre Terdiman
  6. * \date April, 4, 2000
  7. */
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. // Include Guard
  11. #ifndef __ICELSS_H__
  12. #define __ICELSS_H__
  13. class ICEMATHS_API LSS : public Segment
  14. {
  15. public:
  16. //! Constructor
  17. inline_ LSS() {}
  18. //! Constructor
  19. inline_ LSS(const Segment& seg, float radius) : Segment(seg), mRadius(radius) {}
  20. //! Destructor
  21. inline_ ~LSS() {}
  22. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  23. /**
  24. * Computes an OBB surrounding the LSS.
  25. * \param box [out] the OBB
  26. */
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  28. void ComputeOBB(OBB& box);
  29. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30. /**
  31. * Tests if a point is contained within the LSS.
  32. * \param pt [in] the point to test
  33. * \return true if inside the LSS
  34. * \warning point and LSS must be in same space
  35. */
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. inline_ bool Contains(const Point& pt) const { return SquareDistance(pt) <= mRadius*mRadius; }
  38. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  39. /**
  40. * Tests if a sphere is contained within the LSS.
  41. * \param sphere [in] the sphere to test
  42. * \return true if inside the LSS
  43. * \warning sphere and LSS must be in same space
  44. */
  45. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  46. inline_ bool Contains(const Sphere& sphere)
  47. {
  48. float d = mRadius - sphere.mRadius;
  49. if(d>=0.0f) return SquareDistance(sphere.mCenter) <= d*d;
  50. else return false;
  51. }
  52. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  53. /**
  54. * Tests if an LSS is contained within the LSS.
  55. * \param lss [in] the LSS to test
  56. * \return true if inside the LSS
  57. * \warning both LSS must be in same space
  58. */
  59. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60. inline_ bool Contains(const LSS& lss)
  61. {
  62. // We check the LSS contains the two spheres at the start and end of the sweep
  63. return Contains(Sphere(lss.mP0, lss.mRadius)) && Contains(Sphere(lss.mP0, lss.mRadius));
  64. }
  65. float mRadius; //!< Sphere radius
  66. };
  67. #endif // __ICELSS_H__