Search in sources :

Example 1 with Rotation

use of org.terasology.engine.math.Rotation in project Terasology by MovingBlocks.

the class MultiConnectFamily method registerBlock.

/**
 * @param root The root block URI of the family
 * @param definition The definition of the block family as passed down from the engine
 * @param blockBuilder The block builder to make the blocks in the family
 * @param sides A byte representing the sides which should be connected for this block
 * @param rotations All of the ways the block should be rotated
 * @return All of the rotations possible for the block with the given sides
 */
public Set<Block> registerBlock(BlockUri root, BlockFamilyDefinition definition, final BlockBuilderHelper blockBuilder, byte sides, Iterable<Rotation> rotations) {
    Set<Block> result = Sets.newLinkedHashSet();
    for (Rotation rotation : rotations) {
        byte sideBits = 0;
        for (Side side : SideBitFlag.getSides(sides)) {
            sideBits |= SideBitFlag.getSide(rotation.rotate(side));
        }
        BlockUri uri = new BlockUri(root, new Name(String.valueOf(sideBits)));
        Block block = blockBuilder.constructTransformedBlock(definition, rotation, uri, this);
        block.setUri(uri);
        blocks.put(sideBits, block);
        result.add(block);
    }
    return result;
}
Also used : Side(org.terasology.engine.math.Side) BlockUri(org.terasology.engine.world.block.BlockUri) Block(org.terasology.engine.world.block.Block) Rotation(org.terasology.engine.math.Rotation) Name(org.terasology.gestalt.naming.Name)

Example 2 with Rotation

use of org.terasology.engine.math.Rotation in project Terasology by MovingBlocks.

the class RotationTest method testRotateSideYaw.

@Test
public void testRotateSideYaw() {
    Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_90);
    Quaternionfc rot = rotation.orientation();
    Vector3f dir = rot.transform(Side.FRONT.toDirection().asVector3f(), new Vector3f());
    assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT));
    assertEquals(Side.LEFT, Rotation.rotate(Yaw.CLOCKWISE_90).rotate(Side.FRONT));
    assertEquals(Side.TOP, Rotation.rotate(Yaw.CLOCKWISE_90).rotate(Side.TOP));
}
Also used : Quaternionfc(org.joml.Quaternionfc) Vector3f(org.joml.Vector3f) Rotation(org.terasology.engine.math.Rotation) Test(org.junit.jupiter.api.Test)

Example 3 with Rotation

use of org.terasology.engine.math.Rotation in project Terasology by MovingBlocks.

the class RotationTest method testRotateMixed.

@Test
public void testRotateMixed() {
    Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_180, Pitch.CLOCKWISE_90, Roll.CLOCKWISE_90);
    Quaternionfc rot = rotation.orientation();
    Vector3f dir = rot.transform(Side.FRONT.toDirection().asVector3f(), new Vector3f());
    assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT));
}
Also used : Quaternionfc(org.joml.Quaternionfc) Vector3f(org.joml.Vector3f) Rotation(org.terasology.engine.math.Rotation) Test(org.junit.jupiter.api.Test)

Example 4 with Rotation

use of org.terasology.engine.math.Rotation in project Terasology by MovingBlocks.

the class RotationTest method testRotateSideRoll.

@Test
public void testRotateSideRoll() {
    Rotation rotation = Rotation.rotate(Roll.CLOCKWISE_90);
    Quaternionfc rot = rotation.orientation();
    Vector3f dir = rot.transform(Side.TOP.toDirection().asVector3f(), new Vector3f());
    assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.TOP));
    assertEquals(Side.LEFT, Rotation.rotate(Roll.CLOCKWISE_90).rotate(Side.TOP));
    assertEquals(Side.FRONT, Rotation.rotate(Roll.CLOCKWISE_90).rotate(Side.FRONT));
}
Also used : Quaternionfc(org.joml.Quaternionfc) Vector3f(org.joml.Vector3f) Rotation(org.terasology.engine.math.Rotation) Test(org.junit.jupiter.api.Test)

Example 5 with Rotation

use of org.terasology.engine.math.Rotation in project Terasology by MovingBlocks.

the class RotationTest method testRotateSidePitch.

@Test
public void testRotateSidePitch() {
    Rotation rotation = Rotation.rotate(Pitch.CLOCKWISE_90);
    Quaternionfc rot = rotation.orientation();
    Vector3f dir = rot.transform(Side.FRONT.toDirection().asVector3f(), new Vector3f());
    assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT));
    assertEquals(Side.TOP, Rotation.rotate(Pitch.CLOCKWISE_90).rotate(Side.FRONT));
    assertEquals(Side.RIGHT, Rotation.rotate(Pitch.CLOCKWISE_90).rotate(Side.RIGHT));
}
Also used : Quaternionfc(org.joml.Quaternionfc) Vector3f(org.joml.Vector3f) Rotation(org.terasology.engine.math.Rotation) Test(org.junit.jupiter.api.Test)

Aggregations

Rotation (org.terasology.engine.math.Rotation)8 Quaternionfc (org.joml.Quaternionfc)4 Vector3f (org.joml.Vector3f)4 Test (org.junit.jupiter.api.Test)4 Side (org.terasology.engine.math.Side)3 BlockUri (org.terasology.engine.world.block.BlockUri)3 Name (org.terasology.gestalt.naming.Name)3 Block (org.terasology.engine.world.block.Block)2 Quaternionf (org.joml.Quaternionf)1 Yaw (org.terasology.engine.math.Yaw)1 CollisionShape (org.terasology.engine.physics.shapes.CollisionShape)1