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.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.client.event.ViewportEvent;
|
|
||||||
import net.minecraftforge.fml.ModList;
|
import net.minecraftforge.fml.ModList;
|
||||||
import net.minecraftforge.fml.loading.FMLPaths;
|
import net.minecraftforge.fml.loading.FMLPaths;
|
||||||
import net.montoyo.wd.WebDisplays;
|
import net.montoyo.wd.WebDisplays;
|
||||||
|
|
@ -287,11 +286,9 @@ public class GuiKeyboard extends WDScreen {
|
||||||
protected void mouse(double mouseX, double mouseY, Consumer<Vector2i> func) {
|
protected void mouse(double mouseX, double mouseY, Consumer<Vector2i> func) {
|
||||||
float pct = Minecraft.getInstance().getPartialTick();
|
float pct = Minecraft.getInstance().getPartialTick();
|
||||||
|
|
||||||
ViewportEvent.ComputeFov fov = new ViewportEvent.ComputeFov(
|
double fov = Minecraft.getInstance().gameRenderer.getFov(
|
||||||
Minecraft.getInstance().gameRenderer,
|
|
||||||
Minecraft.getInstance().getEntityRenderDispatcher().camera,
|
Minecraft.getInstance().getEntityRenderDispatcher().camera,
|
||||||
pct, Minecraft.getInstance().options.fov().get(),
|
pct, true
|
||||||
true
|
|
||||||
);
|
);
|
||||||
|
|
||||||
mouseX /= width;
|
mouseX /= width;
|
||||||
|
|
@ -301,7 +298,7 @@ public class GuiKeyboard extends WDScreen {
|
||||||
mouseY -= 0.5;
|
mouseY -= 0.5;
|
||||||
mouseY = -mouseY;
|
mouseY = -mouseY;
|
||||||
|
|
||||||
Matrix4f proj = Minecraft.getInstance().gameRenderer.getProjectionMatrix(fov.getFOV());
|
Matrix4f proj = Minecraft.getInstance().gameRenderer.getProjectionMatrix(fov);
|
||||||
|
|
||||||
Entity e = Minecraft.getInstance().getEntityRenderDispatcher().camera.getEntity();
|
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.XP.rotationDegrees(angle[0]));
|
||||||
camera.mulPose(Axis.YP.rotationDegrees(angle[1] + 180.0F));
|
camera.mulPose(Axis.YP.rotationDegrees(angle[1] + 180.0F));
|
||||||
|
|
||||||
Vector4f coord = new Vector4f(0, 0, 0, 0);
|
Vector4f coord = new Vector4f(2f * (float) mouseX, 2 * (float) mouseY, 0, 1f);
|
||||||
coord.add(proj.invert().transform(new Vector4f(2f * (float) mouseX, 2 * (float) mouseY, 0, 1f)));
|
coord.add(proj.invert().transform(coord));
|
||||||
coord = camera.last().pose().invert().transform(coord);
|
coord = camera.last().pose().invert().transform(coord);
|
||||||
coord.w = 0;
|
|
||||||
coord.normalize();
|
|
||||||
|
|
||||||
Vec3 vec3 = e.getEyePosition(pct);
|
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);
|
BlockHitResult result = tes.trace(side, vec3, vec31);
|
||||||
if (result.getType() != HitResult.Type.MISS) {
|
if (result.getType() != HitResult.Type.MISS) {
|
||||||
|
|
@ -343,6 +338,8 @@ public class GuiKeyboard extends WDScreen {
|
||||||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserDown(tes, side, hit, button));
|
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserDown(tes, side, hit, button));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
KeyboardCamera.setMouse(button, true);
|
||||||
|
|
||||||
return super.mouseClicked(mouseX, mouseY, button);
|
return super.mouseClicked(mouseX, mouseY, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -354,6 +351,8 @@ public class GuiKeyboard extends WDScreen {
|
||||||
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserUp(tes, side, button));
|
WDNetworkRegistry.INSTANCE.sendToServer(C2SMessageScreenCtrl.laserUp(tes, side, button));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
KeyboardCamera.setMouse(button, false);
|
||||||
|
|
||||||
return super.mouseReleased(mouseX, mouseY, button);
|
return super.mouseReleased(mouseX, mouseY, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,10 @@ public class KeyboardCamera {
|
||||||
|
|
||||||
private static double nextX = -1;
|
private static double nextX = -1;
|
||||||
private static double nextY = -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) {
|
protected static Vec2 pxToHit(ScreenData scr, Vec2 dst) {
|
||||||
float cx, cy;
|
float cx, cy;
|
||||||
|
|
@ -82,14 +86,20 @@ public class KeyboardCamera {
|
||||||
if (scr != null) {
|
if (scr != null) {
|
||||||
Vec2 c;
|
Vec2 c;
|
||||||
|
|
||||||
if (lock.hasFocused()) {
|
if (!mouseStatus[0] && !mouseStatus[1]) {
|
||||||
if (ClientConfig.Input.keyboardCamera) {
|
if (lock.hasFocused()) {
|
||||||
nextX = lock.getX();
|
if (ClientConfig.Input.keyboardCamera) {
|
||||||
nextY = lock.getY();
|
nextX = lock.getX();
|
||||||
|
nextY = lock.getY();
|
||||||
|
|
||||||
c = pxToHit(scr, new Vec2((float) nextX, (float) nextY));
|
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(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;
|
nextX = c.x;
|
||||||
nextY = c.y;
|
nextY = c.y;
|
||||||
|
|
@ -158,6 +168,10 @@ public class KeyboardCamera {
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setMouse(int side, boolean pressed) {
|
||||||
|
mouseStatus[side] = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateCamera(ViewportEvent.ComputeCameraAngles event) {
|
public static void updateCamera(ViewportEvent.ComputeCameraAngles event) {
|
||||||
if (tes == null) {
|
if (tes == null) {
|
||||||
xCrd = -1;
|
xCrd = -1;
|
||||||
|
|
@ -199,6 +213,11 @@ public class KeyboardCamera {
|
||||||
protected static int delay = 8;
|
protected static int delay = 8;
|
||||||
|
|
||||||
public static void gameTick(TickEvent.ClientTickEvent event) {
|
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 (event.phase.equals(TickEvent.Phase.END)) {
|
||||||
if (side == null) {
|
if (side == null) {
|
||||||
delay = 1;
|
delay = 1;
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,8 @@ public-f net.minecraft.world.phys.AABB f_82289_
|
||||||
public-f net.minecraft.world.phys.AABB f_82290_
|
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_82291_
|
||||||
public-f net.minecraft.world.phys.AABB f_82292_
|
public-f net.minecraft.world.phys.AABB f_82292_
|
||||||
public-f net.minecraft.world.phys.AABB f_82293_
|
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