Implemented sphere. Added icons for circle, cylinder, sphere, circle start corner and start center.
This commit is contained in:
@@ -32,8 +32,8 @@ public class ModeOptions {
|
|||||||
THICKNESS_3("effortlessbuilding.action.thickness_3"),
|
THICKNESS_3("effortlessbuilding.action.thickness_3"),
|
||||||
THICKNESS_5("effortlessbuilding.action.thickness_5"),
|
THICKNESS_5("effortlessbuilding.action.thickness_5"),
|
||||||
|
|
||||||
CIRCLE_START_CENTER("effortlessbuilding.action.start_center"),
|
CIRCLE_START_CORNER("effortlessbuilding.action.start_corner"),
|
||||||
CIRCLE_START_CORNER("effortlessbuilding.action.start_corner");
|
CIRCLE_START_CENTER("effortlessbuilding.action.start_center");
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class ModeOptions {
|
|||||||
CUBE_FILL("effortlessbuilding.action.filling", ActionEnum.CUBE_FULL, ActionEnum.CUBE_HOLLOW, ActionEnum.CUBE_SKELETON),
|
CUBE_FILL("effortlessbuilding.action.filling", ActionEnum.CUBE_FULL, ActionEnum.CUBE_HOLLOW, ActionEnum.CUBE_SKELETON),
|
||||||
RAISED_EDGE("effortlessbuilding.action.raised_edge", ActionEnum.SHORT_EDGE, ActionEnum.LONG_EDGE),
|
RAISED_EDGE("effortlessbuilding.action.raised_edge", ActionEnum.SHORT_EDGE, ActionEnum.LONG_EDGE),
|
||||||
LINE_THICKNESS("effortlessbuilding.action.thickness", ActionEnum.THICKNESS_1, ActionEnum.THICKNESS_3, ActionEnum.THICKNESS_5),
|
LINE_THICKNESS("effortlessbuilding.action.thickness", ActionEnum.THICKNESS_1, ActionEnum.THICKNESS_3, ActionEnum.THICKNESS_5),
|
||||||
CIRCLE_START("effortlessbuilding.action.circle_start", ActionEnum.CIRCLE_START_CENTER, ActionEnum.CIRCLE_START_CORNER);
|
CIRCLE_START("effortlessbuilding.action.circle_start", ActionEnum.CIRCLE_START_CORNER, ActionEnum.CIRCLE_START_CENTER);
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
public ActionEnum[] actions;
|
public ActionEnum[] actions;
|
||||||
@@ -64,7 +64,7 @@ public class ModeOptions {
|
|||||||
private static ActionEnum cubeFill = ActionEnum.CUBE_FULL;
|
private static ActionEnum cubeFill = ActionEnum.CUBE_FULL;
|
||||||
private static ActionEnum raisedEdge = ActionEnum.SHORT_EDGE;
|
private static ActionEnum raisedEdge = ActionEnum.SHORT_EDGE;
|
||||||
private static ActionEnum lineThickness = ActionEnum.THICKNESS_1;
|
private static ActionEnum lineThickness = ActionEnum.THICKNESS_1;
|
||||||
private static ActionEnum circleStart = ActionEnum.CIRCLE_START_CENTER;
|
private static ActionEnum circleStart = ActionEnum.CIRCLE_START_CORNER;
|
||||||
|
|
||||||
public static ActionEnum getOptionSetting(OptionEnum option) {
|
public static ActionEnum getOptionSetting(OptionEnum option) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class Circle extends TwoClicksBuildMode {
|
|||||||
|
|
||||||
float distance = distance(l, n, centerX, centerZ);
|
float distance = distance(l, n, centerX, centerZ);
|
||||||
float radius = calculateEllipseRadius(centerX, centerZ, radiusX, radiusZ, l, n);
|
float radius = calculateEllipseRadius(centerX, centerZ, radiusX, radiusZ, l, n);
|
||||||
if (distance < radius + 0.5f)
|
if (distance < radius + 0.4f)
|
||||||
list.add(new BlockPos(l, y1, n));
|
list.add(new BlockPos(l, y1, n));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ public class Circle extends TwoClicksBuildMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static float distance(float x1, float z1, float x2, float z2) {
|
private static float distance(float x1, float z1, float x2, float z2) {
|
||||||
return MathHelper.sqrt((z2 - z1) * (z2 - z1) + (x2 - x1) * (x2 - x1));
|
return MathHelper.sqrt((x2 - x1) * (x2 - x1) + (z2 - z1) * (z2 - z1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float calculateEllipseRadius(float centerX, float centerZ, float radiusX, float radiusZ, int x, int z) {
|
public static float calculateEllipseRadius(float centerX, float centerZ, float radiusX, float radiusZ, int x, int z) {
|
||||||
|
|||||||
@@ -34,36 +34,77 @@ public class Sphere extends ThreeClicksBuildMode {
|
|||||||
public static List<BlockPos> getSphereBlocks(EntityPlayer player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
|
public static List<BlockPos> getSphereBlocks(EntityPlayer player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
List<BlockPos> list = new ArrayList<>();
|
||||||
|
|
||||||
// float centerX = x1;
|
float centerX = x1;
|
||||||
// float centerZ = z1;
|
float centerY = y1;
|
||||||
//
|
float centerZ = z1;
|
||||||
// //Adjust for CIRCLE_START
|
|
||||||
// if (ModeOptions.getCircleStart() == ModeOptions.ActionEnum.CIRCLE_START_CORNER) {
|
|
||||||
// centerX = x1 + (x2 - x1) / 2f;
|
|
||||||
// centerZ = z1 + (z2 - z1) / 2f;
|
|
||||||
// } else {
|
|
||||||
// x1 = (int) (centerX - (x2 - centerX));
|
|
||||||
// z1 = (int) (centerZ - (z2 - centerZ));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// float radiusX = MathHelper.abs(x2 - centerX);
|
|
||||||
// float radiusZ = MathHelper.abs(z2 - centerZ);
|
|
||||||
//
|
|
||||||
// if (ModeOptions.getFill() == ModeOptions.ActionEnum.FULL)
|
|
||||||
// addCircleBlocks(list, x1, y1, z1, x2, y2, z2, centerX, centerZ, radiusX, radiusZ);
|
|
||||||
// else
|
|
||||||
// addHollowCircleBlocks(list, x1, y1, z1, x2, y2, z2, centerX, centerZ, radiusX, radiusZ, 1f);
|
|
||||||
//
|
|
||||||
// return list;
|
|
||||||
|
|
||||||
//Adjust for CIRCLE_START
|
//Adjust for CIRCLE_START
|
||||||
|
if (ModeOptions.getCircleStart() == ModeOptions.ActionEnum.CIRCLE_START_CORNER) {
|
||||||
|
centerX = x1 + (x2 - x1) / 2f;
|
||||||
|
centerY = y1 + (y3 - y1) / 2f;
|
||||||
|
centerZ = z1 + (z2 - z1) / 2f;
|
||||||
|
} else {
|
||||||
|
x1 = (int) (centerX - (x2 - centerX));
|
||||||
|
y1 = (int) (centerY - (y3 - centerY));
|
||||||
|
z1 = (int) (centerZ - (z2 - centerZ));
|
||||||
|
}
|
||||||
|
|
||||||
//Get center point
|
float radiusX = MathHelper.abs(x2 - centerX);
|
||||||
|
float radiusY = MathHelper.abs(y3 - centerY);
|
||||||
|
float radiusZ = MathHelper.abs(z2 - centerZ);
|
||||||
|
|
||||||
//Get radius
|
if (ModeOptions.getFill() == ModeOptions.ActionEnum.FULL)
|
||||||
|
addSphereBlocks(list, x1, y1, z1, x3, y3, z3, centerX, centerY, centerZ, radiusX, radiusY, radiusZ);
|
||||||
//Get blocks based on FILL
|
else
|
||||||
|
addHollowSphereBlocks(list, x1, y1, z1, x3, y3, z3, centerX, centerY, centerZ, radiusX, radiusY, radiusZ, 1f);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addSphereBlocks(List<BlockPos> list, int x1, int y1, int z1, int x2, int y2, int z2,
|
||||||
|
float centerX, float centerY, float centerZ, float radiusX, float radiusY, float radiusZ) {
|
||||||
|
for (int l = x1; x1 < x2 ? l <= x2 : l >= x2; l += x1 < x2 ? 1 : -1) {
|
||||||
|
|
||||||
|
for (int n = z1; z1 < z2 ? n <= z2 : n >= z2; n += z1 < z2 ? 1 : -1) {
|
||||||
|
|
||||||
|
for (int m = y1; y1 < y2 ? m <= y2 : m >= y2; m += y1 < y2 ? 1 : -1) {
|
||||||
|
|
||||||
|
float distance = distance(l, m, n, centerX, centerY, centerZ);
|
||||||
|
float radius = calculateSpheroidRadius(centerX, centerY, centerZ, radiusX, radiusY, radiusZ, l, m, n);
|
||||||
|
if (distance < radius + 0.5f)
|
||||||
|
list.add(new BlockPos(l, m, n));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addHollowSphereBlocks(List<BlockPos> list, int x1, int y1, int z1, int x2, int y2, int z2,
|
||||||
|
float centerX, float centerY, float centerZ, float radiusX, float radiusY, float radiusZ, float thickness) {
|
||||||
|
for (int l = x1; x1 < x2 ? l <= x2 : l >= x2; l += x1 < x2 ? 1 : -1) {
|
||||||
|
|
||||||
|
for (int n = z1; z1 < z2 ? n <= z2 : n >= z2; n += z1 < z2 ? 1 : -1) {
|
||||||
|
|
||||||
|
for (int m = y1; y1 < y2 ? m <= y2 : m >= y2; m += y1 < y2 ? 1 : -1) {
|
||||||
|
|
||||||
|
float distance = distance(l, m, n, centerX, centerY, centerZ);
|
||||||
|
float radius = calculateSpheroidRadius(centerX, centerY, centerZ, radiusX, radiusY, radiusZ, l, m, n);
|
||||||
|
if (distance < radius + (thickness / 2f) && distance > radius - (thickness / 2f))
|
||||||
|
list.add(new BlockPos(l, m, n));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float distance(float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||||
|
return MathHelper.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float calculateSpheroidRadius(float centerX, float centerY, float centerZ, float radiusX, float radiusY, float radiusZ, int x, int y, int z) {
|
||||||
|
//Twice ellipse radius
|
||||||
|
float radiusXZ = Circle.calculateEllipseRadius(centerX, centerZ, radiusX, radiusZ, x, z);
|
||||||
|
|
||||||
|
//TODO project x to plane
|
||||||
|
|
||||||
|
return Circle.calculateEllipseRadius(centerX, centerY, radiusXZ, radiusY, x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 273 B |
Binary file not shown.
|
After Width: | Height: | Size: 232 B |
Binary file not shown.
|
After Width: | Height: | Size: 222 B |
Binary file not shown.
|
After Width: | Height: | Size: 292 B |
Binary file not shown.
|
After Width: | Height: | Size: 361 B |
Reference in New Issue
Block a user