Author Topic: Bug in UICamera in case of perspective camera  (Read 2039 times)

dkozlovtsev

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Bug in UICamera in case of perspective camera
« on: September 13, 2013, 10:42:59 AM »
I'm currently using NGUI 2.7.0 and there is a problem with hit test for perspective UICamera
in Raycast function max ray lenght  is calculated like this^
  1. float dist = (cam.rangeDistance > 0f) ? cam.rangeDistance : currentCamera.farClipPlane - currentCamera.nearClipPlane;
But in case of perspective camera this is not correct as distance between point on near plane and corresponding point on far plane can be bigger that distance between planes( in fact it is always bigger than distance between planes except for the case of ray orthogonal to both planes )
correct value would be (if i am not mistaken)
  1. //pseudocode
  2. dist = (farPlane - nearPlane)/cos(max(fovX, fovY)/2);
  3.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug in UICamera in case of perspective camera
« Reply #1 on: September 13, 2013, 10:47:50 AM »
While you are correct with the distance always being bigger (except when raycasting directly into the center), it would be a bigger problem if the raycast distance was longer than the draw distance. Then you'd be hitting objects that are not in view. The way it is now is better.

dkozlovtsev

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: Bug in UICamera in case of perspective camera
« Reply #2 on: September 13, 2013, 11:23:21 AM »
Good point, but my users have a problem with not hitting visible UI elements, so why not calculate precise ray lenght like this:
  1. dist = (farPlane - nearPlane)/Vector3.Dot(ray.direction, cam.camera.transform.forward);
  2.  
?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug in UICamera in case of perspective camera
« Reply #3 on: September 13, 2013, 12:27:23 PM »
...or you could just fix it by increasing your far clip plane.