From 1b96bce44fe803a8cd1184cef449c1c2c4053918 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Thu, 5 Aug 2021 07:22:56 -0400 Subject: [PATCH] Hunk rotation --- .../volmit/iris/core/command/CommandIris.java | 4 + .../java/com/volmit/iris/util/hunk/Hunk.java | 130 +++++++++++++++++- .../volmit/iris/util/matter/MatterSlice.java | 1 - 3 files changed, 131 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/command/CommandIris.java b/src/main/java/com/volmit/iris/core/command/CommandIris.java index 8ee4fb1f8..9e432fb1d 100644 --- a/src/main/java/com/volmit/iris/core/command/CommandIris.java +++ b/src/main/java/com/volmit/iris/core/command/CommandIris.java @@ -25,9 +25,12 @@ import com.volmit.iris.core.command.studio.CommandIrisStudio; import com.volmit.iris.core.command.what.CommandIrisWhat; import com.volmit.iris.core.command.world.*; import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.plugin.Command; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; +import com.volmit.iris.util.scheduling.J; +import org.bukkit.util.Vector; public class CommandIris extends MortarCommand { @Command @@ -84,6 +87,7 @@ public class CommandIris extends MortarCommand { public boolean handle(VolmitSender sender, String[] args) { sender.sendMessage("Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software"); printHelp(sender); + return true; } diff --git a/src/main/java/com/volmit/iris/util/hunk/Hunk.java b/src/main/java/com/volmit/iris/util/hunk/Hunk.java index f3d877ebd..f868e5839 100644 --- a/src/main/java/com/volmit/iris/util/hunk/Hunk.java +++ b/src/main/java/com/volmit/iris/util/hunk/Hunk.java @@ -28,6 +28,8 @@ import com.volmit.iris.util.interpolation.InterpolationMethod; import com.volmit.iris.util.interpolation.InterpolationMethod3D; import com.volmit.iris.util.interpolation.IrisInterpolation; import com.volmit.iris.util.math.BlockPosition; +import com.volmit.iris.util.math.M; +import com.volmit.iris.util.math.MathHelper; import com.volmit.iris.util.oldnbt.ByteArrayTag; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; @@ -37,6 +39,7 @@ import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; import org.bukkit.generator.ChunkGenerator.BiomeGrid; import org.bukkit.generator.ChunkGenerator.ChunkData; +import org.bukkit.util.Vector; import java.io.File; import java.io.IOException; @@ -990,15 +993,15 @@ public interface Hunk { } default int getCenterX() { - return Math.round(getWidth() / 2); + return (int) Math.floor(getWidth() / 2); } default int getCenterY() { - return Math.round(getHeight() / 2); + return (int) Math.floor(getHeight() / 2); } default int getCenterZ() { - return Math.round(getDepth() / 2); + return (int) Math.floor(getDepth() / 2); } default void fill(T t) { @@ -1280,4 +1283,125 @@ public interface Hunk { return t; } + + default Hunk rotate(double x, double y, double z) + { + int w = getWidth(); + int h = getHeight(); + int d = getDepth(); + int i,j,k; + int[] c = {w/2,h/2,d/2}; + int[] b = {0,0,0}; + int[] iii = {0,0,0}; + int[] aaa = {w,h,d}; + int[] aai = {w,h,0}; + int[] iaa = {0,h,d}; + int[] aia = {w,0,d}; + int[] iai = {0,h,0}; + int[] iia = {0,0,d}; + int[] aii = {w,0,0}; + rotate(x,y,z,iii); + rotate(x,y,z,aaa); + rotate(x,y,z,aai); + rotate(x,y,z,iaa); + rotate(x,y,z,aia); + rotate(x,y,z,iai); + rotate(x,y,z,iia); + rotate(x,y,z,aii); + int maxX = max(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]); + int minX = min(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]); + int maxY = max(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); + int minY = min(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); + int maxZ = max(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); + int minZ = min(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); + Hunk r = Hunk.newArrayHunk(maxX - minX, maxY - minY, maxZ - minZ); + int[] cr = {(maxX - minX)/2,(maxY - minY)/2,(maxZ - minZ)/2}; + + for(i = 0; i < w; i++) + { + for(j = 0; j < h; j++) + { + for(k = 0; k < d; k++) + { + b[0] = i - c[0]; + b[1] = j - c[1]; + b[2] = k - c[2]; + rotate(x, y, z, b); + + try + { + r.set(b[0] + cr[0], b[1] + cr[1], b[2] + cr[2], get(i, j, k)); + } + + catch(Throwable e) + { + + } + } + } + } + + return r; + } + + static int max(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) + { + return Math.max(Math.max(Math.max(a5, a6), Math.max(a7, a8)), Math.max(Math.max(a1, a2), Math.max(a3, a4))); + } + + static int min(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) + { + return Math.min(Math.min(Math.min(a5, a6), Math.min(a7, a8)), Math.min(Math.min(a1, a2), Math.min(a3, a4))); + } + + static void rotate(double x, double y, double z, int[] c) + { + if(x % 360 != 0) + { + rotateAroundX(Math.toRadians(x), c); + } + + if(y % 360 != 0) + { + rotateAroundY(Math.toRadians(y), c); + } + + if(z % 360 != 0) + { + rotateAroundZ(Math.toRadians(z), c); + } + } + + static void rotateAroundX(double a, int[] c) { + rotateAroundX(Math.cos(a), Math.sin(a), c); + } + + static void rotateAroundX(double cos, double sin, int[] c) { + int y = (int) Math.floor(cos * (double)(c[1]+0.5) - sin * (double)(c[2]+0.5)); + int z = (int) Math.floor(sin * (double)(c[1]+0.5) + cos * (double)(c[2]+0.5)); + c[1] = y; + c[2] = z; + } + + static void rotateAroundY(double a, int[] c) { + rotateAroundY(Math.cos(a), Math.sin(a), c); + } + + static void rotateAroundY(double cos, double sin, int[] c) { + int x = (int) Math.floor(cos * (double)(c[0]+0.5) + sin * (double)(c[2]+0.5)); + int z = (int) Math.floor(-sin * (double)(c[0]+0.5) + cos * (double)(c[2]+0.5)); + c[0] = x; + c[2] = z; + } + + static void rotateAroundZ(double a, int[] c) { + rotateAroundZ(Math.cos(a), Math.sin(a), c); + } + + static void rotateAroundZ(double cos, double sin, int[] c) { + int x = (int) Math.floor(cos * (double)(c[0]+0.5) - sin * (double)(c[1]+0.5)); + int y = (int) Math.floor(sin * (double)(c[0]+0.5) + cos * (double)(c[1]+0.5)); + c[0] = x; + c[1] = y; + } } diff --git a/src/main/java/com/volmit/iris/util/matter/MatterSlice.java b/src/main/java/com/volmit/iris/util/matter/MatterSlice.java index b3156d44b..24a266017 100644 --- a/src/main/java/com/volmit/iris/util/matter/MatterSlice.java +++ b/src/main/java/com/volmit/iris/util/matter/MatterSlice.java @@ -18,7 +18,6 @@ package com.volmit.iris.util.matter; -import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.util.data.Varint; import com.volmit.iris.util.hunk.Hunk;