Sample.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "Application.h"
  24. namespace Urho3D
  25. {
  26. class Node;
  27. class Scene;
  28. class Sprite;
  29. }
  30. // All Urho3D classes reside in namespace Urho3D
  31. using namespace Urho3D;
  32. /// Sample class, as framework for all samples.
  33. /// - Initialization of the Urho3D engine (in Application class)
  34. /// - Modify engine parameters for windowed mode and to show the class name as title
  35. /// - Create Urho3D logo at screen
  36. /// - Set custom window title and icon
  37. /// - Create Console and Debug HUD, and use F1 and F2 key to toggle them
  38. /// - Toggle rendering options from the keys 1-8
  39. /// - Take screenshot with key 9
  40. /// - Handle Esc key down to hide Console or exit application
  41. /// - Init touch input on mobile platform using screen joystick
  42. class Sample : public Application
  43. {
  44. // Enable type information.
  45. OBJECT(Sample);
  46. public:
  47. /// Construct.
  48. Sample(Context* context);
  49. /// Setup before engine initialization. Modifies the engine parameters.
  50. virtual void Setup();
  51. /// Setup after engine initialization. Creates the logo, console & debug HUD.
  52. virtual void Start();
  53. /// Initialize touch input on mobile platform.
  54. void InitTouchInput();
  55. /// Control logo visibility.
  56. void SetLogoVisible(bool enable);
  57. protected:
  58. /// Logo sprite.
  59. SharedPtr<Sprite> logoSprite_;
  60. /// Scene.
  61. SharedPtr<Scene> scene_;
  62. /// Camera scene node.
  63. SharedPtr<Node> cameraNode_;
  64. /// Camera yaw angle.
  65. float yaw_;
  66. /// Camera pitch angle.
  67. float pitch_;
  68. private:
  69. /// Create logo.
  70. void CreateLogo();
  71. /// Set custom window Title & Icon
  72. void SetWindowTitleAndIcon();
  73. /// Create console and debug HUD.
  74. void CreateConsoleAndDebugHud();
  75. /// Handle key down event to process key controls common to all samples.
  76. void HandleKeyDown(StringHash eventType, VariantMap& eventData);
  77. /// Handle scene update event to control camera's pitch and yaw for all samples.
  78. void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
  79. /// Flag to indicate whether touch input has been enabled.
  80. bool touchEnabled_;
  81. /// Screen joystick index for navigational controls (mobile platforms only).
  82. unsigned screenJoystickIndex_;
  83. /// Screen joystick index for settings (mobile platforms only).
  84. unsigned screenJoystickSettingsIndex_;
  85. /// Pause flag.
  86. bool paused_;
  87. };
  88. #include "Sample.inl"