Constraints2D.h 3.9 KB

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