Search in sources :

Example 6 with Quat4f

use of org.terasology.math.geom.Quat4f 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 7 with Quat4f

use of org.terasology.math.geom.Quat4f 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 8 with Quat4f

use of org.terasology.math.geom.Quat4f 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 9 with Quat4f

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

the class PlayerSystem method restoreCharacter.

private void restoreCharacter(EntityRef entity, EntityRef character) {
    Client clientListener = networkSystem.getOwner(entity);
    updateRelevanceEntity(entity, clientListener.getViewDistance().getChunkDistance());
    ClientComponent client = entity.getComponent(ClientComponent.class);
    client.character = character;
    entity.saveComponent(client);
    CharacterComponent characterComp = character.getComponent(CharacterComponent.class);
    if (characterComp != null) {
        characterComp.controller = entity;
        character.saveComponent(characterComp);
        character.setOwner(entity);
        if (!character.hasComponent(AliveCharacterComponent.class)) {
            character.addComponent(new AliveCharacterComponent());
        }
        Location.attachChild(character, entity, new Vector3f(), new Quat4f(0, 0, 0, 1));
    } else {
        character.destroy();
        spawnPlayer(entity);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) CharacterComponent(org.terasology.logic.characters.CharacterComponent) AliveCharacterComponent(org.terasology.logic.characters.AliveCharacterComponent) Client(org.terasology.network.Client) ClientComponent(org.terasology.network.ClientComponent) AliveCharacterComponent(org.terasology.logic.characters.AliveCharacterComponent) Quat4f(org.terasology.math.geom.Quat4f)

Example 10 with Quat4f

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

the class Rotation method getQuat4f.

public Quat4f getQuat4f() {
    Quat4f rotation = new Quat4f(yaw.getRadians(), pitch.getRadians(), roll.getRadians());
    rotation.normalize();
    return rotation;
}
Also used : Quat4f(org.terasology.math.geom.Quat4f)

Aggregations

Quat4f (org.terasology.math.geom.Quat4f)50 Vector3f (org.terasology.math.geom.Vector3f)33 LocationComponent (org.terasology.logic.location.LocationComponent)16 EntityRef (org.terasology.entitySystem.entity.EntityRef)14 Matrix4f (org.terasology.math.geom.Matrix4f)9 ClientComponent (org.terasology.network.ClientComponent)7 BaseQuat4f (org.terasology.math.geom.BaseQuat4f)6 FloatBuffer (java.nio.FloatBuffer)4 Test (org.junit.Test)4 BaseVector3f (org.terasology.math.geom.BaseVector3f)4 ArrayList (java.util.ArrayList)3 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)3 CharacterComponent (org.terasology.logic.characters.CharacterComponent)3 Lists (com.google.common.collect.Lists)2 TIntList (gnu.trove.list.TIntList)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Arrays (java.util.Arrays)2