use a proper inverse of hit2px for the coordinate calculation for the keyboard camera
This commit is contained in:
parent
f3f3cff079
commit
84d475d61c
|
|
@ -209,6 +209,7 @@ public class ScreenBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
Vector3f rel = new Vector3f(hitX, hitY, hitZ);
|
Vector3f rel = new Vector3f(hitX, hitY, hitZ);
|
||||||
|
|
||||||
|
// this dot is acting as a "get distance from plane" where the plane is the edge of the screen
|
||||||
float cx = rel.dot(side.right.toFloat()) - 2.f / 16.f;
|
float cx = rel.dot(side.right.toFloat()) - 2.f / 16.f;
|
||||||
float cy = rel.dot(side.up.toFloat()) - 2.f / 16.f;
|
float cy = rel.dot(side.up.toFloat()) - 2.f / 16.f;
|
||||||
float sw = ((float) scr.size.x) - 4.f / 16.f;
|
float sw = ((float) scr.size.x) - 4.f / 16.f;
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,11 @@ import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.client.event.ViewportEvent;
|
import net.minecraftforge.client.event.ViewportEvent;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.montoyo.wd.client.js.WDRouter;
|
import net.montoyo.wd.client.js.WDRouter;
|
||||||
|
import net.montoyo.wd.config.CommonConfig;
|
||||||
import net.montoyo.wd.entity.ScreenBlockEntity;
|
import net.montoyo.wd.entity.ScreenBlockEntity;
|
||||||
import net.montoyo.wd.entity.ScreenData;
|
import net.montoyo.wd.entity.ScreenData;
|
||||||
import net.montoyo.wd.utilities.data.BlockSide;
|
import net.montoyo.wd.utilities.data.BlockSide;
|
||||||
|
import net.montoyo.wd.utilities.data.Rotation;
|
||||||
|
|
||||||
public class KeyboardCamera {
|
public class KeyboardCamera {
|
||||||
private static ScreenBlockEntity tes;
|
private static ScreenBlockEntity tes;
|
||||||
|
|
@ -28,6 +30,52 @@ public class KeyboardCamera {
|
||||||
private static double nextX = -1;
|
private static double nextX = -1;
|
||||||
private static double nextY = -1;
|
private static double nextY = -1;
|
||||||
|
|
||||||
|
protected static Vec2 pxToHit(ScreenData scr, Vec2 dst) {
|
||||||
|
float cx, cy;
|
||||||
|
if (scr.rotation.isVertical) {
|
||||||
|
cy = dst.x;
|
||||||
|
cx = dst.y;
|
||||||
|
} else {
|
||||||
|
cx = dst.x;
|
||||||
|
cy = dst.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
cx /= (float) scr.resolution.x;
|
||||||
|
cy /= (float) scr.resolution.y;
|
||||||
|
|
||||||
|
switch (scr.rotation) {
|
||||||
|
case ROT_270:
|
||||||
|
cx = 1.0f - cx;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ROT_180:
|
||||||
|
cx = 1.0f - cx;
|
||||||
|
cy = 1.0f - cy;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ROT_90:
|
||||||
|
cy = 1.0f - cy;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (side != BlockSide.BOTTOM)
|
||||||
|
cy = 1.0f - cy;
|
||||||
|
|
||||||
|
float swInverse = (((float) scr.size.x) - 4.f / 16.f);
|
||||||
|
float shInverse = (((float) scr.size.y) - 4.f / 16.f);
|
||||||
|
|
||||||
|
cx *= swInverse;
|
||||||
|
cy *= shInverse;
|
||||||
|
|
||||||
|
if(side.right.x > 0 || side.right.z > 0)
|
||||||
|
cx += 1.f;
|
||||||
|
|
||||||
|
if(side == BlockSide.TOP || side == BlockSide.BOTTOM)
|
||||||
|
cy -= 1.f;
|
||||||
|
|
||||||
|
return new Vec2(cx + (2 / 16f), cy + (2 / 16f));
|
||||||
|
}
|
||||||
|
|
||||||
protected static void updateCrd(JsonObject obj) {
|
protected static void updateCrd(JsonObject obj) {
|
||||||
if (obj.getAsJsonPrimitive("exists").getAsBoolean()) {
|
if (obj.getAsJsonPrimitive("exists").getAsBoolean()) {
|
||||||
ScreenData scr = tes.getScreen(side);
|
ScreenData scr = tes.getScreen(side);
|
||||||
|
|
@ -35,16 +83,17 @@ public class KeyboardCamera {
|
||||||
nextX = obj.getAsJsonPrimitive("x").getAsDouble() + obj.getAsJsonPrimitive("w").getAsDouble() / 2;
|
nextX = obj.getAsJsonPrimitive("x").getAsDouble() + obj.getAsJsonPrimitive("w").getAsDouble() / 2;
|
||||||
nextY = obj.getAsJsonPrimitive("y").getAsDouble() + obj.getAsJsonPrimitive("h").getAsDouble() / 2;
|
nextY = obj.getAsJsonPrimitive("y").getAsDouble() + obj.getAsJsonPrimitive("h").getAsDouble() / 2;
|
||||||
|
|
||||||
nextX /= scr.resolution.x;
|
Vec2 c = pxToHit(scr, new Vec2((float) nextX, (float) nextY));
|
||||||
if (nextX > 1 || nextX < 0) {
|
|
||||||
nextX = -1;
|
|
||||||
} else nextX *= scr.size.x;
|
|
||||||
|
|
||||||
nextY /= scr.resolution.y;
|
nextX = c.x;
|
||||||
nextY = 1 - nextY;
|
nextY = c.y;
|
||||||
if (nextY > 1 || nextY < 0) {
|
|
||||||
nextY = -1;
|
// if (side.right.x > 0)
|
||||||
} else nextY *= scr.size.y;
|
// nextX += 1.f;
|
||||||
|
// if (side.right.z > 0)
|
||||||
|
// nextX += 1.f;
|
||||||
|
// if (side == BlockSide.BOTTOM)
|
||||||
|
// nextY -= 1.f;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nextX = -1;
|
nextX = -1;
|
||||||
|
|
@ -132,45 +181,24 @@ futureStart = System.currentTimeMillis();
|
||||||
return; // nothing to do
|
return; // nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xCrd < 0) return;
|
if (xCrd == -1) return;
|
||||||
if (yCrd < 0) return;
|
if (yCrd == -1) return;
|
||||||
|
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
|
||||||
double coxCrd = Mth.lerp(0.5 * event.getPartialTick(), oxCrd, xCrd);
|
double coxCrd = Mth.lerp(0.5 * event.getPartialTick(), oxCrd, xCrd);
|
||||||
double cxCrd = Mth.lerp(0.15 * event.getPartialTick(), xCrd, nxCrd);
|
|
||||||
|
|
||||||
double coyCrd = Mth.lerp(0.5 * event.getPartialTick(), oyCrd, yCrd);
|
double coyCrd = Mth.lerp(0.5 * event.getPartialTick(), oyCrd, yCrd);
|
||||||
|
|
||||||
double focalX = tes.getBlockPos().getX() +
|
double focalX = tes.getBlockPos().getX() +
|
||||||
side.right.x * (coxCrd - 1) + side.up.x * coyCrd;
|
side.right.x * (coxCrd - 1) + side.up.x * coyCrd + Math.abs(side.forward.x) * 0.5;
|
||||||
double focalY = tes.getBlockPos().getY() +
|
double focalY = tes.getBlockPos().getY() +
|
||||||
side.right.y * (coxCrd - 1) + side.up.y * coyCrd;
|
side.right.y * (coxCrd - 1) + side.up.y * coyCrd + Math.abs(side.forward.y) * 0.5;
|
||||||
double focalZ = tes.getBlockPos().getZ() +
|
double focalZ = tes.getBlockPos().getZ() +
|
||||||
side.right.z * (coxCrd - 1) + side.up.z * coyCrd;
|
side.right.z * (coxCrd - 1) + side.up.z * coyCrd + Math.abs(side.forward.z) * 0.5;
|
||||||
|
|
||||||
//// double pct = 1 - event.getPartialTick();
|
focalX += side.forward.x * 0.5f;
|
||||||
// double pct = 1;
|
focalY += side.forward.y * 0.5f;
|
||||||
//// pct = pct / 5 + (1 / 4f);
|
focalZ += side.forward.z * 0.5f;
|
||||||
// focalX = Mth.lerp(pct,
|
|
||||||
// focalX,
|
|
||||||
// tes.getBlockPos().getX() +
|
|
||||||
// side.right.x * (coxCrd - 1) + side.up.x * coyCrd
|
|
||||||
// );
|
|
||||||
// focalY = Mth.lerp(pct,
|
|
||||||
// focalY,
|
|
||||||
// tes.getBlockPos().getY() +
|
|
||||||
// side.right.y * (coxCrd - 1) + side.up.y * coyCrd
|
|
||||||
// );
|
|
||||||
// focalZ = Mth.lerp(pct,
|
|
||||||
// focalZ,
|
|
||||||
// tes.getBlockPos().getZ() +
|
|
||||||
// side.right.z * (coxCrd - 1) + side.up.z * coyCrd
|
|
||||||
// );
|
|
||||||
|
|
||||||
// focalX += side.forward.x * 0.25f;
|
|
||||||
// focalY += side.forward.y * 0.25f;
|
|
||||||
// focalZ += side.forward.z * 0.25f;
|
|
||||||
|
|
||||||
float[] angle = lookAt(
|
float[] angle = lookAt(
|
||||||
event.getCamera().getEntity(),
|
event.getCamera().getEntity(),
|
||||||
|
|
@ -189,8 +217,8 @@ futureStart = System.currentTimeMillis();
|
||||||
Vec2 v2 = new Vec2((float) mx, (float) my);
|
Vec2 v2 = new Vec2((float) mx, (float) my);
|
||||||
v2 = v2.normalized().scale(Mth.sqrt(v2.length()));
|
v2 = v2.normalized().scale(Mth.sqrt(v2.length()));
|
||||||
|
|
||||||
angle[1] += (v2.x - 0.5f) * scl;
|
// angle[1] += (v2.x - 0.5f) * scl;
|
||||||
angle[0] += (v2.y - 0.5f) * scl;
|
// angle[0] += (v2.y - 0.5f) * scl;
|
||||||
|
|
||||||
float xRot = event.getYaw(); // left right
|
float xRot = event.getYaw(); // left right
|
||||||
float yRot = event.getPitch(); // up down
|
float yRot = event.getPitch(); // up down
|
||||||
|
|
@ -248,6 +276,11 @@ futureStart = System.currentTimeMillis();
|
||||||
|
|
||||||
anxx = data.size.x / 2.0;
|
anxx = data.size.x / 2.0;
|
||||||
anxy = data.size.y / 2.0;
|
anxy = data.size.y / 2.0;
|
||||||
|
|
||||||
|
if (nxCrd == -1) {
|
||||||
|
oxCrd = xCrd = nxCrd = anxx;
|
||||||
|
oyCrd = yCrd = nyCrd = anxy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeTask == null)
|
if (activeTask == null)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user