The Sphere selector can now also shrink the region.

The radius is set to ceil(distanceToCenter).
This commit is contained in:
TomyLobo 2013-08-24 09:55:35 +02:00
parent 878c26a8f0
commit 77219a8b3e
2 changed files with 4 additions and 7 deletions

View File

@ -763,7 +763,7 @@ public void select(CommandContext args, LocalSession session, LocalPlayer player
player.print("Ellipsoid selector: left click=center, right click to extend"); player.print("Ellipsoid selector: left click=center, right click to extend");
} else if (typeName.equalsIgnoreCase("sphere")) { } else if (typeName.equalsIgnoreCase("sphere")) {
selector = new SphereRegionSelector(oldSelector); selector = new SphereRegionSelector(oldSelector);
player.print("Sphere selector: left click=center, right click to extend"); player.print("Sphere selector: left click=center, right click to set radius");
} else if (typeName.equalsIgnoreCase("cyl")) { } else if (typeName.equalsIgnoreCase("cyl")) {
selector = new CylinderRegionSelector(oldSelector); selector = new CylinderRegionSelector(oldSelector);
player.print("Cylindrical selector: Left click=center, right click to extend."); player.print("Cylindrical selector: Left click=center, right click to extend.");

View File

@ -41,7 +41,7 @@ public SphereRegionSelector() {
public SphereRegionSelector(RegionSelector oldSelector) { public SphereRegionSelector(RegionSelector oldSelector) {
super(oldSelector); super(oldSelector);
final Vector radius = region.getRadius(); final Vector radius = region.getRadius();
double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ()); final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ());
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar)); region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
} }
@ -51,12 +51,9 @@ public SphereRegionSelector(LocalWorld world, Vector center, int radius) {
@Override @Override
public boolean selectSecondary(Vector pos) { public boolean selectSecondary(Vector pos) {
final Vector diff = pos.subtract(region.getCenter()); final double radiusScalar = Math.ceil(pos.distance(region.getCenter()));
final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0)); region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
double minRadiusScalar = Math.max(Math.max(minRadius.getX(), minRadius.getY()), minRadius.getZ());
region.extendRadius(new Vector(minRadiusScalar, minRadiusScalar, minRadiusScalar));
return true; return true;
} }