Viewport.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "Object.h"
  24. #include "Ptr.h"
  25. #include "Ray.h"
  26. #include "Rect.h"
  27. #include "Vector2.h"
  28. namespace Urho3D
  29. {
  30. class Camera;
  31. class RenderPath;
  32. class Scene;
  33. class XMLFile;
  34. /// %Viewport definition either for a render surface or the backbuffer.
  35. class URHO3D_API Viewport : public Object
  36. {
  37. OBJECT(Viewport);
  38. public:
  39. /// Construct with defaults.
  40. Viewport(Context* context);
  41. /// Construct with a full rectangle.
  42. Viewport(Context* context, Scene* scene, Camera* camera, RenderPath* renderPath = 0);
  43. /// Construct with a specified rectangle.
  44. Viewport(Context* context, Scene* scene, Camera* camera, const IntRect& rect, RenderPath* renderPath = 0);
  45. /// Destruct.
  46. ~Viewport();
  47. /// Set scene.
  48. void SetScene(Scene* scene);
  49. /// Set camera.
  50. void SetCamera(Camera* camera);
  51. /// Set rectangle.
  52. void SetRect(const IntRect& rect);
  53. /// Set rendering path.
  54. void SetRenderPath(RenderPath* path);
  55. /// Set rendering path from an XML file.
  56. void SetRenderPath(XMLFile* file);
  57. /// Return scene.
  58. Scene* GetScene() const;
  59. /// Return camera.
  60. Camera* GetCamera() const;
  61. /// Return rectangle.
  62. const IntRect& GetRect() const { return rect_; }
  63. /// Return rendering path.
  64. RenderPath* GetRenderPath() const;
  65. /// Return ray corresponding to normalized screen coordinates.
  66. Ray GetScreenRay(int x, int y) const;
  67. // Convert a world space point to normalized screen coordinates.
  68. IntVector2 WorldToScreenPoint(const Vector3& worldPos) const;
  69. // Convert screen coordinates and depth to a world space point.
  70. Vector3 ScreenToWorldPoint(int x, int y, float depth) const;
  71. private:
  72. /// Scene pointer.
  73. WeakPtr<Scene> scene_;
  74. /// Camera pointer.
  75. WeakPtr<Camera> camera_;
  76. /// Viewport rectangle.
  77. IntRect rect_;
  78. /// Rendering path.
  79. SharedPtr<RenderPath> renderPath_;
  80. };
  81. }