Urho2DConstraints.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "Sample.h"
  5. namespace Urho3D
  6. {
  7. class Node;
  8. class Scene;
  9. class ConstraintDistance2D;
  10. class ConstraintFriction2D;
  11. class ConstraintGear2D;
  12. class ConstraintMotor2D;
  13. class ConstraintMouse2D;
  14. class ConstraintPrismatic2D;
  15. class ConstraintPulley2D;
  16. class ConstraintRevolute2D;
  17. class ConstraintRope2D;
  18. class ConstraintWeld2D;
  19. class ConstraintWheel2D;
  20. }
  21. /// Physics2D constraints sample.
  22. /// This sample is designed to help understanding and chosing the right constraint.
  23. /// This sample demonstrates:
  24. /// - Creating physics constraints
  25. /// - Creating Edge and Polygon Shapes from vertices
  26. /// - Displaying physics debug geometry and constraints' joints
  27. /// - Using SetOrderInLayer to alter the way sprites are drawn in relation to each other
  28. /// - Using Text3D to display some text affected by zoom
  29. /// - Setting the background color for the scene
  30. class Urho2DConstraints : public Sample
  31. {
  32. URHO3D_OBJECT(Urho2DConstraints, Sample);
  33. public:
  34. /// Construct.
  35. explicit Urho2DConstraints(Context* context);
  36. /// Setup after engine initialization and before running the main loop.
  37. void Start() override;
  38. protected:
  39. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  40. String GetScreenJoystickPatchString() const override { return
  41. "<patch>"
  42. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  43. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Zoom In</replace>"
  44. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  45. " <element type=\"Text\">"
  46. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  47. " <attribute name=\"Text\" value=\"PAGEUP\" />"
  48. " </element>"
  49. " </add>"
  50. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  51. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Zoom Out</replace>"
  52. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  53. " <element type=\"Text\">"
  54. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  55. " <attribute name=\"Text\" value=\"PAGEDOWN\" />"
  56. " </element>"
  57. " </add>"
  58. "</patch>";
  59. }
  60. private:
  61. /// Construct the scene content.
  62. void CreateScene();
  63. /// Construct an instruction text to the UI.
  64. void CreateInstructions();
  65. /// Create Tex3D flag.
  66. void CreateFlag(const String& text, float x, float y);
  67. /// Read input and moves the camera.
  68. void MoveCamera(float timeStep);
  69. /// Subscribe to application-wide logic update events.
  70. void SubscribeToEvents();
  71. /// Handle the logic update event.
  72. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  73. /// Handle the post render update event during which we request debug geometry.
  74. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  75. /// Handle the mouse click event.
  76. void HandleMouseButtonDown(StringHash eventType, VariantMap& eventData);
  77. /// Handle the mouse button up event.
  78. void HandleMouseButtonUp(StringHash eventType, VariantMap& eventData);
  79. /// Handle the mouse move event.
  80. void HandleMouseMove(StringHash eventType, VariantMap& eventData);
  81. /// Handle the touch begin event.
  82. void HandleTouchBegin3(StringHash eventType, VariantMap& eventData);
  83. /// Handle the touch move event.
  84. void HandleTouchMove3(StringHash eventType, VariantMap& eventData);
  85. /// Handle the touch end event.
  86. void HandleTouchEnd3(StringHash eventType, VariantMap& eventData);
  87. /// Get mouse position in 2D world coordinates.
  88. Vector2 GetMousePositionXY();
  89. /// Flag for drawing debug geometry.
  90. bool drawDebug_{};
  91. /// Camera object.
  92. Camera* camera_{};
  93. };