Example #1
0
 public void addTriangle(Vector3d p1, Vector3d p2, Vector3d p3) {
   Triangle t = new Triangle(p1, p2, p3);
   // System.out.println("Adding triangle to TriangleSet: " + t);
   t.material = this.material;
   triangles.add(t);
   bb = null;
 }
Example #2
0
 @Override
 public String toString() {
   StringBuffer sb = new StringBuffer("TriangleSet(");
   for (Triangle t : triangles) {
     sb.append(t.toString());
     sb.append(", ");
   }
   return sb.substring(0, sb.length() - 2) + ")";
 }
Example #3
0
 @Override
 public Vector3d getNormalAt(Vector3d point) {
   for (Triangle t : triangles) {
     if (t.pointBelongs(point)) {
       return t.getNormalAt(point);
     }
   }
   return null;
 }
Example #4
0
  @Override
  public Intersection intersectsRay(Ray ray) {
    double currentDistance, nearestDistance = Double.MAX_VALUE;
    Intersection nearestIntersection = null;

    for (Triangle t : triangles) {
      Intersection currentIntersection = t.intersectsRay(ray);
      if (currentIntersection == null) {
        continue;
      }

      Vector3d aux = new Vector3d(currentIntersection.point);
      aux.sub(ray.position);
      currentDistance = Util.Norm(aux);

      if (nearestIntersection == null || currentDistance < nearestDistance) {
        nearestIntersection = currentIntersection;
        nearestDistance = currentDistance;
      }
    }

    return nearestIntersection;
  }
Example #5
0
 @Override
 public void transform(Transformation t) {
   for (Triangle tri : triangles) {
     tri.transform(t);
   }
 }