Flywheel/src/main/java/com/jozufozu/flywheel/util/RenderUtil.java

64 lines
2.2 KiB
Java
Raw Normal View History

package com.jozufozu.flywheel.util;
2021-03-08 09:36:23 +01:00
import java.util.function.Supplier;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.util.Direction;
Merge branch 'mc1.15/dev' into mc1.16/dev # Conflicts: # src/generated/resources/.cache/cache # src/generated/resources/assets/create/blockstates/andesite_funnel.json # src/generated/resources/assets/create/blockstates/brass_funnel.json # src/generated/resources/assets/create/lang/unfinished/de_de.json # src/generated/resources/assets/create/lang/unfinished/es_es.json # src/generated/resources/assets/create/lang/unfinished/fr_fr.json # src/generated/resources/assets/create/lang/unfinished/it_it.json # src/generated/resources/assets/create/lang/unfinished/ja_jp.json # src/generated/resources/assets/create/lang/unfinished/ko_kr.json # src/generated/resources/assets/create/lang/unfinished/nl_nl.json # src/generated/resources/assets/create/lang/unfinished/pt_br.json # src/main/java/com/simibubi/create/AllBlocks.java # src/main/java/com/simibubi/create/compat/jei/category/CreateRecipeCategory.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IDisplayAssemblyExceptions.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/LinearChassisBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java # src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java # src/main/java/com/simibubi/create/content/contraptions/particle/RotationIndicatorParticle.java # src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java # src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelFilterSlotPositioning.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelMovementBehaviour.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java # src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPoint.java # src/main/java/com/simibubi/create/content/logistics/item/filter/AbstractFilterScreen.java # src/main/java/com/simibubi/create/content/logistics/item/filter/AttributeFilterScreen.java # src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java # src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java # src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java # src/main/java/com/simibubi/create/events/ClientEvents.java # src/main/java/com/simibubi/create/foundation/block/connected/ConnectedTextureBehaviour.java # src/main/java/com/simibubi/create/foundation/collision/CollisionDebugger.java # src/main/java/com/simibubi/create/foundation/collision/OBBCollider.java # src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java # src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java # src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java # src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java # src/main/java/com/simibubi/create/foundation/gui/AllIcons.java # src/main/java/com/simibubi/create/foundation/gui/widgets/SelectionScrollInput.java # src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java # src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java # src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java # src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java # src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java # src/main/java/com/simibubi/create/foundation/render/backend/Backend.java # src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java # src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java # src/main/java/com/simibubi/create/foundation/utility/ColorHelper.java # src/main/java/com/simibubi/create/foundation/utility/Lang.java # src/main/java/com/simibubi/create/foundation/utility/MatrixStacker.java # src/main/java/com/simibubi/create/foundation/utility/TreeCutter.java # src/main/java/com/simibubi/create/foundation/utility/VecHelper.java # src/main/java/com/simibubi/create/foundation/utility/placement/IPlacementHelper.java # src/main/java/com/simibubi/create/foundation/utility/placement/util/PoleHelper.java
2021-03-20 12:58:02 +01:00
import net.minecraft.util.math.vector.Matrix3f;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3f;
2021-03-08 09:36:23 +01:00
public class RenderUtil {
public static int nextPowerOf2(int a) {
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;
}
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));
}
public static float[] writeMatrixStack(MatrixStack stack) {
2021-07-15 20:36:24 +02:00
return writeMatrixStack(stack.last()
.pose(), stack.last()
.normal());
}
// GPUs want matrices in column major order.
public static float[] writeMatrixStack(Matrix4f model, Matrix3f normal) {
2021-07-15 20:36:24 +02:00
return new float[]{model.m00, model.m10, model.m20, model.m30, model.m01, model.m11, model.m21, model.m31, model.m02, model.m12, model.m22, model.m32, model.m03, model.m13, model.m23, model.m33, normal.m00, normal.m10, normal.m20, normal.m01, normal.m11, normal.m21, normal.m02, normal.m12, normal.m22,};
}
public static float[] writeMatrix(Matrix4f model) {
2021-07-15 20:36:24 +02:00
return new float[]{model.m00, model.m10, model.m20, model.m30, model.m01, model.m11, model.m21, model.m31, model.m02, model.m12, model.m22, model.m32, model.m03, model.m13, model.m23, model.m33,};
}
public static Supplier<MatrixStack> rotateToFace(Direction facing) {
return () -> {
MatrixStack stack = new MatrixStack();
// MatrixStacker.of(stack)
// .centre()
// .rotateY(AngleHelper.horizontalAngle(facing))
// .rotateX(AngleHelper.verticalAngle(facing))
// .unCentre();
2021-07-15 20:36:24 +02:00
stack.last()
.pose()
.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)));
stack.translate(-0.5f, -0.5f, -0.5f);
return stack;
};
}
2021-03-08 09:36:23 +01:00
}