Search in sources :

Example 11 with Vector2f

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));
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector2i(org.terasology.math.geom.Vector2i)

Example 12 with Vector2f

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);
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) SubSampledNoise(org.terasology.utilities.procedural.SubSampledNoise) PerlinNoise(org.terasology.utilities.procedural.PerlinNoise) BrownianNoise(org.terasology.utilities.procedural.BrownianNoise)

Example 13 with Vector2f

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);
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) SubSampledNoise(org.terasology.utilities.procedural.SubSampledNoise) PerlinNoise(org.terasology.utilities.procedural.PerlinNoise) BrownianNoise(org.terasology.utilities.procedural.BrownianNoise)

Example 14 with Vector2f

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(", "));
}
Also used : Color(java.awt.Color) Region(org.terasology.world.generation.Region) Region3i(org.terasology.math.Region3i) BufferedImage(java.awt.image.BufferedImage) TreeGenerator(org.terasology.core.world.generator.trees.TreeGenerator) Set(java.util.Set) RenderingHints(java.awt.RenderingHints) Vector2f(org.terasology.math.geom.Vector2f) CirclePickerAll(org.terasology.world.viewer.picker.CirclePickerAll) Renders(org.terasology.world.viewer.layers.Renders) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) AbstractFacetLayer(org.terasology.world.viewer.layers.AbstractFacetLayer) Stream(java.util.stream.Stream) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) BaseVector3i(org.terasology.math.geom.BaseVector3i) Graphics2D(java.awt.Graphics2D) Map(java.util.Map) Entry(java.util.Map.Entry) CirclePicker(org.terasology.world.viewer.picker.CirclePicker) ZOrder(org.terasology.world.viewer.layers.ZOrder) CirclePickerAll(org.terasology.world.viewer.picker.CirclePickerAll) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) TreeGenerator(org.terasology.core.world.generator.trees.TreeGenerator) Entry(java.util.Map.Entry) Vector2f(org.terasology.math.geom.Vector2f) BaseVector3i(org.terasology.math.geom.BaseVector3i) Region3i(org.terasology.math.Region3i)

Example 15 with Vector2f

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();
}
Also used : ParticleDataSpriteComponent(org.terasology.particles.components.ParticleDataSpriteComponent) TextureOffsetGeneratorComponent(org.terasology.particles.components.generators.TextureOffsetGeneratorComponent) BlockAppearance(org.terasology.world.block.BlockAppearance) Vector2f(org.terasology.math.geom.Vector2f) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.logic.location.LocationComponent) Texture(org.terasology.rendering.assets.texture.Texture)

Aggregations

Vector2f (org.terasology.math.geom.Vector2f)41 Vector3f (org.terasology.math.geom.Vector3f)8 IOException (java.io.IOException)5 TIntList (gnu.trove.list.TIntList)4 Vector2i (org.terasology.math.geom.Vector2i)4 TFloatList (gnu.trove.list.TFloatList)3 Map (java.util.Map)3 Test (org.junit.Test)3 Name (org.terasology.naming.Name)3 SubtextureData (org.terasology.rendering.assets.texture.subtexture.SubtextureData)3 BrownianNoise (org.terasology.utilities.procedural.BrownianNoise)3 PerlinNoise (org.terasology.utilities.procedural.PerlinNoise)3 SubSampledNoise (org.terasology.utilities.procedural.SubSampledNoise)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 InputStream (java.io.InputStream)2 Vector4f (org.terasology.math.geom.Vector4f)2 Bone (org.terasology.rendering.assets.skeletalmesh.Bone)2 BoneWeight (org.terasology.rendering.assets.skeletalmesh.BoneWeight)2 SkeletalMeshDataBuilder (org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder)2 BlockAppearance (org.terasology.world.block.BlockAppearance)2