improve keyboard camera
This commit is contained in:
parent
ecb0dcee56
commit
594c4decf3
|
|
@ -17,7 +17,6 @@ import net.minecraft.world.phys.HitResult;
|
|||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.ViewportEvent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import net.montoyo.wd.WebDisplays;
|
||||
|
|
@ -287,11 +286,9 @@ public class GuiKeyboard extends WDScreen {
|
|||
protected void mouse(double mouseX, double mouseY, Consumer<Vector2i> func) {
|
||||
float pct = Minecraft.getInstance().getPartialTick();
|
||||
|
||||
ViewportEvent.ComputeFov fov = new ViewportEvent.ComputeFov(
|
||||
Minecraft.getInstance().gameRenderer,
|
||||
double fov = Minecraft.getInstance().gameRenderer.getFov(
|
||||
Minecraft.getInstance().getEntityRenderDispatcher().camera,
|
||||
pct, Minecraft.getInstance().options.fov().get(),
|
||||
true
|
||||
pct, true
|
||||
);
|
||||
|
||||
mouseX /= width;
|
||||
|
|
@ -301,7 +298,7 @@ public class GuiKeyboard extends WDScreen {
|
|||
mouseY -= 0.5;
|
||||
mouseY = -mouseY;
|
||||
|
||||
Matrix4f proj = Minecraft.getInstance().gameRenderer.getProjectionMatrix(fov.getFOV());
|
||||
Matrix4f proj = Minecraft.getInstance().gameRenderer.getProjectionMatrix(fov);
|
||||
|
||||
Entity e = Minecraft.getInstance().getEntityRenderDispatcher().camera.getEntity();
|
||||
|
||||
|
|
@ -310,14 +307,12 @@ public class GuiKeyboard extends WDScreen {
|
|||
camera.mulPose(Axis.XP.rotationDegrees(angle[0]));
|
||||
camera.mulPose(Axis.YP.rotationDegrees(angle[1] + 180.0F));
|
||||
|
||||
Vector4f coord = new Vector4f(0, 0, 0, 0);
|
||||
coord.add(proj.invert().transform(new Vector4f(2f * (float) mouseX, 2 * (float) mouseY, 0, 1f)));
|
||||
Vector4f coord = new Vector4f(2f * (float) mouseX, 2 * (float) mouseY, 0, 1f);
|
||||
coord.add(proj.invert().transform(coord));
|
||||
coord = camera.last().pose().invert().transform(coord);
|
||||
coord.w = 0;
|
||||
coord.normalize();
|
||||
|
||||
Vec3 vec3 = e.getEyePosition(pct);
|
||||
Vec3 vec31 = new Vec3(coord.x, coord.y, coord.z);
|
||||
Vec3 vec31 = new Vec3(coord.x, coord.y, coord.z).normalize();
|
||||
|
||||
BlockHitResult result = tes.trace(side, vec3, vec31);
|
||||
if (result.getType() != HitResult.Type.MISS) {
|
||||
|
|
@ -343,6 +338,8 @@ public class GuiKeyboard extends WDScreen {
|
|||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserDown(tes, side, hit, button));
|
||||
});
|
||||
|
||||
KeyboardCamera.setMouse(button, true);
|
||||
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
|
|
@ -354,6 +351,8 @@ public class GuiKeyboard extends WDScreen {
|
|||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserUp(tes, side, button));
|
||||
});
|
||||
|
||||
KeyboardCamera.setMouse(button, false);
|
||||
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ public class KeyboardCamera {
|
|||
|
||||
private static double nextX = -1;
|
||||
private static double nextY = -1;
|
||||
private static double focalX = -1;
|
||||
private static double focalY = -1;
|
||||
|
||||
private static final boolean[] mouseStatus = new boolean[2];
|
||||
|
||||
protected static Vec2 pxToHit(ScreenData scr, Vec2 dst) {
|
||||
float cx, cy;
|
||||
|
|
@ -82,6 +86,7 @@ public class KeyboardCamera {
|
|||
if (scr != null) {
|
||||
Vec2 c;
|
||||
|
||||
if (!mouseStatus[0] && !mouseStatus[1]) {
|
||||
if (lock.hasFocused()) {
|
||||
if (ClientConfig.Input.keyboardCamera) {
|
||||
nextX = lock.getX();
|
||||
|
|
@ -90,6 +95,11 @@ public class KeyboardCamera {
|
|||
c = pxToHit(scr, new Vec2((float) nextX, (float) nextY));
|
||||
} else c = new Vec2(scr.size.x / 2f, scr.size.y / 2f);
|
||||
} else c = new Vec2(scr.size.x / 2f, scr.size.y / 2f);
|
||||
// } else c = new Vec2((float) focalX, (float) focalY);
|
||||
} else return;
|
||||
|
||||
focalX = c.x;
|
||||
focalY = c.y;
|
||||
|
||||
nextX = c.x;
|
||||
nextY = c.y;
|
||||
|
|
@ -158,6 +168,10 @@ public class KeyboardCamera {
|
|||
return angle;
|
||||
}
|
||||
|
||||
public static void setMouse(int side, boolean pressed) {
|
||||
mouseStatus[side] = pressed;
|
||||
}
|
||||
|
||||
public static void updateCamera(ViewportEvent.ComputeCameraAngles event) {
|
||||
if (tes == null) {
|
||||
xCrd = -1;
|
||||
|
|
@ -199,6 +213,11 @@ public class KeyboardCamera {
|
|||
protected static int delay = 8;
|
||||
|
||||
public static void gameTick(TickEvent.ClientTickEvent event) {
|
||||
if (mouseStatus[0] || mouseStatus[1]) {
|
||||
oxCrd = Mth.lerp(0.5, oxCrd, xCrd);
|
||||
oyCrd = Mth.lerp(0.5, oyCrd, yCrd);
|
||||
return;
|
||||
}
|
||||
if (event.phase.equals(TickEvent.Phase.END)) {
|
||||
if (side == null) {
|
||||
delay = 1;
|
||||
|
|
|
|||
|
|
@ -8,3 +8,7 @@ public-f net.minecraft.world.phys.AABB f_82290_
|
|||
public-f net.minecraft.world.phys.AABB f_82291_
|
||||
public-f net.minecraft.world.phys.AABB f_82292_
|
||||
public-f net.minecraft.world.phys.AABB f_82293_
|
||||
|
||||
|
||||
# GameRenderer
|
||||
public net.minecraft.client.renderer.GameRenderer m_109141_(Lnet/minecraft/client/Camera;FZ)D # getFov
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user