Author Topic: camera viewport settings problem  (Read 3882 times)

jjevol

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
camera viewport settings problem
« on: November 06, 2014, 05:19:22 AM »
ViewPort Rect strangely drawn this setting screen.


<ViewPort Setting ( 0.2, 0.2, 0.6, 0.6)>

The problem is that the device comes out in galaxynote1.



<OtherDevice>
The latest model of the device has not yet been confirmed.

Do I need to solve this problem
Thank you for the feedback on the issue.
« Last Edit: November 06, 2014, 05:33:38 AM by jjevol »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: camera viewport settings problem
« Reply #1 on: November 07, 2014, 01:35:52 PM »
Did you forget to clear the screen? UI camera is set to clear flags of "depth only" by default. You need it to clear color too.

jjevol

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: camera viewport settings problem
« Reply #2 on: November 10, 2014, 02:15:28 AM »
In addition to in-game representation of the UI screen and camera illuminates the screen Depth 0
The UICamera Depth 1.

If you set as your comment seems to do this in-game screen

I understand trying to make it look smaller screen thinking about that set the view port rect haejwoya Having had cleared it again
And this problem arises from the specific device

There was no problem in NGUI 3.5.6.

I want the camera to cut road area ratio to fit the screen.

----------------------------------------------------------------------------
if ((float)Screen.width / (float)Screen.height < ManualWidth / ManualHeight)
        {
            height = Screen.width * (ManualHeight / ManualWidth) / (float)Screen.height;
            yPos = (1 - height) / 2f;
            //height -= 0.00001f;
        }
        else
        {
            width = (float)Screen.height * (ManualWidth / ManualHeight) / (float)Screen.width;
            xPos = (1 - width) / 2f;
            //width -= 0.00001f;
        }

        Util.SetScissorRect(uiCamera, new Rect(xPos, yPos, width, height));
        uiRoot.manualHeight = Mathf.FloorToInt(Mathf.Max(ManualHeight, ManualHeight * (ManualWidth / (Screen.width * (ManualHeight / Screen.height)))));


public static void SetScissorRect(Camera cam, Rect r)
    {
        if (r.x < 0)
        {
            r.width += r.x;
            r.x = 0;
        }

        if (r.y < 0)
        {
            r.height += r.y;
            r.y = 0;
        }

        r.width = Mathf.Min(1 - r.x, r.width);
        r.height = Mathf.Min(1 - r.y, r.height);

        cam.rect = new Rect(0, 0, 1, 1);
        cam.ResetProjectionMatrix();
        Matrix4x4 m = cam.projectionMatrix;
        cam.rect = r;
        Matrix4x4 m1 = Matrix4x4.TRS(new Vector3(r.x, r.y, 0), Quaternion.identity, new Vector3(r.width, r.height, 1));
        Matrix4x4 m2 = Matrix4x4.TRS(new Vector3((1 / r.width - 1), (1 / r.height - 1), 0), Quaternion.identity, new Vector3(1 / r.width, 1 / r.height, 1));
        Matrix4x4 m3 = Matrix4x4.TRS(new Vector3(-r.x * 2 / r.width, -r.y * 2 / r.height, 0), Quaternion.identity, Vector3.one);
        cam.projectionMatrix = m3 * m2 * m;
    }
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
It uses the code above problem occurred
Initially found it 's fresh because of projectionMatrix


However, even when a problem occurs to change the viewport rect without using "SetScissorRect"
To receive feedback about the solution to the problem.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: camera viewport settings problem
« Reply #3 on: November 10, 2014, 08:34:03 PM »
It doesn't matter what you do with the projection matrix, there must always be at least ONE camera in the scene to clear the screen fully, and it must not have a view rect / matrix set. It must be the very first camera to draw. Make sure your Main Camera is the one that does this. UI camera should draw after it.