예제 #1
0
  public List<Double> calculate(List<Vector3> points) {
    List<Double> result = new ArrayList<>();

    for (Vector3 p : points) {
      double x = p.get(0);
      double y = p.get(1);
      double z = p.get(2);
      result.add(x * x + y * y + z * z - this.radius * this.radius);
    }

    return result;
  }
예제 #2
0
  @Override
  public RayData sample(Vector3 startPoint, Vector3 endPoint) {
    Vector3 direction = startPoint.subtract(endPoint).normalizeM();

    RayData rdata =
        new RayData(
            new Ray(startPoint, direction, 0, 0),
            Constants.RECURSIVE_EPSILON,
            Double.POSITIVE_INFINITY);

    return rdata;
  }
예제 #3
0
  public ChestLight(GL2 gl) {
    super(new SceneGraphNode(gl));

    SceneGraphNode twister = root.createAttachedNode();

    twister
        .createAttachedNode()
        .attachRenderable(new Cuboid(gl, Vector3.one(), Materials.get().get("shinymetal")))
        .setPosition(new Vector3(-0.5f, -0.31f, -0.1f))
        .setScaling(new Vector3(1, 0.5f, 1));

    chestLight =
        twister
            .createAttachedNode()
            .attachRenderable(new Plane(gl, Materials.get().get("chest_light")))
            .setRotation(new Vector3(1, 0, 0), 90)
            .setPosition(new Vector3(-1, -0.6f, -0.6f));
    Robot.CHEST_LIGHT = this;

    twister.setRotation(new Vector3(0, 1, 0), 90);
    twister.setPosition(new Vector3(-0.5f, 0, -0.5f));
  }
예제 #4
0
파일: Scene.java 프로젝트: mhcrnl/JavaCode
  private void trace(
      Vector3 src,
      Vector3 direction,
      photonColor photon,
      int recursion_left,
      double refractive_indice) {
    Geometry geom = Geometry.visible(src, direction, geometries);

    // Going off into space, no collision.
    if (geom == null) {
      return;
      // throw new Error("Not possible, because we surround the scene with impermeable walls.");
    }

    Vector3 dest = geom.computeIntersectionPoint();

    // Add the light.
    double attenuation = add_light_line(src.getX(), src.getY(), dest.getX(), dest.getY(), photon);

    // FIXME : Implement reflectance, transmittance / refraction.

    // 100 % absorption right now.

    Material mat = geom.material;

    // Base Case.
    if (recursion_left < 1) {
      return;
    }

    // Recursive photon Bouncing.

    // Diffuse.
    Vector3 normal = geom.getNormal();

    // Make sure the normal is not the wrong direction.
    if (normal.dot(direction) > 0) {
      normal = normal.mult(-1);
    }

    Bounce_Type val = mat.getWeightedBounceEvent();

    switch (val) {
      case DIFFUSE:
        Vector3 diffuse_bounce_dir = Vector_math.random_hemi_2D(normal);
        photonColor photon_new = photon.mult(attenuation).mult(mat.diffuse);
        trace(
            dest.add(diffuse_bounce_dir.mult(epsilon)),
            diffuse_bounce_dir,
            photon_new,
            recursion_left - 1,
            refractive_indice);
        break;
      case SPECULAR:
        photon_new = photon.mult(attenuation).mult(mat.specular);
        Vector3 specular_bounce_dir = geom.getReflectionDirection();
        trace(
            dest.add(normal.mult(epsilon)),
            specular_bounce_dir,
            photon_new,
            recursion_left - 1,
            refractive_indice);
        break;

      case TRANSMISSION:
        Vector3 refracted_bounce_dir = geom.refract(refractive_indice);

        // Total Internal Reflection.
        if (refracted_bounce_dir == null) {
          return;
        }

        photon_new = photon.mult(attenuation).mult(mat.transmission);
        double bounce_refraction_indice = geom.getNextRefractiveIndex(refractive_indice);
        trace(
            dest.add(refracted_bounce_dir.mult(epsilon)),
            refracted_bounce_dir,
            photon_new,
            recursion_left - 1,
            bounce_refraction_indice);
        break;
    }

    return;
  }