Esempio n. 1
0
 @Override
 public Illumination illuminate(Vec3D point) {
   Vec3D lightDirection = point.subtract(position);
   double r2 = lightDirection.dotProduct(lightDirection);
   double distance = Math.sqrt(r2);
   lightDirection = lightDirection.multiply(1 / distance);
   Vec3D lightIntensity = color.multiply(intensity / (4 * Math.PI * r2));
   return new Illumination(lightDirection, lightIntensity, distance);
 }
Esempio n. 2
0
  @Override
  public Double intersect(Ray ray) {
    // Moller-Trumbore algorithm
    Vec3D v0v1 = v1.subtract(v0);
    Vec3D v0v2 = v2.subtract(v0);
    Vec3D pvec = ray.direction.crossProduct(v0v2);

    normal = v0v1.crossProduct(v0v2).normalize();

    double det = v0v1.dotProduct(pvec);
    if (Options.culling)
      if (det < Options.kEpsilon) return null;
      else if (Math.abs(det) < Options.kEpsilon) return null;
    double invDet = 1 / det;
    Vec3D tvec = ray.origin.subtract(v0);
    u = tvec.dotProduct(pvec) * invDet;
    if (u < 0 || u > 1) return null;
    Vec3D qvec = tvec.crossProduct(v0v1);
    v = ray.direction.dotProduct(qvec) * invDet;
    if (v < 0 || u + v > 1) return null;
    return v0v2.dotProduct(qvec) * invDet;
  }