예제 #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 correctPosition(BasicModelData obj, PositionSettings pos) {
   if (obj.getX() > pos.getMaxX()) {
     obj.setX(pos.getMaxX() - randomizeDouble(0, xRatio));
   }
   if (obj.getX() < pos.getMinX()) {
     obj.setX(pos.getMinX() + randomizeDouble(0, xRatio));
   }
   if (obj.getZ() > pos.getMaxZ()) {
     obj.setZ(pos.getMaxZ() - randomizeDouble(0, zRatio));
   }
   if (obj.getZ() < pos.getMinZ()) {
     obj.setZ(pos.getMinZ() + randomizeDouble(0, zRatio));
   }
 }