添加wts方法
This commit is contained in:
parent
55a1c9d0bf
commit
dedf86d9e7
1 changed files with 27 additions and 0 deletions
|
@ -2,10 +2,16 @@ package com.atsuishio.superbwarfare.client;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.*;
|
import com.mojang.blaze3d.vertex.*;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
import net.minecraft.client.renderer.culling.Frustum;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class RenderHelper {
|
public class RenderHelper {
|
||||||
|
|
||||||
|
@ -30,4 +36,25 @@ public class RenderHelper {
|
||||||
bufferbuilder.vertex(matrix4f, pX2, pY, pBlitOffset).uv(pMaxU, pMinV).endVertex();
|
bufferbuilder.vertex(matrix4f, pX2, pY, pBlitOffset).uv(pMaxU, pMinV).endVertex();
|
||||||
BufferUploader.drawWithShader(bufferbuilder.end());
|
BufferUploader.drawWithShader(bufferbuilder.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codes based on @Xjqsh
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static Vec3 worldToScreen(Vec3 pos, Vec3 cameraPos) {
|
||||||
|
Minecraft minecraft = Minecraft.getInstance();
|
||||||
|
Frustum frustum = minecraft.levelRenderer.getFrustum();
|
||||||
|
|
||||||
|
Vector3f relativePos = pos.subtract(cameraPos).toVector3f();
|
||||||
|
Vector3f transformedPos = frustum.matrix.transformProject(relativePos.x, relativePos.y, relativePos.z, new Vector3f());
|
||||||
|
|
||||||
|
double scaleFactor = minecraft.getWindow().getGuiScale();
|
||||||
|
float guiScaleMul = 0.5f / (float) scaleFactor;
|
||||||
|
|
||||||
|
Vector3f screenPos = transformedPos.mul(1.0f, -1.0f, 1.0f).add(1.0f, 1.0f, 0.0f)
|
||||||
|
.mul(guiScaleMul * minecraft.getWindow().getWidth(), guiScaleMul * minecraft.getWindow().getHeight(), 1.0f);
|
||||||
|
|
||||||
|
return transformedPos.z < 1.0f ? new Vec3(screenPos.x, screenPos.y, transformedPos.z) : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue