use of com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier2D in project Wizardry by TeamWizardry.
the class TableModule method drawWire.
@SuppressWarnings("unused")
public static void drawWire(Vec2d start, Vec2d end, Color primary, Color secondary) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.disableCull();
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.translate(0, 0, -1);
streak.getTex().bind();
InterpBezier2D bezier = new InterpBezier2D(start, end);
List<Vec2d> list = bezier.list(50);
Vec2d pointerPos = null, behindPointer = null;
float p = 0;
for (int i = 0; i < list.size() - 1; i++) {
float x = (float) (start.length() + ClientTickHandler.getTicks() + ClientTickHandler.getPartialTicks()) / 30f;
if (i == (int) ((x - Math.floor(x)) * 50f)) {
p = i / (list.size() - 1.0f);
}
}
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder vb = tessellator.getBuffer();
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
Vec2d lastPoint = null;
for (int i = 0; i < list.size() - 1; i++) {
Vec2d point = list.get(i);
if (lastPoint == null) {
lastPoint = point;
continue;
}
float dist = (i / (list.size() - 1.0f));
float wire;
if (dist < p) {
float z = Math.abs(dist - p);
wire = 256.0f / 27.0f * (z * z * z - z * z * z * z);
} else {
float z = Math.abs(dist - (p + 1f));
wire = 256.0f / 27.0f * (z * z * z - z * z * z * z);
}
float r = lerp(primary.getRed(), secondary.getRed(), wire) / 255f;
float g = lerp(primary.getGreen(), secondary.getGreen(), wire) / 255f;
float b = lerp(primary.getBlue(), secondary.getBlue(), wire) / 255f;
Vec2d normal = point.sub(lastPoint).normalize();
Vec2d perp = new Vec2d(-normal.getYf(), normal.getXf()).mul((1.0f - 2.0f * Math.abs(dist - 0.5f) + 0.3f));
Vec2d point1 = lastPoint.sub(normal.mul(0.5)).add(perp);
Vec2d point2 = point.add(normal.mul(0.5)).add(perp);
Vec2d point3 = point.add(normal.mul(0.5)).sub(perp);
Vec2d point4 = lastPoint.sub(normal.mul(0.5)).sub(perp);
vb.pos(point1.getXf(), point1.getYf(), 0).tex(0, 0).color(r, g, b, 1f).endVertex();
vb.pos(point2.getXf(), point2.getYf(), 0).tex(0, 1).color(r, g, b, 1f).endVertex();
vb.pos(point3.getXf(), point3.getYf(), 0).tex(1, 0).color(r, g, b, 1f).endVertex();
vb.pos(point4.getXf(), point4.getYf(), 0).tex(1, 1).color(r, g, b, 1f).endVertex();
lastPoint = point;
}
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
}
use of com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier2D in project Wizardry by TeamWizardry.
the class TableModule method drawWire.
public static void drawWire(Vec2d start, Vec2d end, Color primary, Color secondary) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.disableCull();
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.translate(0, 0, -1);
STREAK.bind();
InterpBezier2D bezier = new InterpBezier2D(start, end);
List<Vec2d> list = bezier.list(50);
Vec2d pointerPos = null, behindPointer = null;
float p = 0;
for (int i = 0; i < list.size() - 1; i++) {
float x = (float) (start.length() + ClientTickHandler.getTicks() + ClientTickHandler.getPartialTicks()) / 30f;
if (i == (int) ((x - Math.floor(x)) * 50f)) {
p = i / (list.size() - 1.0f);
}
}
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder vb = tessellator.getBuffer();
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
Vec2d lastPoint = null;
for (int i = 0; i < list.size() - 1; i++) {
Vec2d point = list.get(i);
if (lastPoint == null) {
lastPoint = point;
continue;
}
float dist = (i / (list.size() - 1.0f));
float wire;
if (dist < p) {
float z = Math.abs(dist - p);
wire = 256.0f / 27.0f * (z * z * z - z * z * z * z);
} else {
float z = Math.abs(dist - (p + 1f));
wire = 256.0f / 27.0f * (z * z * z - z * z * z * z);
}
float r = lerp(primary.getRed(), secondary.getRed(), wire) / 255f;
float g = lerp(primary.getGreen(), secondary.getGreen(), wire) / 255f;
float b = lerp(primary.getBlue(), secondary.getBlue(), wire) / 255f;
Vec2d normal = point.sub(lastPoint).normalize();
Vec2d perp = new Vec2d(-normal.getYf(), normal.getXf()).mul((1.0f - 2.0f * Math.abs(dist - 0.5f) + 0.3f));
Vec2d point1 = lastPoint.sub(normal.mul(0.5)).add(perp);
Vec2d point2 = point.add(normal.mul(0.5)).add(perp);
Vec2d point3 = point.add(normal.mul(0.5)).sub(perp);
Vec2d point4 = lastPoint.sub(normal.mul(0.5)).sub(perp);
vb.pos(point1.getXf(), point1.getYf(), 0).tex(0, 0).color(r, g, b, 1f).endVertex();
vb.pos(point2.getXf(), point2.getYf(), 0).tex(0, 1).color(r, g, b, 1f).endVertex();
vb.pos(point3.getXf(), point3.getYf(), 0).tex(1, 0).color(r, g, b, 1f).endVertex();
vb.pos(point4.getXf(), point4.getYf(), 0).tex(1, 1).color(r, g, b, 1f).endVertex();
lastPoint = point;
}
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
}
Aggregations