Water.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include <Urho3D/Math/Plane.h>
  5. #include "Sample.h"
  6. namespace Urho3D
  7. {
  8. class Node;
  9. class Scene;
  10. }
  11. /// Water example.
  12. /// This sample demonstrates:
  13. /// - Creating a large plane to represent a water body for rendering
  14. /// - Setting up a second camera to render reflections on the water surface
  15. class Water : public Sample
  16. {
  17. URHO3D_OBJECT(Water, Sample);
  18. public:
  19. /// Construct.
  20. explicit Water(Context* context);
  21. /// Setup after engine initialization and before running the main loop.
  22. void Start() override;
  23. private:
  24. /// Construct the scene content.
  25. void CreateScene();
  26. /// Construct an instruction text to the UI.
  27. void CreateInstructions();
  28. /// Set up a viewport for displaying the scene.
  29. void SetupViewport();
  30. /// Subscribe to the logic update event.
  31. void SubscribeToEvents();
  32. /// Read input and moves the camera.
  33. void MoveCamera(float timeStep);
  34. /// Handle the logic update event.
  35. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  36. /// Reflection camera scene node.
  37. SharedPtr<Node> reflectionCameraNode_;
  38. /// Water body scene node.
  39. SharedPtr<Node> waterNode_;
  40. /// Reflection plane representing the water surface.
  41. Plane waterPlane_;
  42. /// Clipping plane for reflection rendering. Slightly biased downward from the reflection plane to avoid artifacts.
  43. Plane waterClipPlane_;
  44. };