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