NavArea.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../Core/Context.h"
  24. #include "../Graphics/DebugRenderer.h"
  25. #include "../IO/Log.h"
  26. #include "../Navigation/NavArea.h"
  27. #include "../Scene/Node.h"
  28. namespace Atomic
  29. {
  30. static const unsigned MAX_NAV_AREA_ID = 255;
  31. static const Vector3 DEFAULT_BOUNDING_BOX_MIN(-10.0f, -10.0f, -10.0f);
  32. static const Vector3 DEFAULT_BOUNDING_BOX_MAX(10.0f, 10.0f, 10.0f);
  33. static const unsigned DEFAULT_AREA_ID = 0;
  34. extern const char* NAVIGATION_CATEGORY;
  35. NavArea::NavArea(Context* context) :
  36. Component(context),
  37. areaID_(DEFAULT_AREA_ID),
  38. boundingBox_(DEFAULT_BOUNDING_BOX_MIN, DEFAULT_BOUNDING_BOX_MAX)
  39. {
  40. }
  41. NavArea::~NavArea()
  42. {
  43. }
  44. void NavArea::RegisterObject(Context* context)
  45. {
  46. context->RegisterFactory<NavArea>(NAVIGATION_CATEGORY);
  47. ATOMIC_COPY_BASE_ATTRIBUTES(Component);
  48. ATOMIC_ATTRIBUTE("Bounding Box Min", Vector3, boundingBox_.min_, DEFAULT_BOUNDING_BOX_MIN, AM_DEFAULT);
  49. ATOMIC_ATTRIBUTE("Bounding Box Max", Vector3, boundingBox_.max_, DEFAULT_BOUNDING_BOX_MAX, AM_DEFAULT);
  50. ATOMIC_ACCESSOR_ATTRIBUTE("Area ID", GetAreaID, SetAreaID, unsigned, DEFAULT_AREA_ID, AM_DEFAULT);
  51. }
  52. void NavArea::SetAreaID(unsigned newID)
  53. {
  54. if (newID > MAX_NAV_AREA_ID)
  55. ATOMIC_LOGERRORF("NavArea Area ID %u exceeds maximum value of %u", newID, MAX_NAV_AREA_ID);
  56. areaID_ = (unsigned char)newID;
  57. MarkNetworkUpdate();
  58. }
  59. BoundingBox NavArea::GetWorldBoundingBox() const
  60. {
  61. Matrix3x4 mat;
  62. mat.SetTranslation(node_->GetWorldPosition());
  63. return boundingBox_.Transformed(mat);
  64. }
  65. void NavArea::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
  66. {
  67. if (debug && IsEnabledEffective())
  68. {
  69. Matrix3x4 mat;
  70. mat.SetTranslation(node_->GetWorldPosition());
  71. debug->AddBoundingBox(boundingBox_, mat, Color::GREEN, depthTest);
  72. debug->AddBoundingBox(boundingBox_, mat, Color(0.0f, 1.0f, 0.0f, 0.15f), true, true);
  73. }
  74. }
  75. }