2021-05-11 20:02:43 +02:00
|
|
|
package com.jozufozu.flywheel.util;
|
2021-03-08 09:36:23 +01:00
|
|
|
|
2021-04-30 09:31:52 +02:00
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
|
|
import com.mojang.math.Matrix4f;
|
|
|
|
import com.mojang.math.Vector3f;
|
2021-03-08 09:36:23 +01:00
|
|
|
|
2021-11-18 23:59:39 +01:00
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
|
2021-03-08 09:36:23 +01:00
|
|
|
public class RenderUtil {
|
2021-07-18 02:05:49 +02:00
|
|
|
|
|
|
|
private static final Matrix4f IDENTITY = new Matrix4f();
|
|
|
|
static {
|
|
|
|
IDENTITY.setIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Matrix4f getIdentity() {
|
|
|
|
return IDENTITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Matrix4f copyIdentity() {
|
|
|
|
return IDENTITY.copy();
|
|
|
|
}
|
|
|
|
|
2021-04-28 09:01:26 +02:00
|
|
|
public static int nextPowerOf2(int a) {
|
2021-03-23 04:20:52 +01:00
|
|
|
int h = Integer.highestOneBit(a);
|
|
|
|
return (h == a) ? h : (h << 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isPowerOf2(int n) {
|
|
|
|
int b = n & (n - 1);
|
|
|
|
return b == 0 && n != 0;
|
|
|
|
}
|
|
|
|
|
2021-04-28 09:01:26 +02:00
|
|
|
public static double lengthSqr(double x, double y, double z) {
|
|
|
|
return x * x + y * y + z * z;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double length(double x, double y, double z) {
|
|
|
|
return Math.sqrt(lengthSqr(x, y, z));
|
|
|
|
}
|
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
public static Supplier<PoseStack> rotateToFace(Direction facing) {
|
2021-04-30 09:31:52 +02:00
|
|
|
return () -> {
|
2021-09-15 08:45:29 +02:00
|
|
|
PoseStack stack = new PoseStack();
|
2021-06-30 21:43:54 +02:00
|
|
|
// MatrixStacker.of(stack)
|
|
|
|
// .centre()
|
|
|
|
// .rotateY(AngleHelper.horizontalAngle(facing))
|
|
|
|
// .rotateX(AngleHelper.verticalAngle(facing))
|
|
|
|
// .unCentre();
|
2021-07-15 20:36:24 +02:00
|
|
|
stack.last()
|
|
|
|
.pose()
|
2021-06-30 21:43:54 +02:00
|
|
|
.setTranslation(0.5f, 0.5f, 0.5f);
|
2021-07-15 20:36:24 +02:00
|
|
|
stack.mulPose(Vector3f.YP.rotationDegrees(AngleHelper.horizontalAngle(facing)));
|
|
|
|
stack.mulPose(Vector3f.XP.rotationDegrees(AngleHelper.verticalAngle(facing)));
|
2021-05-11 20:02:43 +02:00
|
|
|
stack.translate(-0.5f, -0.5f, -0.5f);
|
2021-04-30 09:31:52 +02:00
|
|
|
return stack;
|
|
|
|
};
|
|
|
|
}
|
2021-03-08 09:36:23 +01:00
|
|
|
}
|