use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class TessellatorHelper method addBlockMesh.
public static void addBlockMesh(Tessellator tessellator, Vector4f color, Vector2f[] texOffsets, Vector2f[] texSizes, float size, float light1, float light2, float posX, float posY, float posZ) {
final float sizeHalf = size / 2;
tessellator.resetParams();
tessellator.setColor(new Vector4f(light1 * color.x, light1 * color.y, light1 * color.z, color.w));
tessellator.setNormal(new Vector3f(0, 1, 0));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[0].x, texOffsets[0].y), new Vector2f(texOffsets[0].x + texSizes[0].x, texOffsets[0].y), new Vector2f(texOffsets[0].x + texSizes[0].x, texOffsets[0].y + texSizes[0].y), new Vector2f(texOffsets[0].x, texOffsets[0].y + texSizes[0].y) });
tessellator.setNormal(new Vector3f(-1, 0, 0));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[1].x, texOffsets[1].y + texSizes[1].y), new Vector2f(texOffsets[1].x + texSizes[1].x, texOffsets[1].y + texSizes[1].y), new Vector2f(texOffsets[1].x + texSizes[1].x, texOffsets[1].y), new Vector2f(texOffsets[1].x, texOffsets[1].y) });
tessellator.setNormal(new Vector3f(1, 0, 0));
tessellator.addPoly(new Vector3f[] { new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[2].x, texOffsets[2].y), new Vector2f(texOffsets[2].x + texSizes[2].x, texOffsets[2].y), new Vector2f(texOffsets[2].x + texSizes[2].x, texOffsets[2].y + texSizes[2].y), new Vector2f(texOffsets[2].x, texOffsets[2].y + texSizes[2].y) });
tessellator.setColor(new Vector4f(light2 * color.x, light2 * color.y, light2 * color.z, color.w));
tessellator.setNormal(new Vector3f(0, 0, -1));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[3].x, texOffsets[3].y), new Vector2f(texOffsets[3].x + texSizes[3].x, texOffsets[3].y), new Vector2f(texOffsets[3].x + texSizes[3].x, texOffsets[3].y + texSizes[3].y), new Vector2f(texOffsets[3].x, texOffsets[3].y + texSizes[3].y) });
tessellator.setNormal(new Vector3f(0, 0, 1));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[4].x, texOffsets[4].y + texSizes[4].y), new Vector2f(texOffsets[4].x + texSizes[4].x, texOffsets[4].y + texSizes[4].y), new Vector2f(texOffsets[4].x + texSizes[4].x, texOffsets[4].y), new Vector2f(texOffsets[4].x, texOffsets[4].y) });
tessellator.setNormal(new Vector3f(0, -1, 0));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[5].x, texOffsets[5].y), new Vector2f(texOffsets[5].x + texSizes[5].x, texOffsets[5].y), new Vector2f(texOffsets[5].x + texSizes[5].x, texOffsets[5].y + texSizes[5].y), new Vector2f(texOffsets[5].x, texOffsets[5].y + texSizes[5].y) });
}
use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class Port method mid.
public Vector2f mid() {
Vector2f mid = rect.getSize(new Vector2f());
mid.mul(0.5f);
mid.add(rect.minX(), rect.minY());
return mid;
}
use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class BehaviorEditor method drawConnection.
private void drawConnection(Canvas canvas, Port from, Vector2f to, Color color) {
Vector2f start = new Vector2f(from.node.getPosition());
start.add(from.mid());
drawConnection(canvas, start, to, color);
}
use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class BehaviorEditor method onDraw.
@Override
public void onDraw(final Canvas canvas) {
super.onDraw(canvas);
canvas.addInteractionRegion(mouseInteractionListener);
try (SubRegion subRegion = canvas.subRegion(canvas.getRegion(), false)) {
canvas.setDrawOnTop(true);
for (UIWidget widget : getWidgets()) {
if (!widget.isVisible()) {
continue;
}
if (widget instanceof RenderableNode) {
RenderableNode renderableNode = (RenderableNode) widget;
for (Port port : renderableNode.getPorts()) {
Port targetPort = port.getTargetPort();
if (port.isInput() || targetPort == null || !targetPort.node.isVisible()) {
continue;
}
drawConnection(canvas, port, targetPort, port == activeConnectionStart ? Color.BLACK : Color.GREY);
}
}
}
if (activeConnectionStart != null) {
drawConnection(canvas, activeConnectionStart, mouseWorldPosition, Color.WHITE);
}
if (selectedNode != null) {
Vector2f size = new Vector2f(selectedNode.getSize());
Vector2f topLeft = new Vector2f(selectedNode.getPosition());
Vector2f topRight = new Vector2f(topLeft);
topRight.add(new Vector2f(size.x + .1f, 0));
Vector2f bottomLeft = new Vector2f(topLeft);
bottomLeft.add(new Vector2f(0, size.y + .1f));
Vector2f bottomRight = new Vector2f(topLeft);
bottomRight.add(new Vector2f(size.x + 0.1f, size.y + 0.1f));
drawConnection(canvas, topLeft, topRight, Color.GREEN);
drawConnection(canvas, topRight, bottomRight, Color.GREEN);
drawConnection(canvas, bottomRight, bottomLeft, Color.GREEN);
drawConnection(canvas, bottomLeft, topLeft, Color.GREEN);
}
if (newNode != null) {
newNode.visit(node -> drawWidget(canvas, node));
}
canvas.setDrawOnTop(false);
}
}
use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class BehaviorEditor method drawConnection.
private void drawConnection(Canvas canvas, Port from, Port to, Color color) {
Vector2f start = new Vector2f(from.node.getPosition());
start.add(from.mid());
Vector2f end = new Vector2f(to.node.getPosition());
end.add(to.mid());
drawConnection(canvas, start, end, color);
}
Aggregations