/indra/llmath/llbbox.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 101 lines · 46 code · 22 blank · 33 comment · 0 complexity · 11e0965d6f4c128dd7d94097a771d2a6 MD5 · raw file

  1. /**
  2. * @file llbbox.h
  3. * @brief General purpose bounding box class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_BBOX_H
  27. #define LL_BBOX_H
  28. #include "v3math.h"
  29. #include "llquaternion.h"
  30. // Note: "local space" for an LLBBox is defined relative to agent space in terms of
  31. // a translation followed by a rotation. There is no scale term since the LLBBox's min and
  32. // max are not necessarily symetrical and define their own extents.
  33. class LLBBox
  34. {
  35. public:
  36. LLBBox() {mEmpty = TRUE;}
  37. LLBBox( const LLVector3& pos_agent,
  38. const LLQuaternion& rot,
  39. const LLVector3& min_local,
  40. const LLVector3& max_local )
  41. :
  42. mMinLocal( min_local ), mMaxLocal( max_local ), mPosAgent(pos_agent), mRotation( rot), mEmpty( TRUE )
  43. {}
  44. // Default copy constructor is OK.
  45. const LLVector3& getPositionAgent() const { return mPosAgent; }
  46. const LLQuaternion& getRotation() const { return mRotation; }
  47. LLVector3 getMinAgent() const;
  48. const LLVector3& getMinLocal() const { return mMinLocal; }
  49. void setMinLocal( const LLVector3& min ) { mMinLocal = min; }
  50. LLVector3 getMaxAgent() const;
  51. const LLVector3& getMaxLocal() const { return mMaxLocal; }
  52. void setMaxLocal( const LLVector3& max ) { mMaxLocal = max; }
  53. LLVector3 getCenterLocal() const { return (mMaxLocal - mMinLocal) * 0.5f + mMinLocal; }
  54. LLVector3 getCenterAgent() const { return localToAgent( getCenterLocal() ); }
  55. LLVector3 getExtentLocal() const { return mMaxLocal - mMinLocal; }
  56. BOOL containsPointLocal(const LLVector3& p) const;
  57. BOOL containsPointAgent(const LLVector3& p) const;
  58. void addPointAgent(LLVector3 p);
  59. void addBBoxAgent(const LLBBox& b);
  60. void addPointLocal(const LLVector3& p);
  61. void addBBoxLocal(const LLBBox& b) { addPointLocal( b.mMinLocal ); addPointLocal( b.mMaxLocal ); }
  62. void expand( F32 delta );
  63. LLVector3 localToAgent( const LLVector3& v ) const;
  64. LLVector3 agentToLocal( const LLVector3& v ) const;
  65. // Changes rotation but not position
  66. LLVector3 localToAgentBasis(const LLVector3& v) const;
  67. LLVector3 agentToLocalBasis(const LLVector3& v) const;
  68. // Get the smallest possible axis aligned bbox that contains this bbox
  69. LLBBox getAxisAligned() const;
  70. // friend LLBBox operator*(const LLBBox& a, const LLMatrix4& b);
  71. private:
  72. LLVector3 mMinLocal;
  73. LLVector3 mMaxLocal;
  74. LLVector3 mPosAgent; // Position relative to Agent's Region
  75. LLQuaternion mRotation;
  76. BOOL mEmpty; // Nothing has been added to this bbox yet
  77. };
  78. //LLBBox operator*(const LLBBox &a, const LLMatrix4 &b);
  79. #endif // LL_BBOX_H