Added library support for non-integer radius spheres and cylinders.

Dieser Commit ist enthalten in:
TomyLobo 2011-08-07 05:10:59 +02:00
Ursprung a527b59770
Commit 9d98ca3db8
9 geänderte Dateien mit 49 neuen und 46 gelöschten Zeilen

Datei anzeigen

@ -1626,36 +1626,37 @@ public class EditSession {
* @param block
* @throws MaxChangedBlocksException
*/
private int makeHCylinderPoints(Vector center, int x, int z, int height,
private int makeHCylinderPoints(Vector center, int x, double z, int height,
Pattern block) throws MaxChangedBlocksException {
int ceilZ = (int) Math.ceil(z);
int affected = 0;
if (x == 0) {
for (int y = 0; y < height; ++y) {
setBlock(center.add(0, y, z), block);
setBlock(center.add(0, y, -z), block);
setBlock(center.add(z, y, 0), block);
setBlock(center.add(-z, y, 0), block);
setBlock(center.add(0, y, ceilZ), block);
setBlock(center.add(0, y, -ceilZ), block);
setBlock(center.add(ceilZ, y, 0), block);
setBlock(center.add(-ceilZ, y, 0), block);
affected += 4;
}
} else if (x == z) {
for (int y = 0; y < height; ++y) {
setBlock(center.add(x, y, z), block);
setBlock(center.add(-x, y, z), block);
setBlock(center.add(x, y, -z), block);
setBlock(center.add(-x, y, -z), block);
setBlock(center.add(x, y, ceilZ), block);
setBlock(center.add(-x, y, ceilZ), block);
setBlock(center.add(x, y, -ceilZ), block);
setBlock(center.add(-x, y, -ceilZ), block);
affected += 4;
}
} else if (x < z) {
for (int y = 0; y < height; ++y) {
setBlock(center.add(x, y, z), block);
setBlock(center.add(-x, y, z), block);
setBlock(center.add(x, y, -z), block);
setBlock(center.add(-x, y, -z), block);
setBlock(center.add(z, y, x), block);
setBlock(center.add(-z, y, x), block);
setBlock(center.add(z, y, -x), block);
setBlock(center.add(-z, y, -x), block);
setBlock(center.add(x, y, ceilZ), block);
setBlock(center.add(-x, y, ceilZ), block);
setBlock(center.add(x, y, -ceilZ), block);
setBlock(center.add(-x, y, -ceilZ), block);
setBlock(center.add(ceilZ, y, x), block);
setBlock(center.add(-ceilZ, y, x), block);
setBlock(center.add(ceilZ, y, -x), block);
setBlock(center.add(-ceilZ, y, -x), block);
affected += 8;
}
}
@ -1673,11 +1674,11 @@ public class EditSession {
* @return number of blocks set
* @throws MaxChangedBlocksException
*/
public int makeHollowCylinder(Vector pos, Pattern block, int radius,
public int makeHollowCylinder(Vector pos, Pattern block, double radius,
int height) throws MaxChangedBlocksException {
int x = 0;
int z = radius;
int d = (5 - radius * 4) / 4;
double z = radius;
double d = (5 - radius * 4) / 4;
int affected = 0;
if (height == 0) {
@ -1721,13 +1722,14 @@ public class EditSession {
* @param block
* @throws MaxChangedBlocksException
*/
private int makeCylinderPoints(Vector center, int x, int z, int height,
private int makeCylinderPoints(Vector center, int x, double z, int height,
Pattern block) throws MaxChangedBlocksException {
int affected = 0;
int ceilZ = (int) Math.ceil(z);
int affected = 0;
if (x == z) {
for (int y = 0; y < height; ++y) {
for (int z2 = -z; z2 <= z; ++z2) {
for (int z2 = -ceilZ; z2 <= ceilZ; ++z2) {
setBlock(center.add(x, y, z2), block);
setBlock(center.add(-x, y, z2), block);
affected += 2;
@ -1736,12 +1738,12 @@ public class EditSession {
} else if (x < z) {
for (int y = 0; y < height; ++y) {
for (int x2 = -x; x2 <= x; ++x2) {
for (int z2 = -z; z2 <= z; ++z2) {
for (int z2 = -ceilZ; z2 <= ceilZ; ++z2) {
setBlock(center.add(x2, y, z2), block);
++affected;
}
setBlock(center.add(z, y, x2), block);
setBlock(center.add(-z, y, x2), block);
setBlock(center.add(ceilZ, y, x2), block);
setBlock(center.add(-ceilZ, y, x2), block);
affected += 2;
}
}
@ -1760,11 +1762,11 @@ public class EditSession {
* @return number of blocks set
* @throws MaxChangedBlocksException
*/
public int makeCylinder(Vector pos, Pattern block, int radius, int height)
public int makeCylinder(Vector pos, Pattern block, double radius, int height)
throws MaxChangedBlocksException {
int x = 0;
int z = radius;
int d = (5 - radius * 4) / 4;
double z = radius;
double d = (5 - radius * 4) / 4;
int affected = 0;
if (height == 0) {
@ -1807,13 +1809,14 @@ public class EditSession {
* @return number of blocks changed
* @throws MaxChangedBlocksException
*/
public int makeSphere(Vector pos, Pattern block, int radius,
public int makeSphere(Vector pos, Pattern block, double radius,
boolean filled) throws MaxChangedBlocksException {
int affected = 0;
for (int x = 0; x <= radius; ++x) {
for (int y = 0; y <= radius; ++y) {
for (int z = 0; z <= radius; ++z) {
int ceilRadius = (int) Math.ceil(radius);
for (int x = 0; x <= ceilRadius; ++x) {
for (int y = 0; y <= ceilRadius; ++y) {
for (int z = 0; z <= ceilRadius; ++z) {
Vector vec = pos.add(x, y, z);
double d = vec.distance(pos);

Datei anzeigen

@ -41,7 +41,7 @@ public class BrushTool implements TraceTool {
private Mask mask = null;
private Brush brush = new SphereBrush();
private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE));
private int size = 1;
private double size = 1;
private String permission;
/**
@ -125,17 +125,17 @@ public class BrushTool implements TraceTool {
*
* @return
*/
public int getSize() {
public double getSize() {
return size;
}
/**
* Set the set brush size.
*
* @param size
* @param radius
*/
public void setSize(int size) {
this.size = size;
public void setSize(double radius) {
this.size = radius;
}
/**

Datei anzeigen

@ -39,6 +39,6 @@ public interface Brush {
* @param size
* @throws MaxChangedBlocksException
*/
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
public void build(EditSession editSession, Vector pos, Pattern mat, double size)
throws MaxChangedBlocksException;
}

Datei anzeigen

@ -34,7 +34,7 @@ public class ClipboardBrush implements Brush {
this.noAir = noAir;
}
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
public void build(EditSession editSession, Vector pos, Pattern mat, double size)
throws MaxChangedBlocksException {
clipboard.place(editSession,
pos.subtract(clipboard.getSize().divide(2)), noAir);

Datei anzeigen

@ -31,7 +31,7 @@ public class CylinderBrush implements Brush {
this.height = height;
}
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
public void build(EditSession editSession, Vector pos, Pattern mat, double size)
throws MaxChangedBlocksException {
editSession.makeCylinder(pos, mat, size, height);
}

Datei anzeigen

@ -31,7 +31,7 @@ public class HollowCylinderBrush implements Brush {
this.height = height;
}
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
public void build(EditSession editSession, Vector pos, Pattern mat, double size)
throws MaxChangedBlocksException {
editSession.makeHollowCylinder(pos, mat, size, height);
}

Datei anzeigen

@ -28,7 +28,7 @@ public class HollowSphereBrush implements Brush {
public HollowSphereBrush() {
}
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
public void build(EditSession editSession, Vector pos, Pattern mat, double size)
throws MaxChangedBlocksException {
editSession.makeSphere(pos, mat, size, false);
}

Datei anzeigen

@ -36,9 +36,9 @@ public class SmoothBrush implements Brush {
this.iterations = iterations;
}
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
public void build(EditSession editSession, Vector pos, Pattern mat, double size)
throws MaxChangedBlocksException {
int rad = size;
double rad = size;
Vector min = pos.subtract(rad, rad, rad);
Vector max = pos.add(rad, rad + 10, rad);
Region region = new CuboidRegion(min, max);

Datei anzeigen

@ -28,7 +28,7 @@ public class SphereBrush implements Brush {
public SphereBrush() {
}
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
public void build(EditSession editSession, Vector pos, Pattern mat, double size)
throws MaxChangedBlocksException {
editSession.makeSphere(pos, mat, size, true);
}