コード例 #1
0
  public double getDistance(Vector<VivaeObject> objects) {
    GeneralPath thisPath = new GeneralPath(this.getTransformedShape());
    PathIntersection pi = new PathIntersection();
    Point2D.Double[] points;
    double dist = ray_length;
    double nd;
    for (VivaeObject vivaeObject : objects) {
      if (vivaeObject != this.owner) {
        GeneralPath gp = new GeneralPath(vivaeObject.getTransformedShape());
        points = pi.getIntersections(thisPath, gp);
        for (Point2D.Double point : points) {
          nd = pi.euclideanDistance(point.getX(), point.getY(), owner.getX(), owner.getY());
          if (nd < dist) {
            dist = nd;
          }
          // System.out.println(dist);
        }
      }
    }

    opacity = Math.max((float) (1d - (dist / ray_length)), opacity);
    opacityOfRay = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);

    return 1d - (dist / ray_length);
  }
コード例 #2
0
 /**
  * Method intersects area of Sensor and all VivaeObjects and returns those that have non-zero
  * intersection.
  *
  * @param objects Vector of VivaeObjects that are checked for collision with the body of Sensor.
  * @return Vector of VivaeObjects that are in collision with the body of Sensor.
  */
 public Vector<VivaeObject> getVivaesOnSight(Vector<VivaeObject> objects) {
   Vector<VivaeObject> objectsOnSight = new Vector<VivaeObject>();
   // for (VivaeObject vivaeObject : objects) {
   GeneralPath thisPath = new GeneralPath(this.getTransformedShape());
   PathIntersection pi = new PathIntersection();
   Point2D.Double[] points;
   for (VivaeObject vivaeObject : getCloseVivaes(objects)) {
     if (vivaeObject != this.owner) {
       GeneralPath gp = new GeneralPath(vivaeObject.getTransformedShape());
       points = pi.getIntersections(thisPath, gp);
       /*
       for(Point2D.Double point : points){
       System.out.println("x = "+point.getX()+" y = "+point.getY());
       System.out.println("owner x = "+owner.getX()+" owner y = "+owner.getY());
       System.out.println(pi.euclideanDistance(point.getX(),point.getY(),owner.getX(),owner.getY()));
       }*/
       if (points.length > 0) {
         objectsOnSight.add(vivaeObject);
       }
       /*Area actArea = (Area) vivaeObject.getArea().clone();
       actArea.intersect(this.getArea());
       if (!actArea.isEmpty()) objectsOnSight.add(vivaeObject);             */
       //             if(vivaeObject instanceof roboneat.RoboNeatRobot)System.out.println("robot
       // seen by"+this.owner);
     }
   }
   return objectsOnSight;
 }