예제 #1
0
  private static Ray rayThruPixel(Camera cam, int xi, int yi) {
    Ray result = new Ray();
    float x = xi + .5f;
    float y = yi + .5f;
    final int halfW = cam.getHalfW();
    float alpha = (float) (cam.getTanHalfFovX()) * ((x - halfW) / halfW);
    final int halfH = cam.getHalfH();
    float beta = (float) (cam.getTanHalfFovY() * (halfH - y) / halfH);
    Vector3D p13 =
        cam.getU().scalarMultiply(alpha).add(cam.getV().scalarMultiply(beta)).subtract(cam.getW());

    result.setP0(cam.getFrom());
    result.setP1(VectorUtils.toRealVector(p13));

    return result;
  }