Urho2DPhysics.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. }
  10. /// Urho2D and Physics2D sample.
  11. /// This sample demonstrates:
  12. /// - Creating both static and moving 2D physics objects to a scene
  13. /// - Displaying physics debug geometry
  14. class Urho2DPhysics : public Sample
  15. {
  16. URHO3D_OBJECT(Urho2DPhysics, Sample);
  17. public:
  18. /// Construct.
  19. explicit Urho2DPhysics(Context* context);
  20. /// Setup after engine initialization and before running the main loop.
  21. void Start() override;
  22. protected:
  23. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  24. String GetScreenJoystickPatchString() const override { return
  25. "<patch>"
  26. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  27. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Zoom In</replace>"
  28. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  29. " <element type=\"Text\">"
  30. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  31. " <attribute name=\"Text\" value=\"PAGEUP\" />"
  32. " </element>"
  33. " </add>"
  34. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  35. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Zoom Out</replace>"
  36. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  37. " <element type=\"Text\">"
  38. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  39. " <attribute name=\"Text\" value=\"PAGEDOWN\" />"
  40. " </element>"
  41. " </add>"
  42. "</patch>";
  43. }
  44. private:
  45. /// Construct the scene content.
  46. void CreateScene();
  47. /// Construct an instruction text to the UI.
  48. void CreateInstructions();
  49. /// Set up a viewport for displaying the scene.
  50. void SetupViewport();
  51. /// Read input and moves the camera.
  52. void MoveCamera(float timeStep);
  53. /// Subscribe to application-wide logic update events.
  54. void SubscribeToEvents();
  55. /// Handle the logic update event.
  56. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  57. };