use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class ZoomableLayout method drawWidget.
protected void drawWidget(Canvas canvas, PositionalWidget widget) {
if (!widget.isVisible()) {
return;
}
Vector2i screenStart = worldToScreen(widget.getPosition());
Vector2f worldEnd = new Vector2f(widget.getPosition());
worldEnd.add(widget.getSize());
Vector2i screenEnd = worldToScreen(worldEnd);
canvas.drawWidget(widget, Rect2i.createFromMinAndMax(screenStart, screenEnd));
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class PerlinHillsAndMountainsProvider method setSeed.
@Override
public void setSeed(long seed) {
// TODO: reduce the number of octaves in BrownianNoise
mountainNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 3)), new Vector2f(0.0002f, 0.0002f), 4);
hillNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 4)), new Vector2f(0.0008f, 0.0008f), 4);
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class PerlinHumidityProvider method reload.
private void reload() {
float realScale = config.scale * 0.01f;
Vector2f scale = new Vector2f(realScale, realScale);
BrownianNoise brown = new BrownianNoise(new PerlinNoise(seed + 6), config.octaves);
humidityNoise = new SubSampledNoise(brown, scale, SAMPLE_RATE);
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class TreeFacetLayer method getWorldText.
@Override
public String getWorldText(Region region, int wx, int wy) {
TreeFacet treeFacet = region.getFacet(TreeFacet.class);
Region3i worldRegion = treeFacet.getWorldRegion();
Region3i relativeRegion = treeFacet.getRelativeRegion();
int rx = wx - worldRegion.minX() + relativeRegion.minX();
int rz = wy - worldRegion.minZ() + relativeRegion.minZ();
Vector2f relCursor = new Vector2f(rx, rz);
CirclePicker<TreeGenerator> picker = new CirclePickerAll<>(relCursor, radiusFunc);
for (Entry<BaseVector3i, TreeGenerator> entry : treeFacet.getRelativeEntries().entrySet()) {
TreeGenerator treeGen = entry.getValue();
BaseVector3i treePos = entry.getKey();
picker.offer(treePos.getX(), treePos.getZ(), treeGen);
}
Set<TreeGenerator> picked = picker.getAll();
// try to exit early first
if (picked.isEmpty()) {
return null;
}
if (picked.size() == 1) {
TreeGenerator first = picked.iterator().next();
return labelFunc.apply(first);
}
// convert to a stream of labels
Stream<String> labels = picked.stream().map(labelFunc);
// collect identical String elements and collect the count in a map
Map<String, Long> counters = labels.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
// define a mapping from a map entry to a String representation
// TODO: treat 1x occurrences like above (e.g. Tree instead of 1x Tree)
Function<Entry<String, Long>, String> toStringFunc = e -> String.format("%dx %s", e.getValue(), e.getKey());
// apply that mapping and join the Strings with a comma
return counters.entrySet().stream().map(toStringFunc).collect(Collectors.joining(", "));
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class BlockDamageAuthoritySystem method createBlockParticleEffect.
/**
* Creates a new entity for the block damage particle effect.
*
* If the terrain texture of the damaged block is available, the particles will have the block texture. Otherwise,
* the default sprite (smoke) is used.
*
* @param family the {@link BlockFamily} of the damaged block
* @param location the location of the damaged block
*/
private void createBlockParticleEffect(BlockFamily family, Vector3f location) {
EntityBuilder builder = entityManager.newBuilder("core:defaultBlockParticles");
builder.getComponent(LocationComponent.class).setWorldPosition(location);
Optional<Texture> terrainTexture = Assets.getTexture("engine:terrain");
if (terrainTexture.isPresent() && terrainTexture.get().isLoaded()) {
final BlockAppearance blockAppearance = family.getArchetypeBlock().getPrimaryAppearance();
final float relativeTileSize = worldAtlas.getRelativeTileSize();
final float particleScale = 0.25f;
final float spriteSize = relativeTileSize * particleScale;
ParticleDataSpriteComponent spriteComponent = builder.getComponent(ParticleDataSpriteComponent.class);
spriteComponent.texture = terrainTexture.get();
spriteComponent.textureSize.set(spriteSize, spriteSize);
final List<Vector2f> offsets = computeOffsets(blockAppearance, particleScale);
TextureOffsetGeneratorComponent textureOffsetGeneratorComponent = builder.getComponent(TextureOffsetGeneratorComponent.class);
textureOffsetGeneratorComponent.validOffsets.addAll(offsets);
}
builder.build();
}
Aggregations