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

100 lines
2.1 KiB
Java
Raw Normal View History

2021-05-02 01:32:09 +02:00
package com.jozufozu.flywheel.backend;
2021-03-08 09:36:23 +01:00
import java.util.function.Supplier;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.MatrixStacker;
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;
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) {
return writeMatrixStack(stack.peek().getModel(), stack.peek().getNormal());
}
// GPUs want matrices in column major order.
public static float[] writeMatrixStack(Matrix4f model, Matrix3f normal) {
return new float[]{
model.a00,
model.a10,
model.a20,
model.a30,
model.a01,
model.a11,
model.a21,
model.a31,
model.a02,
model.a12,
model.a22,
model.a32,
model.a03,
model.a13,
model.a23,
model.a33,
normal.a00,
normal.a10,
normal.a20,
normal.a01,
normal.a11,
normal.a21,
normal.a02,
normal.a12,
normal.a22,
};
}
public static float[] writeMatrix(Matrix4f model) {
return new float[]{
model.a00,
model.a10,
model.a20,
model.a30,
model.a01,
model.a11,
model.a21,
model.a31,
model.a02,
model.a12,
model.a22,
model.a32,
model.a03,
model.a13,
model.a23,
model.a33,
};
}
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();
return stack;
};
}
2021-03-08 09:36:23 +01:00
}