Search in sources :

Example 36 with Quat4f

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 "";
    }
}
Also used : GazeMountPointComponent(org.terasology.logic.characters.GazeMountPointComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Quat4f(org.terasology.math.geom.Quat4f) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 37 with Quat4f

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);
    }
}
Also used : Quat4f(org.terasology.math.geom.Quat4f)

Example 38 with Quat4f

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);
    }
}
Also used : Quat4f(org.terasology.math.geom.Quat4f)

Example 39 with Quat4f

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));
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) FloatingTextComponent(org.terasology.rendering.logic.FloatingTextComponent) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Example 40 with Quat4f

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);
}
Also used : EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) Quat4f(org.terasology.math.geom.Quat4f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

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