mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Strange solutions to rotating matter objects
This commit is contained in:
parent
1b96bce44f
commit
a1510ffcb5
23
src/main/java/com/volmit/iris/util/function/Supplier3R.java
Normal file
23
src/main/java/com/volmit/iris/util/function/Supplier3R.java
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.function;
|
||||
|
||||
public interface Supplier3R<T, TT, TTT, TTTT> {
|
||||
TTTT get(T t, TT tt, TTT ttt);
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.util.hunk;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.basic.IrisPosition;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.*;
|
||||
import com.volmit.iris.util.hunk.io.HunkIOAdapter;
|
||||
@ -244,18 +245,6 @@ public interface Hunk<T> {
|
||||
return new InvertedHunkView<T>(this);
|
||||
}
|
||||
|
||||
default Hunk<T> rotateX(double degrees) {
|
||||
return new RotatedXHunkView<T>(this, degrees);
|
||||
}
|
||||
|
||||
default Hunk<T> rotateY(double degrees) {
|
||||
return new RotatedYHunkView<T>(this, degrees);
|
||||
}
|
||||
|
||||
default Hunk<T> rotateZ(double degrees) {
|
||||
return new RotatedZHunkView<T>(this, degrees);
|
||||
}
|
||||
|
||||
default int getMaximumDimension() {
|
||||
return Math.max(getWidth(), Math.max(getHeight(), getDepth()));
|
||||
}
|
||||
@ -1284,7 +1273,34 @@ public interface Hunk<T> {
|
||||
return t;
|
||||
}
|
||||
|
||||
default Hunk<T> rotate(double x, double y, double z)
|
||||
static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z)
|
||||
{
|
||||
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]);
|
||||
return new IrisPosition(maxX - minX, maxY - minY, maxZ - minZ);
|
||||
}
|
||||
|
||||
default Hunk<T> rotate(double x, double y, double z, Supplier3R<Integer, Integer, Integer, Hunk<T>> builder)
|
||||
{
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
@ -1314,7 +1330,7 @@ public interface Hunk<T> {
|
||||
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<T> r = Hunk.newArrayHunk(maxX - minX, maxY - minY, maxZ - minZ);
|
||||
Hunk<T> r = builder.get(maxX - minX, maxY - minY, maxZ - minZ);
|
||||
int[] cr = {(maxX - minX)/2,(maxY - minY)/2,(maxZ - minZ)/2};
|
||||
|
||||
for(i = 0; i < w; i++)
|
||||
|
@ -18,7 +18,9 @@
|
||||
|
||||
package com.volmit.iris.util.matter;
|
||||
|
||||
import com.volmit.iris.engine.object.basic.IrisPosition;
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
|
||||
import java.io.*;
|
||||
@ -177,6 +179,28 @@ public interface Matter {
|
||||
return (MatterSlice<T>) getSlice(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate a matter object into a new object
|
||||
* @param x the x rotation (degrees)
|
||||
* @param y the y rotation (degrees)
|
||||
* @param z the z rotation (degrees)
|
||||
* @return the new rotated matter object
|
||||
*/
|
||||
default Matter rotate(double x, double y, double z)
|
||||
{
|
||||
IrisPosition rs = Hunk.rotatedBounding(getWidth(), getHeight(), getDepth(), x, y, z);
|
||||
Matter n = new IrisMatter(rs.getX(), rs.getY(), rs.getZ());
|
||||
n.getHeader().setAuthor(getHeader().getAuthor());
|
||||
n.getHeader().setCreatedAt(getHeader().getCreatedAt());
|
||||
|
||||
for(Class<?> i : getSliceTypes())
|
||||
{
|
||||
getSlice(i).rotateSliceInto(n, x, y, z);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a slice exists for a given type
|
||||
*
|
||||
|
@ -24,6 +24,7 @@ import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.hunk.storage.MappedHunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -147,4 +148,9 @@ public interface MatterSlice<T> extends Hunk<T> {
|
||||
setRaw(pos[0], pos[1], pos[2], palette.readNode(din));
|
||||
}
|
||||
}
|
||||
|
||||
default void rotateSliceInto(Matter n, double x, double y, double z)
|
||||
{
|
||||
rotate(x,y,z, (_x, _y, _z) -> n.slice(getType()));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user