Search in sources :

Example 41 with Vector3f

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

the class OpenALManager method updateListener.

@Override
public void updateListener(Vector3fc position, Quaternionfc orientation, Vector3fc velocity) {
    AL10.alListener3f(AL10.AL_VELOCITY, velocity.x(), velocity.y(), velocity.z());
    OpenALException.checkState("Setting listener velocity");
    Vector3f dir = new Vector3f(Direction.FORWARD.asVector3f()).rotate(orientation);
    Vector3f up = new Vector3f(Direction.UP.asVector3f()).rotate(orientation);
    FloatBuffer listenerOri = BufferUtils.createFloatBuffer(6).put(new float[] { dir.x, dir.y, dir.z, up.x, up.y, up.z });
    listenerOri.flip();
    AL10.alListenerfv(AL10.AL_ORIENTATION, listenerOri);
    OpenALException.checkState("Setting listener orientation");
    listenerPosition.set(position);
    AL10.alListener3f(AL10.AL_POSITION, position.x(), position.y(), position.z());
    OpenALException.checkState("Setting listener position");
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Example 42 with Vector3f

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

the class SectorUtil method getWatchedChunks.

/**
 * Watched chunks are defined as the union of:
 * <ul>
 *     <li>The chunk in which the {@link LocationComponent#getWorldPosition(Vector3f)} resides, if any</li>
 *     <li>The set of chunks in {@link SectorRegionComponent#chunks}, if any</li>
 * </ul>
 *
 * @param entity the entity to query the watched chunks of
 * @return the set of positions of this entity's watched chunks
 */
public static Set<Vector3i> getWatchedChunks(EntityRef entity) {
    Set<Vector3i> chunks = new HashSet<>();
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    Vector3f position = loc.getWorldPosition(new Vector3f());
    if (position.isFinite()) {
        chunks.add(Chunks.toChunkPos(position, new Vector3i()));
    }
    SectorRegionComponent regionComponent = entity.getComponent(SectorRegionComponent.class);
    if (regionComponent != null) {
        // potential leaky abstraction. component exposes its internal vectors
        chunks.addAll(regionComponent.chunks);
    }
    return chunks;
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) LocationComponent(org.terasology.engine.logic.location.LocationComponent) HashSet(java.util.HashSet)

Example 43 with Vector3f

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

the class CameraTargetSystem method updateFocalDistance.

private void updateFocalDistance(HitResult hitInfo, float delta) {
    // how fast the focus distance is updated
    float focusRate = 4.0f;
    // if the hit result from a trace has a recorded a hit
    if (hitInfo.isHit()) {
        Vector3f playerToTargetRay = new Vector3f();
        // calculate the distance from the player to the hit point
        hitInfo.getHitPoint().sub(localPlayer.getViewPosition(new Vector3f()), playerToTargetRay);
        // gradually adjust focalDistance from it's current value to the hit point distance
        focalDistance = TeraMath.lerp(focalDistance, playerToTargetRay.length(), delta * focusRate);
    // if nothing was hit, gradually adjust the focusDistance to the maximum length of the update function trace
    } else {
        focalDistance = TeraMath.lerp(focalDistance, targetDistance, delta * focusRate);
    }
}
Also used : Vector3f(org.joml.Vector3f)

Example 44 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 45 with Vector3f

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

the class PlaySoundAction method onActivationPredicted.

/**
 * This method plays sound in prediction for preventing not playing song because of server lags
 *
 * @param event contains the details for the predicted event, used here for location purposes
 * @param entity is source of the playsound
 */
@ReceiveEvent(components = PlaySoundActionComponent.class)
public void onActivationPredicted(ActivationPredicted event, EntityRef entity) {
    PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
    StaticSound sound = random.nextItem(playSound.sounds);
    if (sound != null) {
        Vector3f pos;
        switch(playSound.relativeTo) {
            case Target:
                pos = event.getTargetLocation();
                break;
            default:
                pos = event.getInstigatorLocation();
                break;
        }
        if (pos == null) {
            pos = event.getOrigin();
        }
        audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) Vector3f(org.joml.Vector3f) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

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