public static void onRender(Matrix4f modelView) {
model.set(modelView);
NametagUtils.projection.set(RenderSystem.getProjectionMatrix());
Utils.set(camera, mc.gameRenderer.getCamera().getPos());
cameraNegated.set(camera);
cameraNegated.negate();
windowScale = mc.getWindow().calculateScaleFactor(1, false);
}
public static boolean to2D(Vector3d pos, double scale) {
return to2D(pos, scale, true);
}
public static boolean to2D(Vector3d pos, double scale, boolean distanceScaling) {
return to2D(pos, scale, distanceScaling, false);
}
public static boolean to2D(Vector3d pos, double scale, boolean distanceScaling, boolean allowBehind) {
Zoom zoom = Modules.get().get(Zoom.class);
NametagUtils.scale = scale * zoom.getScaling();
if (distanceScaling) {
NametagUtils.scale *= getScale(pos);
}
vec4.set(cameraNegated.x + pos.x, cameraNegated.y + pos.y, cameraNegated.z + pos.z, 1);
vec4.mul(model, mmMat4);
mmMat4.mul(projection, pmMat4);
boolean behind = pmMat4.w <= 0.f;
if (behind && !allowBehind) return false;
toScreen(pmMat4);
double x = pmMat4.x * mc.getWindow().getFramebufferWidth();
double y = pmMat4.y * mc.getWindow().getFramebufferHeight();
if (behind) {
x = mc.getWindow().getFramebufferWidth() - x;
y = mc.getWindow().getFramebufferHeight() - y;
}
if (Double.isInfinite(x) || Double.isInfinite(y)) return false;
pos.set(x / windowScale, mc.getWindow().getFramebufferHeight() - y / windowScale, allowBehind ? pmMat4.w : pmMat4.z);
return true;
}