Search in sources :

Example 6 with Rotation

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

the class CeilingSupportingHorizontalFamily method populateBlockMaps.

/**
 * Populates the map with all 8 rotations of the block that are possible.
 * <p>
 * These are all four 90 degree rotations about the Y-axis (YAW) for each case where the TOP side is
 * - facing upwards
 * - facing downwards
 *
 * @param blockBuilder The block builder to use to produce blocks
 * @param shape        The shape the block should be made in
 * @param definition   The definition for the family
 * @param uri          The base URI for the block
 */
private void populateBlockMaps(BlockBuilderHelper blockBuilder, BlockShape shape, BlockFamilyDefinition definition, BlockUri uri) {
    for (Rotation rotation : Rotation.horizontalRotations()) {
        Side horizontalSide = rotation.rotate(Side.FRONT);
        ExtendedSide extendedSideTop = ExtendedSide.getExtendedSideFor(Side.TOP, horizontalSide);
        blocks.put(extendedSideTop, transformBlock(blockBuilder, shape, definition, new BlockUri(uri, new Name(extendedSideTop.name())), rotation, extendedSideTop));
        ExtendedSide extendedSideBottom = ExtendedSide.getExtendedSideFor(Side.BOTTOM, horizontalSide);
        Yaw yaw = Rotation.horizontalRotations().get((rotation.getYaw().getIndex() + 2) % 4).getYaw();
        blocks.put(extendedSideBottom, transformBlock(blockBuilder, shape, definition, new BlockUri(uri, new Name(extendedSideBottom.name())), Rotation.rotate(yaw, Pitch.CLOCKWISE_180, Roll.NONE), extendedSideBottom));
    }
}
Also used : Side(org.terasology.engine.math.Side) BlockUri(org.terasology.engine.world.block.BlockUri) Rotation(org.terasology.engine.math.Rotation) Yaw(org.terasology.engine.math.Yaw) Name(org.terasology.gestalt.naming.Name)

Example 7 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 name The name of the section of the block to be registered, ex: "no_connections"
 * @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, BlockBuilderHelper blockBuilder, String name, 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));
        }
        Block block = blockBuilder.constructTransformedBlock(definition, name, rotation, new BlockUri(root, new Name(String.valueOf(sideBits))), this);
        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 8 with Rotation

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

the class BlockShapeImpl method getCollisionShape.

@Override
public CollisionShape getCollisionShape(Rotation rot) {
    Rotation simplifiedRot = applySymmetry(rot);
    CollisionShape result = collisionShape.get(simplifiedRot);
    if (result == null && baseCollisionShape != null) {
        result = baseCollisionShape.rotate(new Quaternionf(simplifiedRot.orientation()));
        collisionShape.put(simplifiedRot, result);
    }
    return result;
}
Also used : CollisionShape(org.terasology.engine.physics.shapes.CollisionShape) Quaternionf(org.joml.Quaternionf) Rotation(org.terasology.engine.math.Rotation)

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