From 1e51589bde640be5a37e5d4b394dad1d0ef422c0 Mon Sep 17 00:00:00 2001 From: Christian Knaapen Date: Wed, 4 Dec 2019 17:36:26 +0100 Subject: [PATCH] Implemented sphere. Added icons for circle, cylinder, sphere, circle start corner and start center. --- .../buildmode/ModeOptions.java | 8 +- .../buildmode/buildmodes/Circle.java | 4 +- .../buildmode/buildmodes/Sphere.java | 91 +++++++++++++----- .../textures/icons/circle.png | Bin 0 -> 273 bytes .../textures/icons/circle_start_center.png | Bin 0 -> 232 bytes .../textures/icons/circle_start_corner.png | Bin 0 -> 222 bytes .../textures/icons/cylinder.png | Bin 0 -> 292 bytes .../textures/icons/sphere.png | Bin 0 -> 361 bytes 8 files changed, 72 insertions(+), 31 deletions(-) create mode 100644 src/main/resources/assets/effortlessbuilding/textures/icons/circle.png create mode 100644 src/main/resources/assets/effortlessbuilding/textures/icons/circle_start_center.png create mode 100644 src/main/resources/assets/effortlessbuilding/textures/icons/circle_start_corner.png create mode 100644 src/main/resources/assets/effortlessbuilding/textures/icons/cylinder.png create mode 100644 src/main/resources/assets/effortlessbuilding/textures/icons/sphere.png diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmode/ModeOptions.java b/src/main/java/nl/requios/effortlessbuilding/buildmode/ModeOptions.java index 42a1b5f..81dec27 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmode/ModeOptions.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmode/ModeOptions.java @@ -32,8 +32,8 @@ public class ModeOptions { THICKNESS_3("effortlessbuilding.action.thickness_3"), 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; @@ -48,7 +48,7 @@ public class ModeOptions { 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), 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 ActionEnum[] actions; @@ -64,7 +64,7 @@ public class ModeOptions { private static ActionEnum cubeFill = ActionEnum.CUBE_FULL; private static ActionEnum raisedEdge = ActionEnum.SHORT_EDGE; 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) { switch (option) { diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Circle.java b/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Circle.java index 853a99c..1e57d24 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Circle.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Circle.java @@ -54,7 +54,7 @@ public class Circle extends TwoClicksBuildMode { float distance = distance(l, n, centerX, centerZ); 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)); } } @@ -75,7 +75,7 @@ public class Circle extends TwoClicksBuildMode { } 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) { diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Sphere.java b/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Sphere.java index 8483653..6deea57 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Sphere.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Sphere.java @@ -34,36 +34,77 @@ public class Sphere extends ThreeClicksBuildMode { public static List getSphereBlocks(EntityPlayer player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) { List list = new ArrayList<>(); -// float centerX = x1; -// 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; + float centerX = x1; + float centerY = y1; + float centerZ = z1; //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 - - //Get blocks based on FILL + if (ModeOptions.getFill() == ModeOptions.ActionEnum.FULL) + addSphereBlocks(list, x1, y1, z1, x3, y3, z3, centerX, centerY, centerZ, radiusX, radiusY, radiusZ); + else + addHollowSphereBlocks(list, x1, y1, z1, x3, y3, z3, centerX, centerY, centerZ, radiusX, radiusY, radiusZ, 1f); return list; } + + public static void addSphereBlocks(List 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 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); + } } \ No newline at end of file diff --git a/src/main/resources/assets/effortlessbuilding/textures/icons/circle.png b/src/main/resources/assets/effortlessbuilding/textures/icons/circle.png new file mode 100644 index 0000000000000000000000000000000000000000..66d5a04068bac57a2c39c8e384645458fce76bc8 GIT binary patch literal 273 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)1F==&(na6DY!2;1OBO zz`(a3gc&VZgH?cn>?NMQuI!I_Sojr`wKP|o1BK>!x;TbdoIX1FH1A;r9tYp6yHmF{ zr0&?rq`iT$xRLDN~mCO);DJN?3k>I;V6)efveexy4zVI%K%n3aqp&y3Vl8 zV_>Lyul06s{Eo;Zw+j9{f|7!apLO?4wOLp8(2mh~ep^)b>0g#{2F40XEdn7Mu5r11 zxq1DkV)40#j@2yLZ?pVe1d?mY9cMQOb!mBMzAP>{t@7`exZZJYpUoDzO$W<<0bR=A M>FVdQ&MBb@01U-kE&u=k literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/effortlessbuilding/textures/icons/circle_start_center.png b/src/main/resources/assets/effortlessbuilding/textures/icons/circle_start_center.png new file mode 100644 index 0000000000000000000000000000000000000000..6f1a62328ca9e25415b2ff7b9e0e6890a2fdc957 GIT binary patch literal 232 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)1F==&(na6DY!2;1OBO zz`(a3gc&VZgH?cn>?NMQuI!I_SoqaBPF^{(0Vq`J>Eak-ar$h~ZQcV495%D`4u`CH zEamgm;+uPqW7O;`%l7Km6corDn4R#<==Ww@-A&)wL$_{VaPZ<>l@%+%&~d`DQMH?6 zCQG-r;8~R|Ed5pS)6O@%^SiD5+@|anug;c>`}HS2;M7=E^wcROS-JDugZkBfZ25{; W>hF>Jv<2um1_n=8KbLh*2~7Z1jZanp literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/effortlessbuilding/textures/icons/circle_start_corner.png b/src/main/resources/assets/effortlessbuilding/textures/icons/circle_start_corner.png new file mode 100644 index 0000000000000000000000000000000000000000..f64e3eb6050980c2e9ed953a236548a032a55995 GIT binary patch literal 222 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)1F==&(na6DY!2;1OBO zz`(a3gc&VZgH?cn>?NMQuI!I_SoqbfBqWv;0)?_YT^vI!PT!q$oAZDHhim`R(dJkFL|+DhhAETWc`ef!Eaz^#rgh!kz&QWx!uvZlcU@%({}C^}DN1@%+L5<2fYvg2 My85}Sb4q9e0JNh>TL1t6 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/effortlessbuilding/textures/icons/cylinder.png b/src/main/resources/assets/effortlessbuilding/textures/icons/cylinder.png new file mode 100644 index 0000000000000000000000000000000000000000..4964d3312fd8f12ce89f1130c00946a098b8320c GIT binary patch literal 292 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE({An@NE9d0-y+Ifk$L9 z0|VcF5N5Ps4ORgPvX^-Jy0Sm!Vd3YNd1YUn3>4bv>Eak-aeC?GgS;&YA};dww;M_p zvQ|FH(hO>sz0v(}`eV5=#S@FP3-kW`naRVGY~gtSdv#q{Xz*?0^dka?676^nFAY%o z@BGrIq9fcgVj3&M^E-+Aa&Ox#+vdLal9{r;u2sNEXku8A z<|hl*lkxjl4MjB{XDc#yta`LJzs#UddDXAN3tB=a?NfibZDv06x#ow*Ws{{$Zbe&r hmj>LsGe_bho3T&oL&mw;FMy6`@O1TaS?83{1OTpbZG8X$ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/effortlessbuilding/textures/icons/sphere.png b/src/main/resources/assets/effortlessbuilding/textures/icons/sphere.png new file mode 100644 index 0000000000000000000000000000000000000000..73a804a5fb566ebaa244032d36d5dd7cc766ce29 GIT binary patch literal 361 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE({An@NE9d0-y+Ifk$L9 z0|VcF5N5Ps4ORgPvX^-Jy0Sm!Vd3Xy_-CiC0~Gq^>Eak-aeD4#+f^+FBCY!^F0<>h z2McFjHiS!Z3k zlG>Z!cFWQw+RP_#9F4sm7%Cd%#V{pE{eVRu`w3?k9~rLM%Pg;5Hj!1}_dF!NWJ*e; znCS6u4E-OzZqo6*{AI_P&wqS3NsBVr&+S})JMQ||drj{j-4-fW{B&RP*3Iv-*}CU;Dzl&0zG&G##pqV2xODQ4 z-cA3*bP0l+XkK DZWWN$ literal 0 HcmV?d00001