mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Fixed encorrect angles calculated for differing y-positions, and properly skip out calculations when not looking at a block. Closes #123
This commit is contained in:
parent
5ccb81bc11
commit
49f394e367
1 changed files with 32 additions and 12 deletions
|
@ -52,21 +52,36 @@ public class HorseCam {
|
||||||
* B- \
|
* B- \
|
||||||
* |y - \
|
* |y - \
|
||||||
* | - \ Tan(?) = horDist / toHeight
|
* | - \ Tan(?) = horDist / toHeight
|
||||||
* |-------C ? = arcTan(horDist / toHeight);
|
*==|-------C=== ? = arcTan(horDist / toHeight);
|
||||||
* horDist
|
* horDist
|
||||||
|
*
|
||||||
|
* horDist
|
||||||
|
* |-------C
|
||||||
|
* | /.
|
||||||
|
* | /.
|
||||||
|
* | / .
|
||||||
|
* | / .
|
||||||
|
* | / .
|
||||||
|
* |?/ .
|
||||||
|
* A/ .
|
||||||
|
* | .
|
||||||
|
* | .
|
||||||
|
* | .
|
||||||
|
* | .
|
||||||
|
* B
|
||||||
|
* |
|
||||||
|
* |
|
||||||
|
*==o===========
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
PlayerEntity player = client.player;
|
PlayerEntity player = client.player;
|
||||||
|
client.gameRenderer.updateTargetedEntity(1);
|
||||||
HitResult hit = client.hitResult;
|
HitResult hit = client.hitResult;
|
||||||
|
|
||||||
// noop
|
// noop
|
||||||
if (hit == null || player == null) {
|
// Ignore misses, helps with bows, arrows, and projectiles
|
||||||
return originalPitch;
|
if (hit == null || hit.getType() != HitResult.Type.BLOCK || player == null) {
|
||||||
}
|
|
||||||
|
|
||||||
// Small angles aren't worth changing.
|
|
||||||
// Helps with bows, arrows, and projectiles.
|
|
||||||
if (Math.abs(originalPitch) < 2) {
|
|
||||||
return originalPitch;
|
return originalPitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,17 +90,22 @@ public class HorseCam {
|
||||||
|
|
||||||
double diffX = Math.abs(hitPos.x - pos.x);
|
double diffX = Math.abs(hitPos.x - pos.x);
|
||||||
double diffZ = Math.abs(hitPos.z - pos.z);
|
double diffZ = Math.abs(hitPos.z - pos.z);
|
||||||
|
|
||||||
double horDist = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
double horDist = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||||
|
|
||||||
float theta = (float)Math.atan(horDist / toHeight);
|
double toEyePos = pos.y + toHeight;
|
||||||
|
|
||||||
|
double verDist = Math.abs(hitPos.y - toEyePos);
|
||||||
|
|
||||||
|
double theta = Math.atan(horDist / verDist);
|
||||||
|
|
||||||
// convert to degress
|
// convert to degress
|
||||||
theta /= Math.PI / 180;
|
theta /= Math.PI / 180D;
|
||||||
|
|
||||||
// convert to vertical pitch (-90 to 90).
|
// convert to vertical pitch (-90 to 90).
|
||||||
// Preserve up/down direction.
|
// Preserve up/down direction.
|
||||||
float newPitch = (90 - theta) * Math.signum(originalPitch);
|
double newPitch = Math.abs(90 - theta) * Math.signum(originalPitch);
|
||||||
|
|
||||||
return newPitch;
|
return (float)newPitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue