-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update `worldToScreen` function in monkey way Optimize imports
- Loading branch information
Showing
7 changed files
with
35 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 6 additions & 16 deletions
22
src/main/java/me/qualterz/minecraft/lookaround/ProjectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,25 @@ | ||
package me.qualterz.minecraft.lookaround; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.Camera; | ||
import net.minecraft.client.render.GameRenderer; | ||
import net.minecraft.util.math.*; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
public class ProjectionUtils { | ||
public static Vec3f worldToScreen(Vec3d destination) | ||
public static Vec3d worldToScreen(Vec3d destination) | ||
{ | ||
var client = MinecraftClient.getInstance(); | ||
var renderer = client.gameRenderer; | ||
var camera = renderer.getCamera(); | ||
var position = camera.getPos(); | ||
var rotation = camera.getRotation().copy(); | ||
var rotation = camera.getRotation(); | ||
|
||
rotation.conjugate(); | ||
|
||
var calculation = new Vec3f( | ||
(float) (position.x - destination.getX()), | ||
(float) (position.y - destination.getY()), | ||
(float) (position.z - destination.getZ()) | ||
); | ||
|
||
calculation.transform(new Matrix3f(rotation)); | ||
var calculation = rotation.conjugate().transform(position.subtract(destination).toVector3f()); | ||
|
||
// TODO: use dynamic fov value | ||
var fov = client.options.getFov().getValue(); | ||
|
||
var half = client.getWindow().getScaledHeight() / 2; | ||
var scale = half / (calculation.getZ() * Math.tan(Math.toRadians(fov / 2))); | ||
var scale = half / (calculation.z() * Math.tan(Math.toRadians(fov / 2))); | ||
|
||
return new Vec3f((float) (calculation.getX() * scale), (float) (calculation.getY() * scale), calculation.getZ()); | ||
return new Vec3d((calculation.x() * scale), (calculation.y() * scale), calculation.z()); | ||
} | ||
} |
19 changes: 11 additions & 8 deletions
19
src/main/java/me/qualterz/minecraft/lookaround/mixin/CameraMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
src/main/java/me/qualterz/minecraft/lookaround/mixin/InGameHudMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters