Search in sources :

Example 71 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class SpriteParticleRenderer method renderAlphaBlend.

@Override
public void renderAlphaBlend() {
    Material material = Assets.getMaterial(PARTICLE_MATERIAL_URI).get();
    material.enable();
    Vector3f camPos = worldRenderer.getActiveCamera().getPosition();
    particleSystemManager.getParticleEmittersByDataComponent(ParticleDataSpriteComponent.class).forEach(p -> drawParticles(material, p, camPos));
}
Also used : ParticleDataSpriteComponent(org.terasology.particles.components.ParticleDataSpriteComponent) Vector3f(org.terasology.math.geom.Vector3f) Material(org.terasology.rendering.assets.material.Material)

Example 72 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class ParticleUpdaterImpl method checkCollision.

// == particles =====================================================================================================
private void checkCollision(final ParticlePool pool, final int offset) {
    final Vector3f vel = new Vector3f();
    final Vector3f halfVelDir = new Vector3f();
    final Vector3f curr = new Vector3f();
    for (int i = offset; i < pool.livingParticles(); i += PHYSICS_SKIP_NR) {
        int i3 = i * 3;
        curr.set(pool.position[i3 + 0], pool.position[i3 + 1], pool.position[i3 + 2]);
        vel.set(pool.velocity[i3 + 0], pool.velocity[i3 + 1], pool.velocity[i3 + 2]);
        halfVelDir.scale(0).add(vel).normalize().scale(0.5f);
        curr.sub(halfVelDir);
        float dist = (vel.length() + 0.5f) * movingAvgDelta * PHYSICS_SKIP_NR * 1.5f;
        vel.normalize();
        HitResult hitResult = physics.rayTrace(curr, vel, dist, StandardCollisionGroup.WORLD);
        if (hitResult.isHit()) {
            pool.energy[i] = 0;
        }
    }
}
Also used : HitResult(org.terasology.physics.HitResult) Vector3f(org.terasology.math.geom.Vector3f)

Example 73 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class AnimationScreen method initialise.

@Override
public void initialise() {
    spawnEntityIdButton = find("spawnEntityIdButton", UIButton.class);
    entityDropdown = find("entityDropdown", UIDropdownScrollable.class);
    logger.info("Number of available skeletal meshes: " + assetManager.getAvailableAssets(SkeletalMesh.class).size());
    ArrayList skeletalMesh = new ArrayList(assetManager.getAvailableAssets(SkeletalMesh.class));
    if (entityDropdown != null) {
        entityDropdown.setOptions(skeletalMesh);
    }
    animationSpeedSlider = find("entityAnimationSpeedSlider", UISlider.class);
    if (animationSpeedSlider != null) {
        animationSpeedSlider.setMinimum(-0.0f);
        animationSpeedSlider.setIncrement(0.1f);
        animationSpeedSlider.setRange(10.0f);
        animationSpeedSlider.setPrecision(1);
    }
    spawnEntityIdButton.subscribe(widget -> {
        Vector3f localPlayerPosition = localPlayer.getPosition();
        Quat4f localPlayerRotation = localPlayer.getRotation();
        Vector3f offset = localPlayer.getViewDirection();
        offset.scale(2.0f);
        offset.y = 0;
        localPlayerPosition.add(offset);
        Optional<Prefab> prefab = assetManager.getAsset(entityDropdown.getSelection(), Prefab.class);
        if (prefab.isPresent() && prefab.get().getComponent(LocationComponent.class) != null) {
            entityRef = entityManager.create(prefab.get(), localPlayerPosition, localPlayerRotation);
            SkeletalMeshComponent skeletalMeshComponent = entityRef.getComponent(SkeletalMeshComponent.class);
            skeletalMeshComponent.animationRate = animationSpeedSlider.getValue();
            entityRef.saveComponent(skeletalMeshComponent);
            CharacterMovementComponent movementComponent = entityRef.getComponent(CharacterMovementComponent.class);
            movementComponent.speedMultiplier = animationSpeedSlider.getValue();
            entityRef.saveComponent(movementComponent);
        }
    });
}
Also used : SkeletalMeshComponent(org.terasology.rendering.logic.SkeletalMeshComponent) UISlider(org.terasology.rendering.nui.widgets.UISlider) UIButton(org.terasology.rendering.nui.widgets.UIButton) UIDropdownScrollable(org.terasology.rendering.nui.widgets.UIDropdownScrollable) Vector3f(org.terasology.math.geom.Vector3f) ArrayList(java.util.ArrayList) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Prefab(org.terasology.entitySystem.prefab.Prefab) Quat4f(org.terasology.math.geom.Quat4f)

Example 74 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class DoorSystem method placeDoor.

@ReceiveEvent(components = { DoorComponent.class, ItemComponent.class })
public void placeDoor(ActivateEvent event, EntityRef entity) {
    DoorComponent door = entity.getComponent(DoorComponent.class);
    BlockComponent targetBlockComp = event.getTarget().getComponent(BlockComponent.class);
    if (targetBlockComp == null) {
        event.consume();
        return;
    }
    Vector3f horizDir = new Vector3f(event.getDirection());
    horizDir.y = 0;
    Side facingDir = Side.inDirection(horizDir);
    if (!facingDir.isHorizontal()) {
        event.consume();
        return;
    }
    Vector3f offset = new Vector3f(event.getHitPosition());
    offset.sub(targetBlockComp.getPosition().toVector3f());
    Side offsetDir = Side.inDirection(offset);
    Vector3i primePos = new Vector3i(targetBlockComp.getPosition());
    primePos.add(offsetDir.getVector3i());
    Block primeBlock = worldProvider.getBlock(primePos);
    if (!primeBlock.isReplacementAllowed()) {
        event.consume();
        return;
    }
    Block belowBlock = worldProvider.getBlock(primePos.x, primePos.y - 1, primePos.z);
    Block aboveBlock = worldProvider.getBlock(primePos.x, primePos.y + 1, primePos.z);
    // Determine top and bottom blocks
    Vector3i bottomBlockPos;
    Vector3i topBlockPos;
    if (belowBlock.isReplacementAllowed()) {
        bottomBlockPos = new Vector3i(primePos.x, primePos.y - 1, primePos.z);
        topBlockPos = primePos;
    } else if (aboveBlock.isReplacementAllowed()) {
        bottomBlockPos = primePos;
        topBlockPos = new Vector3i(primePos.x, primePos.y + 1, primePos.z);
    } else {
        event.consume();
        return;
    }
    Side attachSide = determineAttachSide(facingDir, offsetDir, bottomBlockPos, topBlockPos);
    if (attachSide == null) {
        event.consume();
        return;
    }
    Side closedSide = facingDir.reverse();
    if (closedSide == attachSide || closedSide.reverse() == attachSide) {
        closedSide = attachSide.yawClockwise(1);
    }
    Block newBottomBlock = door.bottomBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, bottomBlockPos, closedSide, Side.TOP);
    Block newTopBlock = door.topBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, bottomBlockPos, closedSide, Side.TOP);
    Map<Vector3i, Block> blockMap = new HashMap<>();
    blockMap.put(bottomBlockPos, newBottomBlock);
    blockMap.put(topBlockPos, newTopBlock);
    PlaceBlocks blockEvent = new PlaceBlocks(blockMap, event.getInstigator());
    worldProvider.getWorldEntity().send(blockEvent);
    if (!blockEvent.isConsumed()) {
        EntityRef newDoor = entityManager.create(door.doorRegionPrefab);
        entity.removeComponent(MeshComponent.class);
        newDoor.addComponent(new BlockRegionComponent(Region3i.createBounded(bottomBlockPos, topBlockPos)));
        Vector3f doorCenter = bottomBlockPos.toVector3f();
        doorCenter.y += 0.5f;
        newDoor.addComponent(new LocationComponent(doorCenter));
        DoorComponent newDoorComp = newDoor.getComponent(DoorComponent.class);
        newDoorComp.closedSide = closedSide;
        newDoorComp.openSide = attachSide.reverse();
        newDoorComp.isOpen = false;
        newDoor.saveComponent(newDoorComp);
        newDoor.send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
        logger.info("Closed Side: {}", newDoorComp.closedSide);
        logger.info("Open Side: {}", newDoorComp.openSide);
        newDoor.send(new DoorPlacedEvent(event.getInstigator()));
    }
}
Also used : HashMap(java.util.HashMap) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) LocationComponent(org.terasology.logic.location.LocationComponent) BlockComponent(org.terasology.world.block.BlockComponent) Side(org.terasology.math.Side) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) PlaceBlocks(org.terasology.world.block.entity.placement.PlaceBlocks) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 75 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class TreeGeneratorLSystem method generate.

@Override
public void generate(BlockManager blockManager, CoreChunk view, Random rand, int posX, int posY, int posZ) {
    Vector3f position = new Vector3f(0f, 0f, 0f);
    Matrix4f rotation = new Matrix4f(new Quat4f(new Vector3f(0f, 0f, 1f), (float) Math.PI / 2f), Vector3f.ZERO, 1.0f);
    float angleOffset = rand.nextFloat(-MAX_ANGLE_OFFSET, MAX_ANGLE_OFFSET);
    Block bark = blockManager.getBlock(barkType);
    Block leaf = blockManager.getBlock(leafType);
    recursiveGenerator.recurse(view, rand, posX, posY, posZ, angleOffset, new CharSequenceIterator(initialAxiom), position, rotation, bark, leaf, 0, this);
}
Also used : Matrix4f(org.terasology.math.geom.Matrix4f) Vector3f(org.terasology.math.geom.Vector3f) Block(org.terasology.world.block.Block) Quat4f(org.terasology.math.geom.Quat4f) CharSequenceIterator(org.terasology.utilities.collection.CharSequenceIterator)

Aggregations

Vector3f (org.terasology.math.geom.Vector3f)194 LocationComponent (org.terasology.logic.location.LocationComponent)45 EntityRef (org.terasology.entitySystem.entity.EntityRef)44 Quat4f (org.terasology.math.geom.Quat4f)33 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)26 Vector3i (org.terasology.math.geom.Vector3i)21 Test (org.junit.Test)20 ClientComponent (org.terasology.network.ClientComponent)15 Command (org.terasology.logic.console.commandSystem.annotations.Command)14 Matrix4f (org.terasology.math.geom.Matrix4f)13 BaseVector3f (org.terasology.math.geom.BaseVector3f)9 Block (org.terasology.world.block.Block)9 Vector2f (org.terasology.math.geom.Vector2f)8 HitResult (org.terasology.physics.HitResult)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 IOException (java.io.IOException)6 FloatBuffer (java.nio.FloatBuffer)6 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 AABB (org.terasology.math.AABB)5 ChunkMesh (org.terasology.rendering.primitives.ChunkMesh)5