Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: An axis aligned bounding box class.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BOUNDBOX_H
  8. #define BOUNDBOX_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "mathlib/vector.h"
  13. #define COORD_NOTINIT ((float)(99999.0))
  14. enum
  15. {
  16. AXIS_X = 0,
  17. AXIS_Y,
  18. AXIS_Z
  19. };
  20. class BoundBox
  21. {
  22. public:
  23. BoundBox(void);
  24. BoundBox(const Vector &mins, const Vector &maxs);
  25. void ResetBounds(void);
  26. inline void SetBounds(const Vector &mins, const Vector &maxs);
  27. void UpdateBounds(const Vector& bmins, const Vector& bmaxs);
  28. void UpdateBounds(const Vector& pt);
  29. void UpdateBounds(const BoundBox *pBox);
  30. void GetBoundsCenter(Vector& ptdest);
  31. inline void GetBounds(Vector& Mins, Vector& Maxs);
  32. virtual bool IsIntersectingBox(const Vector& pfMins, const Vector& pfMaxs) const;
  33. bool IsInsideBox(const Vector& pfMins, const Vector& pfMaxs) const;
  34. bool ContainsPoint(const Vector& pt) const;
  35. bool IsValidBox(void) const;
  36. void GetBoundsSize(Vector& size);
  37. void SnapToGrid(int iGridSize);
  38. void Rotate90(int axis);
  39. Vector bmins;
  40. Vector bmaxs;
  41. };
  42. //-----------------------------------------------------------------------------
  43. // Purpose: Gets the bounding box as two vectors, a min and a max.
  44. // Input : Mins - Receives the box's minima.
  45. // Maxs - Receives the box's maxima.
  46. //-----------------------------------------------------------------------------
  47. void BoundBox::GetBounds(Vector &Mins, Vector &Maxs)
  48. {
  49. Mins = bmins;
  50. Maxs = bmaxs;
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose: Sets the box outright, equivalent to ResetBounds + UpdateBounds.
  54. // Input : mins - Minima to set.
  55. // maxs - Maxima to set.
  56. //-----------------------------------------------------------------------------
  57. void BoundBox::SetBounds(const Vector &mins, const Vector &maxs)
  58. {
  59. bmins = mins;
  60. bmaxs = maxs;
  61. }
  62. #endif // BOUNDBOX_H