Add storage module tracers, fix tracer destinations when bobbing camera

- also removed an unused var and cleaned up a lil bit of code
This commit is contained in:
rafern 2021-08-21 19:45:16 +01:00
parent 6a99196c02
commit 4b99c4b778
No known key found for this signature in database
GPG Key ID: FE8BE3E64992D5CF
4 changed files with 74 additions and 26 deletions

View File

@ -3,6 +3,7 @@ package me.rigamortis.seppuku.api.util;
import org.lwjgl.BufferUtils;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector4f;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
@ -319,11 +320,13 @@ public final class GLUProjection {
} else {
pitch = -Math.toDegrees(Math.atan2(nuv.cross(uv).length(), nuv.dot(uv)));
}
this.lookVec = this.getRotationVector(yaw, pitch);
//Get modelview matrix and invert it
Matrix4f modelviewMatrix = new Matrix4f();
modelviewMatrix.load(this.modelview.asReadOnlyBuffer());
modelviewMatrix.invert();
//Get look vector (forward) from modelview matrix
Vector4f forward = Matrix4f.transform(modelviewMatrix, new Vector4f(0, 0, -1, 0), null);
this.lookVec = new Vector3D(forward.x, forward.y, forward.z).snormalize();
//Get frustum position
this.frustumPos = new Vector3D(modelviewMatrix.m30, modelviewMatrix.m31, modelviewMatrix.m32);
this.frustum = this.getFrustum(this.frustumPos.x, this.frustumPos.y, this.frustumPos.z, yaw, pitch, fov, 1.0F, displayWidth / displayHeight);
@ -579,6 +582,15 @@ public final class GLUProjection {
return this.lookVec;
}
/**
* Returns the camera position (frustumPos) updated with {@link GLUProjection#updateMatrices(IntBuffer, FloatBuffer, FloatBuffer, double, double)}
*
* @return
*/
public Vector3D getCamPos() {
return this.frustumPos;
}
/**
* Returns a rotated vector with the given yaw and pitch.
*

View File

@ -57,8 +57,6 @@ public final class PortalFinderModule extends Module {
private final List<Vec3d> portals = new CopyOnWriteArrayList<>();
private static final int COLOR = 0xFFFFFFFF;
public PortalFinderModule() {
super("PortalFinder", new String[]{"PortalFinder", "PFinder"}, "Highlights nearby portals.", "NONE", -1, Module.ModuleType.RENDER);
}
@ -79,7 +77,7 @@ public final class PortalFinderModule extends Module {
// Line
if (this.tracer.getValue()) {
RenderUtil.drawLine((float) projection.getX(), (float) projection.getY(), event.getScaledResolution().getScaledWidth() / 2.0f, event.getScaledResolution().getScaledHeight() / 2.0f, this.width.getValue(), ColorUtil.changeAlpha(new Color(this.color.getValue().getRed() / 255.0f, this.color.getValue().getGreen() / 255.0f, this.color.getValue().getBlue() / 255.0f).getRGB(), this.alpha.getValue()));
RenderUtil.drawLine((float) projection.getX(), (float) projection.getY(), event.getScaledResolution().getScaledWidth() / 2.0f, event.getScaledResolution().getScaledHeight() / 2.0f, this.width.getValue(), ColorUtil.changeAlpha(this.color.getValue().getRGB(), this.alpha.getValue()));
}
// Info
@ -103,15 +101,14 @@ public final class PortalFinderModule extends Module {
RenderUtil.begin3D();
for (Vec3d portal : this.portals) {
GlStateManager.pushMatrix();
final boolean bobbing = mc.gameSettings.viewBobbing;
mc.gameSettings.viewBobbing = false;
mc.entityRenderer.setupCameraTransform(event.getPartialTicks(), 0);
final Vec3d forward = new Vec3d(0, 0, 1).rotatePitch(-(float) Math.toRadians(Minecraft.getMinecraft().player.rotationPitch)).rotateYaw(-(float) Math.toRadians(Minecraft.getMinecraft().player.rotationYaw));
// Line
if (this.tracer.getValue()) {
RenderUtil.drawLine3D(forward.x, forward.y + mc.player.getEyeHeight(), forward.z, portal.x - mc.getRenderManager().renderPosX, portal.y - mc.getRenderManager().renderPosY, portal.z - mc.getRenderManager().renderPosZ, this.width.getValue(), ColorUtil.changeAlpha(new Color(this.color.getValue().getRed() / 255.0f, this.color.getValue().getGreen() / 255.0f, this.color.getValue().getBlue() / 255.0f).getRGB(), this.alpha.getValue()));
// need to update modelview matrix or it freaks out when rendering another tracer, not sure why though
// XXX this is done in other places, ctrl+shift+f to other files
RenderUtil.updateModelViewProjectionMatrix();
final GLUProjection.Vector3D forward = GLUProjection.getInstance().getLookVector().sadd(GLUProjection.getInstance().getCamPos());
RenderUtil.drawLine3D(forward.x, forward.y, forward.z, portal.x - mc.getRenderManager().renderPosX, portal.y - mc.getRenderManager().renderPosY, portal.z - mc.getRenderManager().renderPosZ, this.width.getValue(), ColorUtil.changeAlpha(this.color.getValue().getRGB(), this.alpha.getValue()));
}
// Info
@ -122,8 +119,6 @@ public final class PortalFinderModule extends Module {
GlStateManager.enableDepth();
}
mc.gameSettings.viewBobbing = bobbing;
mc.entityRenderer.setupCameraTransform(event.getPartialTicks(), 0);
GlStateManager.popMatrix();
}
RenderUtil.end3D();

View File

@ -16,6 +16,8 @@ import net.minecraft.util.math.Vec3d;
import org.lwjgl.opengl.GL11;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.awt.*;
/**
* Author Seth
* 5/17/2019 @ 8:45 PM.
@ -30,6 +32,11 @@ public final class StorageESPModule extends Module {
public final Value<Boolean> nametag = new Value<Boolean>("Nametag", new String[]{"Nametag", "Tag", "Tags", "Ntag", "name", "names"}, "Renders the name of the drawn storage object.", false);
public final Value<Integer> opacity = new Value<Integer>("Opacity", new String[]{"Opacity", "Transparency", "Alpha"}, "Opacity of the rendered esp.", 128, 0, 255, 1);
public final Value<Boolean> tracer = new Value<Boolean>("Tracer", new String[]{"TracerLine", "trace", "line"}, "Display a tracer line to each storage object.", false);
public final Value<Color> tracerColor = new Value<Color>("TracerColor", new String[]{"TracerColor", "TColor", "TC"}, "Edit the storage object tracer color.", new Color(0, 0, 255));
public final Value<Boolean> tracerStorageColor = new Value<Boolean>("TracerStorageColor", new String[]{"TracerStorageColor", "TStorageColor", "TSColor", "TStorageC", "TSC"}, "Use the storage object's color as the tracer color.", false);
public final Value<Float> tracerWidth = new Value<Float>("TracerWidth", new String[]{"TracerWidth", "TWidth", "TW"}, "Pixel width of each tracer-line.", 0.5f, 0.1f, 5.0f, 0.1f);
public final Value<Integer> tracerAlpha = new Value<Integer>("TracerAlpha", new String[]{"TracerAlpha", "TAlpha", "TA", "TracerOpacity", "TOpacity", "TO"}, "Alpha value for each drawn line.", 255, 1, 255, 1);
private final ICamera camera = new Frustum();
@ -51,8 +58,15 @@ public final class StorageESPModule extends Module {
final float[] bounds = this.convertBounds(bb, event.getScaledResolution().getScaledWidth(), event.getScaledResolution().getScaledHeight());
if (bounds != null) {
if (this.mode.getValue() == Mode.TWO_D) { // 2D
// Box
RenderUtil.drawOutlineRect(bounds[0], bounds[1], bounds[2], bounds[3], 1.5f, ColorUtil.changeAlpha(0xAA000000, this.opacity.getValue()));
RenderUtil.drawOutlineRect(bounds[0] - 0.5f, bounds[1] - 0.5f, bounds[2] + 0.5f, bounds[3] + 0.5f, 0.5f, ColorUtil.changeAlpha(this.getColor(te), this.opacity.getValue()));
RenderUtil.drawOutlineRect(bounds[0] - 0.5f, bounds[1] - 0.5f, bounds[2] + 0.5f, bounds[3] + 0.5f, 0.5f, this.getBoxColor(te));
// Line
if (this.tracer.getValue()) {
final GLUProjection.Projection projection = GLUProjection.getInstance().project((bb.minX + bb.maxX) / 2, (bb.minY + bb.maxY) / 2, (bb.minZ + bb.maxZ) / 2, GLUProjection.ClampMode.NONE, true);
RenderUtil.drawLine((float) projection.getX(), (float) projection.getY(), event.getScaledResolution().getScaledWidth() / 2.0f, event.getScaledResolution().getScaledHeight() / 2.0f, this.tracerWidth.getValue(), this.getTracerColor(te));
}
}
if (this.nametag.getValue()) {
@ -81,8 +95,18 @@ public final class StorageESPModule extends Module {
if (this.isTileStorage(te)) {
final AxisAlignedBB bb = this.boundingBoxForEnt(te);
if (bb != null) {
//RenderUtil.drawFilledBox(bb, ColorUtil.changeAlpha(this.getColor(te), this.opacity.getValue()));
//RenderUtil.drawBoundingBox(bb, 1.5f, ColorUtil.changeAlpha(this.getColor(te), this.opacity.getValue()));
// Line
if (this.tracer.getValue()) {
// need to update modelview matrix or it freaks out when rendering another tracer, not sure why though
// XXX this is done in other places, ctrl+shift+f to other files
RenderUtil.updateModelViewProjectionMatrix();
final GLUProjection.Vector3D forward = GLUProjection.getInstance().getLookVector().sadd(GLUProjection.getInstance().getCamPos());
RenderUtil.drawLine3D(forward.x, forward.y, forward.z, (bb.minX + bb.maxX) / 2, (bb.minY + bb.maxY) / 2, (bb.minZ + bb.maxZ) / 2, this.tracerWidth.getValue(), this.getTracerColor(te));
}
// Box
//RenderUtil.drawFilledBox(bb, this.getBoxColor(te));
//RenderUtil.drawBoundingBox(bb, 1.5f, this.getBoxColor(te));
camera.setPosition(mc.getRenderViewEntity().posX, mc.getRenderViewEntity().posY, mc.getRenderViewEntity().posZ);
if (camera.isBoundingBoxInFrustum(new AxisAlignedBB(bb.minX + mc.getRenderManager().viewerPosX,
@ -91,8 +115,9 @@ public final class StorageESPModule extends Module {
bb.maxX + mc.getRenderManager().viewerPosX,
bb.maxY + mc.getRenderManager().viewerPosY,
bb.maxZ + mc.getRenderManager().viewerPosZ))) {
RenderUtil.drawFilledBox(bb, ColorUtil.changeAlpha(this.getColor(te), this.opacity.getValue()));
RenderUtil.drawBoundingBox(bb, 1.5f, ColorUtil.changeAlpha(this.getColor(te), this.opacity.getValue()));
final int colorWithAlpha = this.getBoxColor(te);
RenderUtil.drawFilledBox(bb, colorWithAlpha);
RenderUtil.drawBoundingBox(bb, 1.5f, colorWithAlpha);
}
}
}
@ -189,7 +214,7 @@ public final class StorageESPModule extends Module {
}
private int getColor(TileEntity te) {
private int getBaseColor(TileEntity te) {
if (te instanceof TileEntityChest) {
return 0xFFFFC417;
}
@ -218,6 +243,22 @@ public final class StorageESPModule extends Module {
return 0xFFFFFFFF;
}
private int getBoxColor(TileEntity te) {
return ColorUtil.changeAlpha(this.getBaseColor(te), this.opacity.getValue());
}
private int getTracerColor(TileEntity te) {
int baseColor;
if (this.tracerStorageColor.getValue()) {
baseColor = this.getBaseColor(te);
}
else {
baseColor = this.tracerColor.getValue().getRGB();
}
return ColorUtil.changeAlpha(baseColor, this.tracerAlpha.getValue());
}
private float[] convertBounds(AxisAlignedBB bb, int width, int height) {
float x = -1;
float y = -1;

View File

@ -4,6 +4,7 @@ import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.event.render.EventRender2D;
import me.rigamortis.seppuku.api.event.render.EventRender3D;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.ColorUtil;
import me.rigamortis.seppuku.api.util.GLUProjection;
import me.rigamortis.seppuku.api.util.MathUtil;
import me.rigamortis.seppuku.api.util.RenderUtil;
@ -51,6 +52,7 @@ public final class TracersModule extends Module {
}
public final Value<Float> width = new Value<Float>("Width", new String[]{"Wid"}, "Pixel width of each tracer-line.", 0.5f, 0.0f, 5.0f, 0.1f);
public final Value<Integer> alpha = new Value<Integer>("Alpha", new String[]{"Alpha", "A", "Opacity", "Op"}, "Alpha value for each drawn line.", 255, 1, 255, 1);
public TracersModule() {
super("Tracers", new String[]{"Trace", "Tracer", "Snapline", "Snaplines"}, "Draws a line to entities", "NONE", -1, ModuleType.RENDER);
@ -88,13 +90,11 @@ public final class TracersModule extends Module {
if (e != null) {
if (this.checkFilter(e)) {
final Vec3d pos = MathUtil.interpolateEntity(e, event.getPartialTicks()).subtract(mc.getRenderManager().renderPosX, mc.getRenderManager().renderPosY, mc.getRenderManager().renderPosZ);
final boolean bobbing = mc.gameSettings.viewBobbing;
mc.gameSettings.viewBobbing = false;
mc.entityRenderer.setupCameraTransform(event.getPartialTicks(), 0);
final Vec3d forward = new Vec3d(0, 0, 1).rotatePitch(-(float) Math.toRadians(Minecraft.getMinecraft().player.rotationPitch)).rotateYaw(-(float) Math.toRadians(Minecraft.getMinecraft().player.rotationYaw));
RenderUtil.drawLine3D(forward.x, forward.y + mc.player.getEyeHeight(), forward.z, pos.x, pos.y, pos.z, this.width.getValue(), this.getColor(e));
mc.gameSettings.viewBobbing = bobbing;
mc.entityRenderer.setupCameraTransform(event.getPartialTicks(), 0);
// need to update modelview matrix or it freaks out when rendering another tracer, not sure why though
// XXX this is done in other places, ctrl+shift+f to other files
RenderUtil.updateModelViewProjectionMatrix();
final GLUProjection.Vector3D forward = GLUProjection.getInstance().getLookVector().sadd(GLUProjection.getInstance().getCamPos());
RenderUtil.drawLine3D(forward.x, forward.y, forward.z, pos.x, pos.y, pos.z, this.width.getValue(), this.getColor(e));
}
}
}
@ -155,7 +155,7 @@ public final class TracersModule extends Module {
}
}
return ret;
return ColorUtil.changeAlpha(ret, this.alpha.getValue());
}
}