Obstacle.h 3.1 KB

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