CollisionBox2D.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 box collision component.
  8. class URHO3D_API CollisionBox2D : public CollisionShape2D
  9. {
  10. URHO3D_OBJECT(CollisionBox2D, CollisionShape2D);
  11. public:
  12. /// Construct.
  13. explicit CollisionBox2D(Context* context);
  14. /// Destruct.
  15. ~CollisionBox2D() override;
  16. /// Register object factory.
  17. /// @nobind
  18. static void RegisterObject(Context* context);
  19. /// Set size.
  20. /// @property
  21. void SetSize(const Vector2& size);
  22. /// Set size.
  23. void SetSize(float width, float height);
  24. /// Set center.
  25. /// @property
  26. void SetCenter(const Vector2& center);
  27. /// Set center.
  28. void SetCenter(float x, float y);
  29. /// Set angle.
  30. /// @property
  31. void SetAngle(float angle);
  32. /// Return size.
  33. /// @property
  34. const Vector2& GetSize() const { return size_; }
  35. /// Return center.
  36. /// @property
  37. const Vector2& GetCenter() const { return center_; }
  38. /// Return angle.
  39. /// @property
  40. float GetAngle() const { return angle_; }
  41. private:
  42. /// Apply node world scale.
  43. void ApplyNodeWorldScale() override;
  44. /// Recreate fixture.
  45. void RecreateFixture();
  46. /// Box shape.
  47. b2PolygonShape boxShape_;
  48. /// Size.
  49. Vector2 size_;
  50. /// Center.
  51. Vector2 center_;
  52. /// Angle.
  53. float angle_;
  54. };
  55. }