Example #1
0
 /** Transforms a pixel in window coordinates to a ray in world coordinates. */
 public static Ray windowToWorld(Camera camera, Viewport viewport, Point windowCoords) {
   Vec2f ndc = viewport.windowToNDC(windowCoords);
   Vec4f n =
       camera
           .getViewInverse()
           .times(camera.getProjectionInverse().times(new Vec4f(ndc.x, ndc.y, -1, 1)));
   n.divide(n.w);
   Vec4f f =
       camera
           .getViewInverse()
           .times(camera.getProjectionInverse().times(new Vec4f(ndc.x, ndc.y, 1, 1)));
   f.divide(f.w);
   return new Ray(n.xyz(), f.minus(n).xyz().normalized());
 }