CollisionChain2D.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Physics2D/CollisionShape2D.h"
  5. namespace Urho3D
  6. {
  7. /// 2D chain collision component.
  8. class URHO3D_API CollisionChain2D : public CollisionShape2D
  9. {
  10. URHO3D_OBJECT(CollisionChain2D, CollisionShape2D);
  11. public:
  12. /// Construct.
  13. explicit CollisionChain2D(Context* context);
  14. /// Destruct.
  15. ~CollisionChain2D() override;
  16. /// Register object factory.
  17. /// @nobind
  18. static void RegisterObject(Context* context);
  19. /// Set loop.
  20. /// @property
  21. void SetLoop(bool loop);
  22. /// Return loop.
  23. /// @property
  24. bool GetLoop() const { return loop_; }
  25. /// Set vertex count.
  26. /// @property
  27. void SetVertexCount(i32 count);
  28. /// Return vertex count.
  29. /// @property
  30. i32 GetVertexCount() const { return vertices_.Size(); }
  31. /// Set vertex.
  32. void SetVertex(i32 index, const Vector2& vertex);
  33. /// Return vertex.
  34. const Vector2& GetVertex(i32 index) const
  35. {
  36. assert(index >= 0);
  37. return (index < vertices_.Size()) ? vertices_[index] : Vector2::ZERO;
  38. }
  39. /// Set vertices. For non loop first and last must be ghost.
  40. void SetVertices(const Vector<Vector2>& vertices);
  41. /// Return vertices.
  42. const Vector<Vector2>& GetVertices() const { return vertices_; }
  43. /// Set vertices attribute. For non loop first and last must be ghost.
  44. void SetVerticesAttr(const Vector<byte>& value);
  45. /// Return vertices attribute.
  46. Vector<byte> GetVerticesAttr() const;
  47. private:
  48. /// Apply node world scale.
  49. void ApplyNodeWorldScale() override;
  50. /// Recreate fixture.
  51. void RecreateFixture();
  52. /// Chain shape.
  53. b2ChainShape chainShape_;
  54. /// Loop.
  55. bool loop_;
  56. /// Vertices.
  57. Vector<Vector2> vertices_;
  58. };
  59. }