From a00eec402ebe2538380de2edbe0dbca6a09a6540 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Mar 2019 16:32:04 -0700 Subject: [PATCH] i love retina wtf --- src/main/java/baritone/utils/GuiClick.java | 392 ++++++++++----------- 1 file changed, 196 insertions(+), 196 deletions(-) diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java index f0a3eb9a6..7eca85b98 100644 --- a/src/main/java/baritone/utils/GuiClick.java +++ b/src/main/java/baritone/utils/GuiClick.java @@ -58,8 +58,8 @@ public class GuiClick extends GuiScreen { double mx = mc.mouseHelper.getMouseX(); double my = mc.mouseHelper.getMouseY(); my = mc.mainWindow.getHeight() - my; - my *= 2; - mx *= 2; + my *= mc.mainWindow.getFramebufferHeight() / (double) mc.mainWindow.getHeight(); + mx *= mc.mainWindow.getFramebufferWidth() / (double) mc.mainWindow.getWidth(); Vec3d near = toWorld(mx, my, 0); Vec3d far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - leijurv if (near != null && far != null) { @@ -100,221 +100,221 @@ public class GuiClick extends GuiScreen { GlStateManager.getFloatv(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear()); GL11.glGetIntegerv(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear()); - if (currentMouseOver != null) { - Entity e = mc.getRenderViewEntity(); - // drawSingleSelectionBox WHEN? - PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(currentMouseOver), Color.CYAN); - if (clickStart != null && !clickStart.equals(currentMouseOver)) { - GlStateManager.enableBlend(); - GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); - GlStateManager.color4f(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F); - GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(false); - GlStateManager.disableDepthTest(); - BetterBlockPos a = new BetterBlockPos(currentMouseOver); - BetterBlockPos b = new BetterBlockPos(clickStart); - PathRenderer.drawAABB(new AxisAlignedBB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1)); - GlStateManager.enableDepthTest(); - - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } - } - - - } - - public Vec3d toWorld ( double x, double y, double z){ - boolean result = gluUnProject((float) x, (float) y, (float) z, MODELVIEW, PROJECTION, VIEWPORT, (FloatBuffer) TO_WORLD_BUFFER.clear()); - if (result) { - return new Vec3d(TO_WORLD_BUFFER.get(0), TO_WORLD_BUFFER.get(1), TO_WORLD_BUFFER.get(2)); - } - return null; - } - - // skidded from lwjgl2 :ok_hand: - // its uhhhhh mit license so its ok - // here is the uhh license - /* - * Copyright (c) 2002-2007 Lightweight Java Game Library Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'Light Weight Java Game Library' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - public static boolean gluUnProject ( - float winx, - float winy, - float winz, - FloatBuffer modelMatrix, - FloatBuffer projMatrix, - IntBuffer viewport, - FloatBuffer obj_pos){ - FloatBuffer finalMatrix = BufferUtils.createFloatBuffer(16); - float[] in = new float[4]; - float[] out = new float[4]; - - __gluMultMatricesf(modelMatrix, projMatrix, finalMatrix); - - if (!__gluInvertMatrixf(finalMatrix, finalMatrix)) - return false; - - in[0] = winx; - in[1] = winy; - in[2] = winz; - in[3] = 1.0f; - - // Map x and y from window coordinates - in[0] = (in[0] - viewport.get(viewport.position() + 0)) / viewport.get(viewport.position() + 2); - in[1] = (in[1] - viewport.get(viewport.position() + 1)) / viewport.get(viewport.position() + 3); - - // Map to range -1 to 1 - in[0] = in[0] * 2 - 1; - in[1] = in[1] * 2 - 1; - in[2] = in[2] * 2 - 1; - - __gluMultMatrixVecf(finalMatrix, in, out); - - if (out[3] == 0.0) - return false; - - out[3] = 1.0f / out[3]; - - obj_pos.put(obj_pos.position() + 0, out[0] * out[3]); - obj_pos.put(obj_pos.position() + 1, out[1] * out[3]); - obj_pos.put(obj_pos.position() + 2, out[2] * out[3]); - - return true; - } - - private static void __gluMultMatrixVecf (FloatBuffer m,float[] in, float[] out){ - for (int i = 0; i < 4; i++) { - out[i] = - in[0] * m.get(m.position() + 0 * 4 + i) - + in[1] * m.get(m.position() + 1 * 4 + i) - + in[2] * m.get(m.position() + 2 * 4 + i) - + in[3] * m.get(m.position() + 3 * 4 + i); + if (currentMouseOver != null) { + Entity e = mc.getRenderViewEntity(); + // drawSingleSelectionBox WHEN? + PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(currentMouseOver), Color.CYAN); + if (clickStart != null && !clickStart.equals(currentMouseOver)) { + GlStateManager.enableBlend(); + GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); + GlStateManager.color4f(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F); + GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + GlStateManager.disableDepthTest(); + BetterBlockPos a = new BetterBlockPos(currentMouseOver); + BetterBlockPos b = new BetterBlockPos(clickStart); + PathRenderer.drawAABB(new AxisAlignedBB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1)); + GlStateManager.enableDepthTest(); + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); } } - private static void __gluMultMatricesf (FloatBuffer a, FloatBuffer b, FloatBuffer r){ - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - r.put(r.position() + i * 4 + j, - a.get(a.position() + i * 4 + 0) * b.get(b.position() + 0 * 4 + j) + a.get(a.position() + i * 4 + 1) * b.get(b.position() + 1 * 4 + j) + a.get(a.position() + i * 4 + 2) * b.get(b.position() + 2 * 4 + j) + a.get(a.position() + i * 4 + 3) * b.get(b.position() + 3 * 4 + j)); - } + + } + + public Vec3d toWorld(double x, double y, double z) { + boolean result = gluUnProject((float) x, (float) y, (float) z, MODELVIEW, PROJECTION, VIEWPORT, (FloatBuffer) TO_WORLD_BUFFER.clear()); + if (result) { + return new Vec3d(TO_WORLD_BUFFER.get(0), TO_WORLD_BUFFER.get(1), TO_WORLD_BUFFER.get(2)); + } + return null; + } + + // skidded from lwjgl2 :ok_hand: + // its uhhhhh mit license so its ok + // here is the uhh license + /* + * Copyright (c) 2002-2007 Lightweight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + public static boolean gluUnProject( + float winx, + float winy, + float winz, + FloatBuffer modelMatrix, + FloatBuffer projMatrix, + IntBuffer viewport, + FloatBuffer obj_pos) { + FloatBuffer finalMatrix = BufferUtils.createFloatBuffer(16); + float[] in = new float[4]; + float[] out = new float[4]; + + __gluMultMatricesf(modelMatrix, projMatrix, finalMatrix); + + if (!__gluInvertMatrixf(finalMatrix, finalMatrix)) + return false; + + in[0] = winx; + in[1] = winy; + in[2] = winz; + in[3] = 1.0f; + + // Map x and y from window coordinates + in[0] = (in[0] - viewport.get(viewport.position() + 0)) / viewport.get(viewport.position() + 2); + in[1] = (in[1] - viewport.get(viewport.position() + 1)) / viewport.get(viewport.position() + 3); + + // Map to range -1 to 1 + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecf(finalMatrix, in, out); + + if (out[3] == 0.0) + return false; + + out[3] = 1.0f / out[3]; + + obj_pos.put(obj_pos.position() + 0, out[0] * out[3]); + obj_pos.put(obj_pos.position() + 1, out[1] * out[3]); + obj_pos.put(obj_pos.position() + 2, out[2] * out[3]); + + return true; + } + + private static void __gluMultMatrixVecf(FloatBuffer m, float[] in, float[] out) { + for (int i = 0; i < 4; i++) { + out[i] = + in[0] * m.get(m.position() + 0 * 4 + i) + + in[1] * m.get(m.position() + 1 * 4 + i) + + in[2] * m.get(m.position() + 2 * 4 + i) + + in[3] * m.get(m.position() + 3 * 4 + i); + + } + } + + private static void __gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + r.put(r.position() + i * 4 + j, + a.get(a.position() + i * 4 + 0) * b.get(b.position() + 0 * 4 + j) + a.get(a.position() + i * 4 + 1) * b.get(b.position() + 1 * 4 + j) + a.get(a.position() + i * 4 + 2) * b.get(b.position() + 2 * 4 + j) + a.get(a.position() + i * 4 + 3) * b.get(b.position() + 3 * 4 + j)); } } + } - private static boolean __gluInvertMatrixf (FloatBuffer src, FloatBuffer inverse){ - int i, j, k, swap; - float t; - FloatBuffer temp = BufferUtils.createFloatBuffer(16); + private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) { + int i, j, k, swap; + float t; + FloatBuffer temp = BufferUtils.createFloatBuffer(16); - for (i = 0; i < 16; i++) { - temp.put(i, src.get(i + src.position())); - } - __gluMakeIdentityf(inverse); + for (i = 0; i < 16; i++) { + temp.put(i, src.get(i + src.position())); + } + __gluMakeIdentityf(inverse); - for (i = 0; i < 4; i++) { + for (i = 0; i < 4; i++) { + /* + * * Look for largest element in column + */ + swap = i; + for (j = i + 1; j < 4; j++) { /* - * * Look for largest element in column + * if (fabs(temp[j][i]) > fabs(temp[i][i])) { swap = j; */ - swap = i; - for (j = i + 1; j < 4; j++) { - /* - * if (fabs(temp[j][i]) > fabs(temp[i][i])) { swap = j; - */ - if (Math.abs(temp.get(j * 4 + i)) > Math.abs(temp.get(i * 4 + i))) { - swap = j; - } + if (Math.abs(temp.get(j * 4 + i)) > Math.abs(temp.get(i * 4 + i))) { + swap = j; } + } - if (swap != i) { - /* - * * Swap rows. - */ - for (k = 0; k < 4; k++) { - t = temp.get(i * 4 + k); - temp.put(i * 4 + k, temp.get(swap * 4 + k)); - temp.put(swap * 4 + k, t); - - t = inverse.get(i * 4 + k); - inverse.put(i * 4 + k, inverse.get(swap * 4 + k)); - //inverse.put((i << 2) + k, inverse.get((swap << 2) + k)); - inverse.put(swap * 4 + k, t); - //inverse.put((swap << 2) + k, t); - } - } - - if (temp.get(i * 4 + i) == 0) { - /* - * * No non-zero pivot. The matrix is singular, which shouldn't * - * happen. This means the user gave us a bad matrix. - */ - return false; - } - - t = temp.get(i * 4 + i); + if (swap != i) { + /* + * * Swap rows. + */ for (k = 0; k < 4; k++) { - temp.put(i * 4 + k, temp.get(i * 4 + k) / t); - inverse.put(i * 4 + k, inverse.get(i * 4 + k) / t); + t = temp.get(i * 4 + k); + temp.put(i * 4 + k, temp.get(swap * 4 + k)); + temp.put(swap * 4 + k, t); + + t = inverse.get(i * 4 + k); + inverse.put(i * 4 + k, inverse.get(swap * 4 + k)); + //inverse.put((i << 2) + k, inverse.get((swap << 2) + k)); + inverse.put(swap * 4 + k, t); + //inverse.put((swap << 2) + k, t); } - for (j = 0; j < 4; j++) { - if (j != i) { - t = temp.get(j * 4 + i); - for (k = 0; k < 4; k++) { - temp.put(j * 4 + k, temp.get(j * 4 + k) - temp.get(i * 4 + k) * t); - inverse.put(j * 4 + k, inverse.get(j * 4 + k) - inverse.get(i * 4 + k) * t); + } + + if (temp.get(i * 4 + i) == 0) { + /* + * * No non-zero pivot. The matrix is singular, which shouldn't * + * happen. This means the user gave us a bad matrix. + */ + return false; + } + + t = temp.get(i * 4 + i); + for (k = 0; k < 4; k++) { + temp.put(i * 4 + k, temp.get(i * 4 + k) / t); + inverse.put(i * 4 + k, inverse.get(i * 4 + k) / t); + } + for (j = 0; j < 4; j++) { + if (j != i) { + t = temp.get(j * 4 + i); + for (k = 0; k < 4; k++) { + temp.put(j * 4 + k, temp.get(j * 4 + k) - temp.get(i * 4 + k) * t); + inverse.put(j * 4 + k, inverse.get(j * 4 + k) - inverse.get(i * 4 + k) * t); /*inverse.put( (j << 2) + k, inverse.get((j << 2) + k) - inverse.get((i << 2) + k) * t);*/ - } } } } - return true; - } - - private static final float[] IDENTITY_MATRIX = - new float[]{ - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f}; - - private static void __gluMakeIdentityf (FloatBuffer m){ - int oldPos = m.position(); - m.put(IDENTITY_MATRIX); - m.position(oldPos); } + return true; } + + private static final float[] IDENTITY_MATRIX = + new float[]{ + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f}; + + private static void __gluMakeIdentityf(FloatBuffer m) { + int oldPos = m.position(); + m.put(IDENTITY_MATRIX); + m.position(oldPos); + } +}