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