Obstacle.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 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. Obstacle(Context*);
  36. /// Destruct.
  37. virtual ~Obstacle();
  38. /// Register Obstacle with engine context.
  39. static void RegisterObject(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);
  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);
  50. /// Get the internal obstacle ID.
  51. unsigned GetObstacleID() const { return obstacleId_; }
  52. /// Render debug information.
  53. virtual void DrawDebugGeometry(DebugRenderer*, 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. private:
  64. /// Radius of this obstacle.
  65. float radius_;
  66. /// Height of this obstacle, extends 1/2 height below and 1/2 height above the owning node's position.
  67. float height_;
  68. /// Id received from tile cache.
  69. unsigned obstacleId_;
  70. /// Pointer to the navigation mesh we belong to.
  71. WeakPtr<DynamicNavigationMesh> ownerMesh_;
  72. };
  73. }