Skip to content

Commit

Permalink
Change way to render esp's using planes instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
GT3CH1 committed Mar 22, 2023
1 parent 48bb195 commit 633c874
Showing 1 changed file with 47 additions and 55 deletions.
102 changes: 47 additions & 55 deletions src/main/kotlin/com/peasenet/util/RenderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ object RenderUtils {
*/
@JvmOverloads
fun renderSingleLine(
stack: MatrixStack,
buffer: VertexConsumer,
playerPos: Vec3d,
boxPos: Vec3d,
color: Color,
alpha: Float = 1f
stack: MatrixStack, buffer: VertexConsumer, playerPos: Vec3d, boxPos: Vec3d, color: Color, alpha: Float = 1f
) {
val normal =
Vec3d(boxPos.getX() - playerPos.getX(), boxPos.getY() - playerPos.getY(), boxPos.getZ() - playerPos.getZ())
Expand Down Expand Up @@ -225,32 +220,29 @@ object RenderUtils {
val x2 = aabb.maxX.toFloat()
val y2 = aabb.maxY.toFloat()
val z2 = aabb.maxZ.toFloat()
val r = c.red
val g = c.green
val b = c.blue
val matrix4f = stack!!.peek().positionMatrix
val color = c.getAsInt(alpha)
stack.push()
renderCorner(buffer!!, matrix4f, x1, x2, y1, y2, z1, z2, color)
renderCorner(buffer, matrix4f, x2, x1, y2, y1, z1, z2, color)
renderCorner(buffer, matrix4f, x1, x2, y2, y1, z2, z1, color)
renderCorner(buffer, matrix4f, x2, x1, y1, y2, z2, z1, color)
renderPlane(buffer!!, matrix4f, x1, x2, y1, y1, z1, z2, color)
renderPlane(buffer, matrix4f, x2, x2, y1, y2, z1, z2, color)
renderPlane(buffer, matrix4f, x1, x2, y2, y2, z1, z2, color)
renderPlane(buffer, matrix4f, x1, x1, y1, y2, z1, z2, color)
stack.pop()
}

/**
* Renders a corner of a box with the given coordinates.
* Renders a 2 dimensional plane.
* @param buffer The buffer to write to.
* @param matrix4f The matrix to use.
* @param x1 The x coordinate of the first vertex.
* @param x2 The x coordinate of the second vertex.
* @param y1 The y coordinate of the first vertex.
* @param y2 The y coordinate of the second vertex.
* @param z1 The z coordinate of the first vertex.
* @param z2 The z coordinate of the second vertex.
* @param c The color to draw the box in.
* @param x1 The first x coordinate.
* @param x2 The second x coordinate.
* @param y1 The first y coordinate.
* @param y2 The second y coordinate.
* @param z1 The first z coordinate.
* @param z2 The second z coordinate.
* @param c The color to draw the plane in.
*/
private fun renderCorner(
private fun renderPlane(
buffer: BufferBuilder,
matrix4f: Matrix4f,
x1: Float,
Expand All @@ -261,43 +253,43 @@ object RenderUtils {
z2: Float,
c: Int
) {
buffer.vertex(matrix4f, x1, y1, z1).color(c).next()
buffer.vertex(matrix4f, x2, y1, z1).color(c).next()
if (x1 == x2) {
buffer.vertex(matrix4f, x1, y1, z1).color(c).next();
buffer.vertex(matrix4f, x1, y2, z1).color(c).next();

buffer.vertex(matrix4f, x1, y2, z1).color(c).next();
buffer.vertex(matrix4f, x1, y2, z2).color(c).next();

buffer.vertex(matrix4f, x1, y2, z2).color(c).next();
buffer.vertex(matrix4f, x1, y1, z2).color(c).next();

buffer.vertex(matrix4f, x1, y1, z1).color(c).next()
buffer.vertex(matrix4f, x1, y1, z2).color(c).next()
buffer.vertex(matrix4f, x1, y1, z2).color(c).next();
buffer.vertex(matrix4f, x1, y1, z1).color(c).next();
} else if (z1 == z2) {
buffer.vertex(matrix4f, x1, y1, z1).color(c).next();
buffer.vertex(matrix4f, x2, y1, z1).color(c).next();

buffer.vertex(matrix4f, x1, y1, z1).color(c).next()
buffer.vertex(matrix4f, x1, y2, z1).color(c).next()
buffer.vertex(matrix4f, x2, y1, z1).color(c).next();
buffer.vertex(matrix4f, x2, y2, z1).color(c).next();

buffer.vertex(matrix4f, x2, y2, z1).color(c).next();
buffer.vertex(matrix4f, x1, y2, z1).color(c).next();

// buffer.vertex(matrix4f, x1, y1, z1).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x2, y1, z1).color(r, g, b, alpha).next()
//
// buffer.vertex(matrix4f, x2, y1, z1).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x2, y1, z2).color(r, g, b, alpha).next()
//
// buffer.vertex(matrix4f, x2, y1, z2).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x1, y1, z2).color(r, g, b, alpha).next()
//
// buffer.vertex(matrix4f, x1, y1, z2).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x1, y1, z1).color(r, g, b, alpha).next()
//
// buffer.vertex(matrix4f, x1, y1, z1).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x1, y2, z1).color(r, g, b, alpha).next()
//
// buffer.vertex(matrix4f, x1, y2, z1).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x2, y2, z1).color(r, g, b, alpha).next()
//
//
// buffer.vertex(matrix4f, x2, y2, z2).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x2, y1, z2).color(r, g, b, alpha).next()
//
// buffer.vertex(matrix4f, x2, y1, z2).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x2, y1, z1).color(r, g, b, alpha).next()
//
// buffer.vertex(matrix4f, x2, y1, z1).color(r, g, b, alpha).next()
// buffer.vertex(matrix4f, x1, y1, z1).color(r, g, b, alpha).next()
buffer.vertex(matrix4f, x1, y2, z1).color(c).next();
buffer.vertex(matrix4f, x1, y1, z1).color(c).next();
} else if (y1 == y2) {
buffer.vertex(matrix4f, x1, y1, z1).color(c).next();
buffer.vertex(matrix4f, x2, y1, z1).color(c).next();

buffer.vertex(matrix4f, x2, y1, z1).color(c).next();
buffer.vertex(matrix4f, x2, y1, z2).color(c).next();

buffer.vertex(matrix4f, x2, y1, z2).color(c).next();
buffer.vertex(matrix4f, x1, y1, z2).color(c).next();

buffer.vertex(matrix4f, x1, y1, z2).color(c).next();
buffer.vertex(matrix4f, x1, y1, z1).color(c).next();
}
}

/**
Expand Down

0 comments on commit 633c874

Please sign in to comment.