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");
}
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;
}
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);
}
}
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));
}
}
}
}
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);
}
}
Aggregations