2D Toolkit Forum

2D Toolkit => Support => Topic started by: DJVDJV on November 17, 2016, 11:16:22 am

Title: Plane fill the 2DTk-camera
Post by: DJVDJV on November 17, 2016, 11:16:22 am
Hellos, I am using 2dTk Camera (orthographic).

Now I have plane that I want to fill whole camera.

I tried it like this:
transform.localScale = new Vector3(k2dCamera.Instance.ScreenCamera.orthographicSize * 2.0f * Screen.width / Screen.height, k2dCamera.Instance.ScreenCamera.orthographicSize * 2.0f, 10f);

Also like this:
float worldScreenHeight = tk2dCamera.Instance.ScreenCamera.orthographicSize * 2;
float worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;
Bounds bounds = plane.bounds; // Plane is here plane I want fill camera
transform.localScale = new Vector3(
worldScreenWidth / bounds.size.x,
worldScreenHeight / bounds.size.y, 1);

But scale seems to about 80 times too big? How do I get this to work with 2Dtk camera?
Title: Re: Plane fill the 2DTk-camera
Post by: unikronsoftware on November 29, 2016, 06:54:07 pm
tk2dCamera doesn't use orthographic size, it uses a custom projection matrix. You can get the 2 points in world space you need to scale to fit by doing -

Code: [Select]
Vector3 pt0 = tk2dCamera.Instance.ScreenCamera.ViewportToWorldPoint(new Vector3(0, 0, 0));
Vector3 pt1 = tk2dCamera.Instance.ScreenCamera.ViewportToWorldPoint(new Vector3(1, 1, 0));

Then reposition and rescale your plane to fit those 2 world points