use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class WorldAtlasImpl method createTextureAtlas.
private void createTextureAtlas(final Texture texture) {
final Map<Name, Map<Name, SubtextureData>> textureAtlases = Maps.newHashMap();
final Vector2f texSize = new Vector2f(getRelativeTileSize(), getRelativeTileSize());
tileIndexes.forEachEntry((tileUri, index) -> {
Vector2f coords = getTexCoords(index);
SubtextureData subtextureData = new SubtextureData(texture, Rect2f.createFromMinAndSize(coords, texSize));
Map<Name, SubtextureData> textureAtlas = textureAtlases.get(tileUri.getModuleName());
if (textureAtlas == null) {
textureAtlas = Maps.newHashMap();
textureAtlases.put(tileUri.getModuleName(), textureAtlas);
}
textureAtlas.put(tileUri.getResourceName(), subtextureData);
return true;
});
for (Map.Entry<Name, Map<Name, SubtextureData>> atlas : textureAtlases.entrySet()) {
AtlasData data = new AtlasData(atlas.getValue());
Assets.generateAsset(new ResourceUrn(atlas.getKey(), new Name("terrain")), data, Atlas.class);
}
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class TextureOffsetGeneratorFunction method onEmission.
@Override
public void onEmission(TextureOffsetGeneratorComponent component, ParticleData particleData, Random random) {
if (component.validOffsets.size() == 0) {
return;
}
final int randomOffsetIndex = random.nextInt(component.validOffsets.size());
final Vector2f randomOffset = component.validOffsets.get(randomOffsetIndex);
particleData.textureOffset.set(randomOffset.getX(), randomOffset.getY());
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class BehaviorEditor method copyNode.
public void copyNode(RenderableNode node) {
BehaviorTreeBuilder treeBuilder = CoreRegistry.get(BehaviorTreeBuilder.class);
String json = treeBuilder.toJson(node.getNode());
BehaviorNode nodeCopy = treeBuilder.fromJson(json);
List<RenderableNode> renderables = createRenderables(nodeCopy);
if (renderables.size() > 0) {
newNode = renderables.get(0);
Vector2f oldPos = newNode.getPosition();
layout(newNode);
oldPos.sub(newNode.getPosition());
newNode.move(oldPos);
}
}
use of org.terasology.math.geom.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 = selectedNode.getSize();
Vector2f topLeft = 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.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class ZoomableLayoutTest method testZoomOut.
@Test
public void testZoomOut() throws Exception {
zoomableLayout.onDraw(canvas);
// zoom out 2x from top left corner
zoomableLayout.zoom(2, 2, new Vector2i(0, 0));
zoomableLayout.onDraw(canvas);
// world size doubled
assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2 * 2, WORLD_HEIGHT * 2));
assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2 * 2), CANVAS_HEIGHT / (WORLD_HEIGHT * 2)));
verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x / 4), ceilToInt(pos1.y / 4)), new Vector2i(ceilToInt((pos1.x + size1.x) / 4), ceilToInt((pos1.y + size1.y) / 4))));
verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos2.x / 4), ceilToInt(pos2.y / 4)), new Vector2i(ceilToInt((pos2.x + size2.x) / 4), ceilToInt((pos2.y + size2.y) / 4))));
verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x / 4), ceilToInt(pos3.y / 4)), new Vector2i(ceilToInt((pos3.x + size3.x) / 4), ceilToInt((pos3.y + size3.y) / 4))));
}
Aggregations