Obstacle.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // Copyright (c) 2008-2020 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. #pragma once
  23. #include "../Container/Ptr.h"
  24. #include "../Scene/Component.h"
  25. namespace Urho3D
  26. {
  27. class DynamicNavigationMesh;
  28. /// Obstacle for dynamic navigation mesh.
  29. class URHO3D_API Obstacle : public Component
  30. {
  31. URHO3D_OBJECT(Obstacle, Component);
  32. friend class DynamicNavigationMesh;
  33. public:
  34. /// Construct.
  35. explicit Obstacle(Context* context);
  36. /// Destruct.
  37. ~Obstacle() override;
  38. /// Register Obstacle with engine context.
  39. static void RegisterObject(Context* context);
  40. /// Update the owning mesh when enabled status has changed.
  41. void OnSetEnabled() override;
  42. /// Get the height of this obstacle.
  43. /// @property
  44. float GetHeight() const { return height_; }
  45. /// Set the height of this obstacle.
  46. /// @property
  47. void SetHeight(float newHeight);
  48. /// Get the blocking radius of this obstacle.
  49. /// @property
  50. float GetRadius() const { return radius_; }
  51. /// Set the blocking radius of this obstacle.
  52. /// @property
  53. void SetRadius(float newRadius);
  54. /// Get the internal obstacle ID.
  55. /// @property{get_obstacleId}
  56. unsigned GetObstacleID() const { return obstacleId_; }
  57. /// Render debug information.
  58. void DrawDebugGeometry(DebugRenderer* debug, bool depthTest) override;
  59. /// Simplified rendering of debug information for script usage.
  60. void DrawDebugGeometry(bool depthTest);
  61. protected:
  62. /// Handle node being assigned.
  63. void OnNodeSet(Node* node) override;
  64. /// Handle scene being assigned, identify our DynamicNavigationMesh.
  65. void OnSceneSet(Scene* scene) override;
  66. /// Handle node transform being dirtied.
  67. void OnMarkedDirty(Node* node) override;
  68. /// Handle navigation mesh tile added.
  69. void HandleNavigationTileAdded(StringHash eventType, VariantMap& eventData);
  70. private:
  71. /// Radius of this obstacle.
  72. float radius_;
  73. /// Height of this obstacle, extends 1/2 height below and 1/2 height above the owning node's position.
  74. float height_;
  75. /// Id received from tile cache.
  76. unsigned obstacleId_;
  77. /// Pointer to the navigation mesh we belong to.
  78. WeakPtr<DynamicNavigationMesh> ownerMesh_;
  79. };
  80. }