NavArea.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #include "../Precompiled.h"
  4. #include "../Core/Context.h"
  5. #include "../Graphics/DebugRenderer.h"
  6. #include "../IO/Log.h"
  7. #include "../Navigation/NavArea.h"
  8. #include "../Scene/Node.h"
  9. namespace Urho3D
  10. {
  11. static const unsigned MAX_NAV_AREA_ID = 255;
  12. static const Vector3 DEFAULT_BOUNDING_BOX_MIN(-10.0f, -10.0f, -10.0f);
  13. static const Vector3 DEFAULT_BOUNDING_BOX_MAX(10.0f, 10.0f, 10.0f);
  14. static const unsigned DEFAULT_AREA_ID = 0;
  15. extern const char* NAVIGATION_CATEGORY;
  16. NavArea::NavArea(Context* context) :
  17. Component(context),
  18. areaID_(DEFAULT_AREA_ID),
  19. boundingBox_(DEFAULT_BOUNDING_BOX_MIN, DEFAULT_BOUNDING_BOX_MAX)
  20. {
  21. }
  22. NavArea::~NavArea() = default;
  23. void NavArea::RegisterObject(Context* context)
  24. {
  25. context->RegisterFactory<NavArea>(NAVIGATION_CATEGORY);
  26. URHO3D_COPY_BASE_ATTRIBUTES(Component);
  27. URHO3D_ATTRIBUTE("Bounding Box Min", boundingBox_.min_, DEFAULT_BOUNDING_BOX_MIN, AM_DEFAULT);
  28. URHO3D_ATTRIBUTE("Bounding Box Max", boundingBox_.max_, DEFAULT_BOUNDING_BOX_MAX, AM_DEFAULT);
  29. URHO3D_ACCESSOR_ATTRIBUTE("Area ID", GetAreaID, SetAreaID, DEFAULT_AREA_ID, AM_DEFAULT);
  30. }
  31. void NavArea::SetAreaID(unsigned newID)
  32. {
  33. if (newID > MAX_NAV_AREA_ID)
  34. URHO3D_LOGERRORF("NavArea Area ID %u exceeds maximum value of %u", newID, MAX_NAV_AREA_ID);
  35. areaID_ = (unsigned char)newID;
  36. MarkNetworkUpdate();
  37. }
  38. BoundingBox NavArea::GetWorldBoundingBox() const
  39. {
  40. Matrix3x4 mat;
  41. mat.SetTranslation(node_->GetWorldPosition());
  42. return boundingBox_.Transformed(mat);
  43. }
  44. void NavArea::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
  45. {
  46. if (debug && IsEnabledEffective())
  47. {
  48. Matrix3x4 mat;
  49. mat.SetTranslation(node_->GetWorldPosition());
  50. debug->AddBoundingBox(boundingBox_, mat, Color::GREEN, depthTest);
  51. debug->AddBoundingBox(boundingBox_, mat, Color(0.0f, 1.0f, 0.0f, 0.15f), true, true);
  52. }
  53. }
  54. }