NavArea.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // Copyright (c) 2008-2015 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 "../Scene/Component.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. #include "../Container/Str.h"
  29. namespace Atomic
  30. {
  31. static const unsigned MAX_NAV_AREA_ID = 255;
  32. static const Vector3 DEFAULT_BOUNDING_BOX_MIN(-10.0f, -10.0f, -10.0f);
  33. static const Vector3 DEFAULT_BOUNDING_BOX_MAX(10.0f, 10.0f, 10.0f);
  34. static const unsigned DEFAULT_MASK_FLAG = 0;
  35. static const unsigned DEFAULT_AREA_ID = 0;
  36. extern const char* NAVIGATION_CATEGORY;
  37. NavArea::NavArea(Context* context) :
  38. Component(context),
  39. areaID_(DEFAULT_AREA_ID),
  40. boundingBox_(DEFAULT_BOUNDING_BOX_MIN, DEFAULT_BOUNDING_BOX_MAX)
  41. {
  42. }
  43. NavArea::~NavArea()
  44. {
  45. }
  46. void NavArea::RegisterObject(Context* context)
  47. {
  48. context->RegisterFactory<NavArea>(NAVIGATION_CATEGORY);
  49. COPY_BASE_ATTRIBUTES(Component);
  50. ATTRIBUTE("Bounding Box Min", Vector3, boundingBox_.min_, DEFAULT_BOUNDING_BOX_MIN, AM_DEFAULT);
  51. ATTRIBUTE("Bounding Box Max", Vector3, boundingBox_.max_, DEFAULT_BOUNDING_BOX_MAX, AM_DEFAULT);
  52. ACCESSOR_ATTRIBUTE("Area ID", GetAreaID, SetAreaID, unsigned, DEFAULT_AREA_ID, AM_DEFAULT);
  53. }
  54. void NavArea::SetAreaID(unsigned newID)
  55. {
  56. if (newID > MAX_NAV_AREA_ID)
  57. LOGERRORF("NavArea Area ID %u exceeds maximum value of %u", newID, MAX_NAV_AREA_ID);
  58. areaID_ = (unsigned char)newID;
  59. MarkNetworkUpdate();
  60. }
  61. BoundingBox NavArea::GetWorldBoundingBox() const
  62. {
  63. Matrix3x4 mat;
  64. mat.SetTranslation(node_->GetWorldPosition());
  65. return boundingBox_.Transformed(mat);
  66. }
  67. void NavArea::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
  68. {
  69. if (debug && IsEnabledEffective())
  70. {
  71. Matrix3x4 mat;
  72. mat.SetTranslation(node_->GetWorldPosition());
  73. debug->AddBoundingBox(boundingBox_, mat, Color::GREEN, depthTest);
  74. }
  75. }
  76. }