Search in sources :

Example 26 with Vector3f

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

the class FirstPersonHeldItemMountPointComponent method poseChanged.

/**
 * A callback target for the controller listener. When this callback triggers, the pos of the mount point will
 * cuange to the value of the pose parameter. This is mainly designed as a callback, and not intended to be part
 * of the public interface of this class.
 * @param pose - the controller pose - a homogenous transformation matrix.
 * @param handIndex - the hand index - 0 for left and 1 for right.
 */
public void poseChanged(Matrix4f pose, int handIndex) {
    // TODO: put a hand for the second controller.
    if (handIndex != 0) {
        return;
    }
    trackingDataReceived = true;
    Matrix4f adjustedPose = pose.mul(toolAdjustmentMatrix);
    translate = new Vector3f(adjustedPose.m30(), adjustedPose.m31(), adjustedPose.m32());
    org.joml.Vector4f jomlQuaternion = org.terasology.rendering.openvrprovider.OpenVRUtil.convertToQuaternion(adjustedPose);
    if (rotationQuaternion == null) {
        rotationQuaternion = new Quat4f(jomlQuaternion.x, jomlQuaternion.y, jomlQuaternion.z, jomlQuaternion.w);
    } else {
        rotationQuaternion.set(jomlQuaternion.x, jomlQuaternion.y, jomlQuaternion.z, jomlQuaternion.w);
    }
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.terasology.math.geom.Vector3f) Quat4f(org.terasology.math.geom.Quat4f)

Example 27 with Vector3f

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

the class LocalPlayer method getViewDirection.

public Vector3f getViewDirection() {
    Quat4f rot = getViewRotation();
    // TODO: Put a generator for direction vectors in a util class somewhere
    // And just put quaternion -> vector somewhere too
    Vector3f dir = Direction.FORWARD.getVector3f();
    return rot.rotate(dir, dir);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Quat4f(org.terasology.math.geom.Quat4f)

Example 28 with Vector3f

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

the class LocalPlayerSystem method processInput.

private void processInput(EntityRef entity, CharacterMovementComponent characterMovementComponent) {
    lookYaw = (lookYaw - lookYawDelta) % 360;
    lookYawDelta = 0f;
    lookPitch = TeraMath.clamp(lookPitch + lookPitchDelta, -89, 89);
    lookPitchDelta = 0f;
    Vector3f relMove = new Vector3f(relativeMovement);
    relMove.y = 0;
    Quat4f viewRotation;
    switch(characterMovementComponent.mode) {
        case CROUCHING:
        case WALKING:
            if (!config.getRendering().isVrSupport()) {
                viewRotation = new Quat4f(TeraMath.DEG_TO_RAD * lookYaw, 0, 0);
                playerCamera.setOrientation(viewRotation);
            }
            playerCamera.getOrientation().rotate(relMove, relMove);
            break;
        case CLIMBING:
            // Rotation is applied in KinematicCharacterMover
            relMove.y += relativeMovement.y;
            break;
        default:
            if (!config.getRendering().isVrSupport()) {
                viewRotation = new Quat4f(TeraMath.DEG_TO_RAD * lookYaw, TeraMath.DEG_TO_RAD * lookPitch, 0);
                playerCamera.setOrientation(viewRotation);
            }
            playerCamera.getOrientation().rotate(relMove, relMove);
            relMove.y += relativeMovement.y;
            break;
    }
    // For some reason, Quat4f.rotate is returning NaN for valid inputs. This prevents those NaNs from causing trouble down the line.
    if (!Float.isNaN(relMove.getX()) && !Float.isNaN(relMove.getY()) && !Float.isNaN(relMove.getZ())) {
        entity.send(new CharacterMoveInputEvent(inputSequenceNumber++, lookPitch, lookYaw, relMove, run, crouch, jump, time.getGameDeltaInMs()));
    }
    jump = false;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) CharacterMoveInputEvent(org.terasology.logic.characters.CharacterMoveInputEvent) Quat4f(org.terasology.math.geom.Quat4f)

Example 29 with Vector3f

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

the class LocalPlayerSystem method onTargetChanged.

@ReceiveEvent
public void onTargetChanged(PlayerTargetChangedEvent event, EntityRef entity) {
    EntityRef target = event.getNewTarget();
    if (target.exists()) {
        LocationComponent location = target.getComponent(LocationComponent.class);
        if (location != null) {
            BlockComponent blockComp = target.getComponent(BlockComponent.class);
            BlockRegionComponent blockRegion = target.getComponent(BlockRegionComponent.class);
            if (blockComp != null || blockRegion != null) {
                Vector3f blockPos = location.getWorldPosition();
                Block block = worldProvider.getBlock(blockPos);
                aabb = block.getBounds(blockPos);
            } else {
                MeshComponent mesh = target.getComponent(MeshComponent.class);
                if (mesh != null && mesh.mesh != null) {
                    aabb = mesh.mesh.getAABB();
                    aabb = aabb.transform(location.getWorldRotation(), location.getWorldPosition(), location.getWorldScale());
                }
            }
        }
    } else {
        aabb = null;
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) MeshComponent(org.terasology.rendering.logic.MeshComponent) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3f(org.terasology.math.geom.Vector3f) Block(org.terasology.world.block.Block) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 30 with Vector3f

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

the class PlayerSystem method onRespawnRequest.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL, components = { ClientComponent.class })
public void onRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
    Vector3f spawnPosition = entity.getComponent(LocationComponent.class).getWorldPosition();
    if (worldProvider.isBlockRelevant(spawnPosition)) {
        respawnPlayer(entity);
    } else {
        updateRelevanceEntity(entity, ViewDistance.LEGALLY_BLIND.getChunkDistance());
        SpawningClientInfo info = new SpawningClientInfo(entity, spawnPosition);
        clientsPreparingToRespawn.add(info);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

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