示例#1
0
 protected void correctPosition(
     BasicModelData obj, PositionSettings pos, List<HeightInfo> positions) {
   double xVar = xRatio;
   double zVar = zRatio;
   double x = obj.getX();
   double z = obj.getZ();
   if (!positions.isEmpty() || collisionTree != null) {
     HeightInfo actual = new HeightInfo(obj.getX(), 0, obj.getZ());
     HeightInfo nearest = new HeightInfo(Double.MAX_VALUE, 0, Double.MAX_VALUE);
     if (!positions.isEmpty()) {
       nearest = findNearest(positions, actual, nearest);
       x = nearest.getX();
       z = nearest.getZ();
     }
     if (collisionTree != null) {
       actual.setSx(obj.getSx());
       actual.setSz(obj.getSz());
       TreeNode place = collisionTree.findPlace(actual);
       if (place != null) {
         x = place.getMid()[0];
         z = place.getMid()[1];
         double nodeRange = place.getRange();
         xVar = nodeRange + 1 - actual.getSx();
         zVar = nodeRange + 1 - actual.getSz();
         TreeNode.mark(place);
       } else {
         collisionDetected = true;
       }
     }
   }
   obj.setX(x + randomizeDouble(-xVar, xVar));
   obj.setZ(z + randomizeDouble(-zVar, zVar));
   correctPosition(obj, pos);
 }
示例#2
0
 protected void setPosition(
     PositionSettings pos, List<HeightInfo> heights, BasicModelData obj, int heightPos) {
   HeightInfo height = heights.get(heightPos);
   obj.setPosition(
       height.getX() + randomizeDouble(-xRatio, xRatio),
       randomizeDouble(pos.getMinY(), pos.getMaxY()),
       height.getZ() + randomizeDouble(-zRatio, zRatio));
   correctPosition(obj, pos, heights);
 }
示例#3
0
 private HeightInfo findNearest(
     List<HeightInfo> positions, HeightInfo actual, HeightInfo nearest) {
   double minLength = Double.MAX_VALUE;
   Collections.shuffle(positions);
   for (HeightInfo i : positions) {
     if (i.equals(actual)) {
       return i;
     }
     double tempLenght = getLength(i.getX(), nearest.getX(), i.getZ(), nearest.getZ());
     if (minLength < 0.5) {
       break;
     }
     if (tempLenght < minLength) {
       minLength = tempLenght;
       nearest = i;
     }
   }
   return nearest;
 }