Hello Guest

Author Topic: Plane fill the 2DTk-camera  (Read 3790 times)

DJVDJV

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Plane fill the 2DTk-camera
« 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?
« Last Edit: November 22, 2016, 08:01:45 am by DJVDJV »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Plane fill the 2DTk-camera
« Reply #1 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