Decals.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "Sample.h"
  5. namespace Urho3D
  6. {
  7. class Drawable;
  8. class Node;
  9. class Scene;
  10. }
  11. /// Decals example.
  12. /// This sample demonstrates:
  13. /// - Performing a raycast to the octree and adding a decal to the hit location
  14. /// - Defining a Cursor UI element which stays inside the window and can be shown/hidden
  15. /// - Marking suitable (large) objects as occluders for occlusion culling
  16. /// - Displaying renderer debug geometry to see the effect of occlusion
  17. class Decals : public Sample
  18. {
  19. URHO3D_OBJECT(Decals, Sample);
  20. public:
  21. /// Construct.
  22. explicit Decals(Context* context);
  23. /// Setup after engine initialization and before running the main loop.
  24. void Start() override;
  25. protected:
  26. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  27. String GetScreenJoystickPatchString() const override { return
  28. "<patch>"
  29. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  30. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Paint</replace>"
  31. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  32. " <element type=\"Text\">"
  33. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />"
  34. " <attribute name=\"Text\" value=\"LEFT\" />"
  35. " </element>"
  36. " </add>"
  37. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  38. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>"
  39. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  40. " <element type=\"Text\">"
  41. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  42. " <attribute name=\"Text\" value=\"SPACE\" />"
  43. " </element>"
  44. " </add>"
  45. "</patch>";
  46. }
  47. private:
  48. /// Construct the scene content.
  49. void CreateScene();
  50. /// Construct user interface elements.
  51. void CreateUI();
  52. /// Set up a viewport for displaying the scene.
  53. void SetupViewport();
  54. /// Subscribe to application-wide logic update and post-render update events.
  55. void SubscribeToEvents();
  56. /// Reads input and moves the camera.
  57. void MoveCamera(float timeStep);
  58. /// Paint a decal using a ray cast from the mouse cursor.
  59. void PaintDecal();
  60. /// Utility function to raycast to the cursor position. Return true if hit
  61. bool Raycast(float maxDistance, Vector3& hitPos, Drawable*& hitDrawable);
  62. /// Handle the logic update event.
  63. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  64. /// Handle the post-render update event.
  65. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  66. /// Flag for drawing debug geometry.
  67. bool drawDebug_;
  68. };