Author Topic: 3d camera Z distance  (Read 3363 times)

duncanfoo

  • Guest
3d camera Z distance
« on: October 24, 2013, 10:12:55 AM »
I created a new 3d ui root. The camera distance was set by ngui to -700. I have some widgets that I want anchored to the top and bottom of the screen which should span the entire screen. They are currently 1280x some height. If I use a 2d camera with a 720 viewport (16:9) this works correctly and it correctly spans the screen. With the 3d camera it does not unless I change the Z value to about -623 (the sprite is scaled slightly). Why is that?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3d camera Z distance
« Reply #1 on: October 24, 2013, 11:54:08 PM »
Short answer: math. 2D cameras have a uniform width and height from min to max draw distance (near and far planes). Perspective cameras (3D) have a non-uniform width and height that changes from min to max draw distance. That 623 is what you'd call a "magic" number in your case. If you were to change the near or far clipping planes on your camera, that value would also need to change.

duncanfoo

  • Guest
Re: 3d camera Z distance
« Reply #2 on: October 25, 2013, 06:04:35 AM »
Thanks for the answer. I fixed the problem by using both a 2d and a 3d camera (the nGUI example which demonstrates this was very useful). The sprites which span the top and bottom use the 2d camera the skewed panels use the 3d camera.

One note which might qualify for a FAQ

My game scene is renderered using deferred rendering and uses bloom/ssao. When I first attached the nGUI 3d camera nothing was rendered. I had to switch the nGUI camera to use forward rendering to get this working.