Search in sources :

Example 76 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class PlayerTargetSystem method update.

@Override
public void update(float delta) {
    EntityRef charEntity = player.getCharacterEntity();
    if (charEntity.exists()) {
        Vector3f cameraPos = player.getViewPosition(new Vector3f());
        CharacterComponent charComp = charEntity.getComponent(CharacterComponent.class);
        if (charComp != null) {
            Vector3f dir = player.getViewDirection(new Vector3f());
            float maxDist = charComp.interactionRange;
            FirstPersonHeldItemMountPointComponent heldItemMountPoint = player.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
            if (heldItemMountPoint != null && heldItemMountPoint.isTracked()) {
                maxDist = heldItemMountPoint.translate.length() + 0.25f;
                dir = new Vector3f(heldItemMountPoint.translate).normalize();
            }
            if (targetSystem.updateTarget(cameraPos, dir, maxDist)) {
                EntityRef oldTarget = targetSystem.getPreviousTarget();
                EntityRef newTarget = targetSystem.getTarget();
                charEntity.send(new PlayerTargetChangedEvent(oldTarget, newTarget));
            }
        }
    }
}
Also used : PlayerTargetChangedEvent(org.terasology.engine.logic.players.PlayerTargetChangedEvent) Vector3f(org.joml.Vector3f) CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) FirstPersonHeldItemMountPointComponent(org.terasology.engine.logic.players.FirstPersonHeldItemMountPointComponent)

Example 77 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class SpriteParticleRenderer method renderAlphaBlend.

@Override
public void renderAlphaBlend() {
    if (!opengl33) {
        return;
    }
    PerspectiveCamera camera = (PerspectiveCamera) worldRenderer.getActiveCamera();
    Vector3f cameraPosition = camera.getPosition();
    Matrix4f viewProjection = new Matrix4f(camera.getViewProjectionMatrix()).translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z);
    Material material = Assets.getMaterial(PARTICLE_MATERIAL_URI).get();
    material.enable();
    material.setFloat3("camera_position", cameraPosition.x, cameraPosition.y, cameraPosition.z);
    material.setMatrix4("view_projection", viewProjection.get(matrixBuffer));
    particleSystemManager.getParticleEmittersByDataComponent(ParticleDataSpriteComponent.class).forEach(particleSystem -> drawParticles(material, particleSystem));
}
Also used : ParticleDataSpriteComponent(org.terasology.engine.particles.components.ParticleDataSpriteComponent) Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) Material(org.terasology.engine.rendering.assets.material.Material) PerspectiveCamera(org.terasology.engine.rendering.cameras.PerspectiveCamera)

Example 78 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class AbstractStorageManager method getEntitiesOfChunk.

protected Collection<EntityRef> getEntitiesOfChunk(Chunk chunk) {
    List<EntityRef> entitiesToStore = Lists.newArrayList();
    AABBfc aabb = chunk.getAABB();
    for (EntityRef entity : getEntityManager().getEntitiesWith(LocationComponent.class)) {
        if (!entity.getOwner().exists() && !entity.isAlwaysRelevant() && !entity.hasComponent(ClientComponent.class)) {
            LocationComponent loc = entity.getComponent(LocationComponent.class);
            if (loc == null) {
                continue;
            }
            Vector3f pos = loc.getWorldPosition(new Vector3f());
            if (pos.isFinite()) {
                if (aabb.containsPoint(loc.getWorldPosition(new Vector3f()))) {
                    entitiesToStore.add(entity);
                }
            }
        }
    }
    return entitiesToStore;
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 79 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class ScaleRangeGeneratorComponent method copyFrom.

@Override
public void copyFrom(ScaleRangeGeneratorComponent other) {
    this.minScale = new Vector3f(other.minScale);
    this.maxScale = new Vector3f(other.maxScale);
}
Also used : Vector3f(org.joml.Vector3f)

Example 80 with Vector3f

use of org.joml.Vector3f in project Terasology by MovingBlocks.

the class PositionRangeGeneratorComponent method copyFrom.

@Override
public void copyFrom(PositionRangeGeneratorComponent other) {
    this.minPosition = new Vector3f(other.minPosition);
    this.maxPosition = new Vector3f(other.maxPosition);
}
Also used : Vector3f(org.joml.Vector3f)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8