use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.
the class MovementDebugCommands method playerEyeHeight.
@Command(shortDescription = "Sets the eye-height of the player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerEyeHeight(@Sender EntityRef client, @CommandParam("eye-height") float amount) {
EntityRef player = client.getComponent(ClientComponent.class).character;
try {
GazeMountPointComponent gazeMountPointComponent = player.getComponent(GazeMountPointComponent.class);
if (gazeMountPointComponent != null) {
float prevHeight = gazeMountPointComponent.translate.y;
gazeMountPointComponent.translate.y = amount;
Location.removeChild(player, gazeMountPointComponent.gazeEntity);
Location.attachChild(player, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quat4f(Quat4f.IDENTITY));
player.saveComponent(gazeMountPointComponent);
return "Eye-height of player set to " + amount + " (was " + prevHeight + ")";
}
return "";
} catch (NullPointerException e) {
e.printStackTrace();
return "";
}
}
use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.
the class LocationComponent method setWorldPosition.
public void setWorldPosition(Vector3f value) {
this.position.set(value);
LocationComponent parentLoc = parent.getComponent(LocationComponent.class);
if (parentLoc != null) {
this.position.sub(parentLoc.getWorldPosition());
this.position.scale(1f / parentLoc.getWorldScale());
Quat4f rot = new Quat4f(0, 0, 0, 1);
rot.inverse(parentLoc.getWorldRotation());
rot.rotate(this.position, this.position);
}
}
use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.
the class LocationComponent method setWorldRotation.
public void setWorldRotation(Quat4f value) {
this.rotation.set(value);
LocationComponent parentLoc = parent.getComponent(LocationComponent.class);
if (parentLoc != null) {
Quat4f worldRot = parentLoc.getWorldRotation();
worldRot.inverse();
this.rotation.mul(worldRot, this.rotation);
}
}
use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.
the class NameTagClientSystem method createOrUpdateNameTagFor.
private void createOrUpdateNameTagFor(EntityRef entity, NameTagComponent nameTagComponent) {
EntityRef nameTag = nameTagEntityToFloatingTextMap.get(entity);
Vector3f offset = new Vector3f(0, nameTagComponent.yOffset, 0);
if (nameTag != null) {
FloatingTextComponent floatingText = nameTag.getComponent(FloatingTextComponent.class);
floatingText.text = nameTagComponent.text;
floatingText.textColor = nameTagComponent.textColor;
floatingText.scale = nameTagComponent.scale;
nameTag.saveComponent(floatingText);
LocationComponent nameTagLoc = nameTag.getComponent(LocationComponent.class);
nameTagLoc.setLocalPosition(offset);
nameTag.saveComponent(nameTagLoc);
} else {
EntityBuilder nameTagBuilder = entityManager.newBuilder();
FloatingTextComponent floatingTextComponent = new FloatingTextComponent();
nameTagBuilder.addComponent(floatingTextComponent);
LocationComponent locationComponent = new LocationComponent();
nameTagBuilder.addComponent(locationComponent);
floatingTextComponent.text = nameTagComponent.text;
floatingTextComponent.textColor = nameTagComponent.textColor;
floatingTextComponent.scale = nameTagComponent.scale;
nameTagBuilder.setOwner(entity);
nameTagBuilder.setPersistent(false);
nameTag = nameTagBuilder.build();
nameTagEntityToFloatingTextMap.put(entity, nameTag);
Location.attachChild(entity, nameTag, offset, new Quat4f(1, 0, 0, 0));
}
}
use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method ensureClientSideEntityOnHeldItemMountPoint.
// ensures held item mount point entity exists, attaches it to the camera and sets its transform
@ReceiveEvent
public void ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent event, EntityRef camera, FirstPersonHeldItemMountPointComponent firstPersonHeldItemMountPointComponent) {
if (!firstPersonHeldItemMountPointComponent.mountPointEntity.exists()) {
EntityBuilder builder = entityManager.newBuilder("engine:FirstPersonHeldItemMountPoint");
builder.setPersistent(false);
firstPersonHeldItemMountPointComponent.mountPointEntity = builder.build();
camera.saveComponent(firstPersonHeldItemMountPointComponent);
}
// link the mount point entity to the camera
Location.removeChild(camera, firstPersonHeldItemMountPointComponent.mountPointEntity);
Location.attachChild(camera, firstPersonHeldItemMountPointComponent.mountPointEntity, firstPersonHeldItemMountPointComponent.translate, new Quat4f(TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.y, TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.x, TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.z), firstPersonHeldItemMountPointComponent.scale);
}
Aggregations