Physics.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /// Physics example.
  11. /// This sample demonstrates:
  12. /// - Creating both static and moving physics objects to a scene
  13. /// - Displaying physics debug geometry
  14. /// - Using the Skybox component for setting up an unmoving sky
  15. /// - Saving a scene to a file and loading it to restore a previous state
  16. class Physics : public Sample
  17. {
  18. URHO3D_OBJECT(Physics, Sample);
  19. public:
  20. /// Construct.
  21. explicit Physics(Context* context);
  22. /// Setup after engine initialization and before running the main loop.
  23. void Start() override;
  24. protected:
  25. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  26. String GetScreenJoystickPatchString() const override { return
  27. "<patch>"
  28. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  29. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Spawn</replace>"
  30. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  31. " <element type=\"Text\">"
  32. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />"
  33. " <attribute name=\"Text\" value=\"LEFT\" />"
  34. " </element>"
  35. " </add>"
  36. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  37. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>"
  38. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  39. " <element type=\"Text\">"
  40. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  41. " <attribute name=\"Text\" value=\"SPACE\" />"
  42. " </element>"
  43. " </add>"
  44. "</patch>";
  45. }
  46. private:
  47. /// Construct the scene content.
  48. void CreateScene();
  49. /// Construct an instruction text to the UI.
  50. void CreateInstructions();
  51. /// Set up a viewport for displaying the scene.
  52. void SetupViewport();
  53. /// Subscribe to application-wide logic update and post-render update events.
  54. void SubscribeToEvents();
  55. /// Read input and moves the camera.
  56. void MoveCamera(float timeStep);
  57. /// Spawn a physics object from the camera position.
  58. void SpawnObject();
  59. /// Handle the logic update event.
  60. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  61. /// Handle the post-render update event.
  62. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  63. /// Flag for drawing debug geometry.
  64. bool drawDebug_;
  65. };