Search in sources :

Example 1 with Vector2d

use of com.enderio.core.common.vecmath.Vector2d in project EnderIO by SleepyTrousers.

the class TravelController method updateSelectedTarget.

@SideOnly(Side.CLIENT)
private void updateSelectedTarget(@Nonnull EntityPlayerSP player) {
    selectedCoord = null;
    if (candidates.isEmpty()) {
        return;
    }
    double closestDistance = Double.MAX_VALUE;
    for (BlockPos bc : candidates.keySet()) {
        if (!bc.equals(onBlockCoord)) {
            double d = addRatio(bc);
            if (d < closestDistance) {
                selectedCoord = bc;
                closestDistance = d;
            }
        }
    }
    if (selectedCoord != null) {
        Vector3d blockCenter = new Vector3d(selectedCoord.getX() + 0.5, selectedCoord.getY() + 0.5, selectedCoord.getZ() + 0.5);
        Vector2d blockCenterPixel = currentView.getScreenPoint(blockCenter);
        Vector2d screenMidPixel = new Vector2d(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
        screenMidPixel.scale(0.5);
        double pixDist = blockCenterPixel.distance(screenMidPixel);
        double rat = pixDist / Minecraft.getMinecraft().displayHeight;
        if (rat != rat) {
            rat = 0;
        }
        if (rat > 0.07) {
            selectedCoord = null;
        }
    }
}
Also used : Vector2d(com.enderio.core.common.vecmath.Vector2d) Vector3d(com.enderio.core.common.vecmath.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with Vector2d

use of com.enderio.core.common.vecmath.Vector2d in project EnderIO by SleepyTrousers.

the class TravelController method addRatio.

private double addRatio(@Nonnull BlockPos bc) {
    Vector2d sp = currentView.getScreenPoint(new Vector3d(bc.getX() + 0.5, bc.getY() + 0.5, bc.getZ() + 0.5));
    Vector2d mid = new Vector2d(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
    mid.scale(0.5);
    double d = sp.distance(mid);
    if (d != d) {
        d = 0f;
    }
    float ratio = (float) d / Minecraft.getMinecraft().displayWidth;
    candidates.put(bc, ratio);
    return d;
}
Also used : Vector2d(com.enderio.core.common.vecmath.Vector2d) Vector3d(com.enderio.core.common.vecmath.Vector3d)

Aggregations

Vector2d (com.enderio.core.common.vecmath.Vector2d)2 Vector3d (com.enderio.core.common.vecmath.Vector3d)2 BlockPos (net.minecraft.util.math.BlockPos)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1