refactor Tesselator

This commit is contained in:
Daniella / Tove 2024-06-06 14:06:45 +02:00
parent 2fca8db352
commit e7f2088700
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
3 changed files with 72 additions and 12 deletions

View file

@ -14,7 +14,7 @@ import org.lwjgl.opengl.GL11;
import java.util.Objects;
import static com.baseband.client.util.render.Tesselator.*;
import static com.baseband.client.util.render.RenderAdapter.*;
@Render
public class Freecam extends Feature {

View file

@ -24,7 +24,7 @@ import java.util.ArrayList;
import java.util.Objects;
import static com.baseband.client.BaseBand.LOGGER;
import static com.baseband.client.util.render.Tesselator.*;
import static com.baseband.client.util.render.RenderAdapter.*;
@World
@Description("Shows changes done to the world compared to its original state\n" +

View file

@ -1,7 +1,6 @@
package com.baseband.client.util.render;
import de.tudbut.net.ic.PBIC;
import de.tudbut.type.Vector3d;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.opengl.GL11;
@ -10,19 +9,23 @@ import java.awt.*;
import static org.lwjgl.opengl.GL11.*;
public class Tesselator {
public class RenderAdapter {
static int mode;
static int color;
static Vector3d translated;
static Vec3d translated;
static boolean depth;
private static byte[] splitIntBE(int i) {
return new byte[]{(byte)(i >> 24 & 0xff), (byte)(i >> 16 & 0xff), (byte)(i >> 8 & 0xff), (byte)(i >> 0 & 0xff)};
}
public static void ready() {
glPushMatrix();
}
public static void translate(double x, double y, double z) {
glTranslated(x,y,z);
translated = new Vector3d(x,y,z);
translated = new Vec3d(x,y,z);
}
public static void begin(int modeIn) {
glBegin(mode = modeIn);
@ -32,13 +35,12 @@ public class Tesselator {
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
byte[] bytes = PBIC.putInt(argb);
glColor4ub(bytes[1], bytes[2], bytes[3], bytes[0]);
color = argb;
changeColor(argb);
}
public static void changeColor(int argb) {
byte[] bytes = PBIC.putInt(argb);
byte[] bytes = splitIntBE(argb);
glColor4ub(bytes[1], bytes[2], bytes[3], bytes[0]);
color = argb;
}
public static void depth(boolean b) {
depth = b;
@ -76,7 +78,7 @@ public class Tesselator {
// start new
glPushMatrix();
glTranslated(translated.getX(), translated.getY(), translated.getZ());
glTranslated(translated.x, translated.y, translated.z);
color(color);
depth(depth);
glBegin(mode);
@ -212,4 +214,62 @@ public class Tesselator {
public static void drawBlockFaces(BlockPos pos, Color color, Vec3d eyePos) {
drawBlockFaces(pos, color.getRGB(), eyePos);
}
public static void drawAABB(AxisAlignedBB box, int color, Vec3d eyePos) {
try {
ready();
translate(-eyePos.x, -eyePos.y, -eyePos.z);
color(color);
depth(false);
begin(GL11.GL_QUADS);
double entityHalfed = (box.maxX - box.minX) / 2;
double entityHeight = (box.maxY - box.minY);
Vec3d pos = new Vec3d(box.maxX - entityHalfed, box.minY, box.maxZ - entityHalfed);
drawAABBNow(pos, entityHalfed, entityHeight);
end();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void drawAABBNow(Vec3d halfPos, double entityHalfed, double entityHeight) {
// bottom
put(halfPos.x - entityHalfed, halfPos.y - 0.01, halfPos.z + entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y - 0.01, halfPos.z + entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y - 0.01, halfPos.z - entityHalfed);
put(halfPos.x - entityHalfed, halfPos.y - 0.01, halfPos.z - entityHalfed);
// top
put(halfPos.x - entityHalfed, halfPos.y + entityHeight, halfPos.z + entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y + entityHeight, halfPos.z + entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y + entityHeight, halfPos.z - entityHalfed);
put(halfPos.x - entityHalfed, halfPos.y + entityHeight, halfPos.z - entityHalfed);
// z -
put(halfPos.x - entityHalfed, halfPos.y + entityHeight, halfPos.z - entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y + entityHeight, halfPos.z - entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y - 0.01, halfPos.z - entityHalfed);
put(halfPos.x - entityHalfed, halfPos.y - 0.01, halfPos.z - entityHalfed);
// z +
put(halfPos.x - entityHalfed, halfPos.y + entityHeight, halfPos.z + entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y + entityHeight, halfPos.z + entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y - 0.01, halfPos.z + entityHalfed);
put(halfPos.x - entityHalfed, halfPos.y - 0.01, halfPos.z + entityHalfed);
// x -
put(halfPos.x - entityHalfed, halfPos.y + entityHeight, halfPos.z - entityHalfed);
put(halfPos.x - entityHalfed, halfPos.y + entityHeight, halfPos.z + entityHalfed);
put(halfPos.x - entityHalfed, halfPos.y - 0.01, halfPos.z + entityHalfed);
put(halfPos.x - entityHalfed, halfPos.y - 0.01, halfPos.z - entityHalfed);
// y +
put(halfPos.x + entityHalfed, halfPos.y + entityHeight, halfPos.z - entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y + entityHeight, halfPos.z + entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y - 0.01, halfPos.z + entityHalfed);
put(halfPos.x + entityHalfed, halfPos.y - 0.01, halfPos.z - entityHalfed);
}
}