Urho2DConstraints.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "Sample.h"
  24. namespace Urho3D
  25. {
  26. class Node;
  27. class Scene;
  28. class ConstraintDistance2D;
  29. class ConstraintFriction2D;
  30. class ConstraintGear2D;
  31. class ConstraintMotor2D;
  32. class ConstraintMouse2D;
  33. class ConstraintPrismatic2D;
  34. class ConstraintPulley2D;
  35. class ConstraintRevolute2D;
  36. class ConstraintRope2D;
  37. class ConstraintWeld2D;
  38. class ConstraintWheel2D;
  39. }
  40. /// Urho2D constraints sample.
  41. /// This sample is designed to help understanding and chosing the right constraint.
  42. /// This sample demonstrates:
  43. /// - Creating physics constraints
  44. /// - Creating Edge and Polygon Shapes from vertices
  45. /// - Displaying physics debug geometry and constraints' joints
  46. /// - Using SetOrderInLayer to alter the way sprites are drawn in relation to each other
  47. /// - Using Text3D to display some text affected by zoom
  48. /// - Setting the background color for the scene
  49. class Urho2DConstraints : public Sample
  50. {
  51. OBJECT(Urho2DConstraints);
  52. public:
  53. /// Construct.
  54. Urho2DConstraints(Context* context);
  55. /// Setup after engine initialization and before running the main loop.
  56. virtual void Start();
  57. protected:
  58. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  59. virtual String GetScreenJoystickPatchString() const { return
  60. "<patch>"
  61. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  62. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Zoom In</replace>"
  63. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  64. " <element type=\"Text\">"
  65. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  66. " <attribute name=\"Text\" value=\"PAGEUP\" />"
  67. " </element>"
  68. " </add>"
  69. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  70. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Zoom Out</replace>"
  71. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  72. " <element type=\"Text\">"
  73. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  74. " <attribute name=\"Text\" value=\"PAGEDOWN\" />"
  75. " </element>"
  76. " </add>"
  77. "</patch>";
  78. }
  79. private:
  80. /// Construct the scene content.
  81. void CreateScene();
  82. /// Construct an instruction text to the UI.
  83. void CreateInstructions();
  84. /// Create Tex3D flag.
  85. void CreateFlag(const String& text, float x, float y);
  86. /// Read input and moves the camera.
  87. void MoveCamera(float timeStep);
  88. /// Subscribe to application-wide logic update events.
  89. void SubscribeToEvents();
  90. /// Handle the logic update event.
  91. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  92. /// Handle the post render update event during which we request debug geometry.
  93. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  94. /// Handle the mouse click event.
  95. void HandleMouseButtonDown(StringHash eventType, VariantMap& eventData);
  96. /// Handle the mouse button up event.
  97. void HandleMouseButtonUp(StringHash eventType, VariantMap& eventData);
  98. /// Handle the mouse move event.
  99. void HandleMouseMove(StringHash eventType, VariantMap& eventData);
  100. /// Handle the touch begin event.
  101. void HandleTouchBegin3(StringHash eventType, VariantMap& eventData);
  102. /// Handle the touch move event.
  103. void HandleTouchMove3(StringHash eventType, VariantMap& eventData);
  104. /// Handle the touch end event.
  105. void HandleTouchEnd3(StringHash eventType, VariantMap& eventData);
  106. /// Get mouse position in 2D world coordinates.
  107. Vector2 GetMousePositionXY();
  108. /// Flag for drawing debug geometry.
  109. bool drawDebug_;
  110. /// Camera object.
  111. Camera* camera_;
  112. };