Browse Source

Add public accessors for View's view rectangle & view dimensions. Explain that Viewport may return a zero rect, which means to dynamically use the rendertarget's full size. Add todo's related to Viewport::WorldToScreenPoint() && Viewport::ScreenToWorldPoint() potentially operating incorrectly for texture rendertargets. Closes #1482.

Lasse Öörni 9 years ago
parent
commit
995fbd4213

+ 7 - 1
Source/Urho3D/Graphics/View.h

@@ -146,13 +146,19 @@ public:
 
     /// Return information of the frame being rendered.
     const FrameInfo& GetFrameInfo() const { return frame_; }
-
+    
     /// Return the rendertarget. 0 if using the backbuffer.
     RenderSurface* GetRenderTarget() const { return renderTarget_; }
 
     /// Return whether should draw debug geometry.
     bool GetDrawDebug() const { return drawDebug_; }
 
+    /// Return view rectangle.
+    const IntRect& GetViewRect() const { return viewRect_; }
+    
+    /// Return view dimensions.
+    const IntVector2& GetViewSize() const { return viewSize_; }
+    
     /// Return geometry objects.
     const PODVector<Drawable*>& GetGeometries() const { return geometries_; }
 

+ 2 - 0
Source/Urho3D/Graphics/Viewport.cpp

@@ -171,6 +171,7 @@ IntVector2 Viewport::WorldToScreenPoint(const Vector3& worldPos) const
     int y;
     if (rect_ == IntRect::ZERO)
     {
+        /// \todo This is incorrect if the viewport is used on a texture rendertarget instead of the backbuffer, as it may have different dimensions.
         Graphics* graphics = GetSubsystem<Graphics>();
         x = (int)(screenPoint.x_ * graphics->GetWidth());
         y = (int)(screenPoint.y_ * graphics->GetHeight());
@@ -194,6 +195,7 @@ Vector3 Viewport::ScreenToWorldPoint(int x, int y, float depth) const
 
     if (rect_ == IntRect::ZERO)
     {
+        /// \todo This is incorrect if the viewport is used on a texture rendertarget instead of the backbuffer, as it may have different dimensions.
         Graphics* graphics = GetSubsystem<Graphics>();
         screenX = (float)x / (float)graphics->GetWidth();
         screenY = (float)y / (float)graphics->GetHeight();

+ 2 - 2
Source/Urho3D/Graphics/Viewport.h

@@ -56,7 +56,7 @@ public:
     void SetScene(Scene* scene);
     /// Set viewport camera.
     void SetCamera(Camera* camera);
-    /// Set rectangle.
+    /// Set view rectangle. A zero rectangle (0 0 0 0) means to use the rendertarget's full dimensions.
     void SetRect(const IntRect& rect);
     /// Set rendering path.
     void SetRenderPath(RenderPath* path);
@@ -74,7 +74,7 @@ public:
     /// Return the internal rendering structure. May be null if the viewport has not been rendered yet.
     View* GetView() const;
 
-    /// Return rectangle.
+    /// Return view rectangle. A zero rectangle (0 0 0 0) means to use the rendertarget's full dimensions. In this case you could fetch the actual view rectangle from View object, though it will be valid only after the first frame.
     const IntRect& GetRect() const { return rect_; }
 
     /// Return rendering path.