public static Rotation rotate(Yaw yaw, Roll roll) { return rotate(yaw, Pitch.NONE, roll); }
private static Rotation findReverseInternal(Rotation rotation) { Side frontResult = rotation.rotate(Side.FRONT); Side topResult = rotation.rotate(Side.TOP); for (Rotation possibility : values()) { if (possibility.rotate(frontResult) == Side.FRONT && possibility.rotate(topResult) == Side.TOP) { return possibility; } } throw new RuntimeException("Unable to find reverse rotation"); }
@Test public void testRotateSideYaw() { Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), 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)); }
public HorizontalFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) { super(definition, blockBuilder); BlockUri uri = new BlockUri(definition.getUrn()); for (Rotation rot : Rotation.horizontalRotations()) { Side side = rot.rotate(Side.FRONT); Block block = blockBuilder.constructTransformedBlock(definition, side.toString().toLowerCase(Locale.ENGLISH), rot, new BlockUri(uri, new Name(side.name())), this); if (block == null) { throw new IllegalArgumentException("Missing block for side: " + side.toString()); } blocks.put(side, block); } }
private ColliderInfo processCompoundShape(List<ColliderInfo> colliders) { CompoundShape collisionShape = COLLISION_SHAPE_FACTORY.getNewCompoundShape(); for (ColliderInfo collider : colliders) { Transform transform = new Transform(collider.offset, Rotation.none().getQuat4f(), 1.0f); collisionShape.addChildShape(transform, collider.collisionShape); } return new ColliderInfo(new Vector3f(), collisionShape); }
@Test public void testReverseRotation() { for (Rotation rotation : Rotation.allValues()) { Rotation reverseRotation = Rotation.findReverse(rotation); for (Side side : Side.getAllSides()) { assertEquals(side, reverseRotation.rotate(rotation.rotate(side))); } } } }
@Override public Block constructSimpleBlock(BlockFamilyDefinition definition, BlockShape shape, BlockUri uri, BlockFamily blockFamily) { return constructCustomBlock(definition.getUrn().getResourceName().toString(), shape, Rotation.none(), definition.getData().getBaseSection(), uri, blockFamily); }
@Override public CollisionShape getCollisionShape(Rotation rot) { Rotation simplifiedRot = applySymmetry(rot); CollisionShape result = collisionShape.get(simplifiedRot); if (result == null && baseCollisionShape != null) { result = baseCollisionShape.rotate(simplifiedRot.getQuat4f()); collisionShape.put(simplifiedRot, result); } return result; }
@Test public void testRotateSideRoll() { Rotation rotation = Rotation.rotate(Roll.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.TOP.toDirection().getVector3f(), 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)); }
public HorizontalFamily(BlockFamilyDefinition definition, BlockShape shape, BlockBuilderHelper blockBuilder) { super(definition, shape, blockBuilder); BlockUri uri; if (CUBE_SHAPE_URN.equals(shape.getUrn())) { uri = new BlockUri(definition.getUrn()); } else { uri = new BlockUri(definition.getUrn(), shape.getUrn()); } for (Rotation rot : Rotation.horizontalRotations()) { Side side = rot.rotate(Side.FRONT); Block block = blockBuilder.constructTransformedBlock(definition, shape, side.toString().toLowerCase(Locale.ENGLISH), rot, new BlockUri(uri, new Name(side.name())), this); if (block == null) { throw new IllegalArgumentException("Missing block for side: " + side.toString()); } blocks.put(side, block); } setBlockUri(uri); }
@Override public CollisionShape rotate(Quat4f rot) { CompoundShape newShape = new CompoundShape(); for (BulletCompoundShapeChild child : childList) { CollisionShape rotatedChild = child.childShape.rotate(rot); javax.vecmath.Vector3f offset = com.bulletphysics.linearmath.QuaternionUtil.quatRotate(VecMath.to(rot), child.transform.origin, new javax.vecmath.Vector3f()); newShape.addChildShape(new Transform(new javax.vecmath.Matrix4f(VecMath.to(Rotation.none().getQuat4f()), offset, 1.0f)), ((BulletCollisionShape) rotatedChild).underlyingShape); } return new BulletCompoundShape(newShape); }
@Override public Block constructSimpleBlock(BlockFamilyDefinition definition, BlockShape shape, String section, BlockUri uri, BlockFamily blockFamily) { return constructCustomBlock(definition.getUrn().getResourceName().toString(), shape, Rotation.none(), definition.getData().getSection(section), uri, blockFamily); }
private BlockAppearance createAppearance(BlockShape shape, Map<BlockPart, BlockTile> tiles, Rotation rot) { Map<BlockPart, BlockMeshPart> meshParts = Maps.newEnumMap(BlockPart.class); Map<BlockPart, Vector2f> textureAtlasPositions = Maps.newEnumMap(BlockPart.class); for (BlockPart part : BlockPart.values()) { // TODO: Need to be more sensible with the texture atlas. Because things like block particles read from a part that may not exist, we're being fairly lenient Vector2f atlasPos; if (tiles.get(part) == null) { atlasPos = new Vector2f(); } else { atlasPos = worldAtlas.getTexCoords(tiles.get(part), shape.getMeshPart(part) != null); } BlockPart targetPart = part.rotate(rot); textureAtlasPositions.put(targetPart, atlasPos); if (shape.getMeshPart(part) != null) { meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.getQuat4f()).mapTexCoords(atlasPos, worldAtlas.getRelativeTileSize())); } } return new BlockAppearance(meshParts, textureAtlasPositions); }
@Test public void testRotateSidePitch() { Rotation rotation = Rotation.rotate(Pitch.CLOCKWISE_90); Quat4f rot = rotation.getQuat4f(); Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), 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)); }
public static Rotation rotate(Roll roll) { return rotate(Yaw.NONE, Pitch.NONE, roll); }
if (definition.getData().hasSection("top")) { Block block = blockBuilder.constructSimpleBlock(definition, "top", new BlockUri(definition.getUrn(), new Name(Side.TOP.name())), this); block.setRotation(Rotation.rotate(Pitch.CLOCKWISE_270)); blockMap.put(Side.TOP, block); for (Rotation rot : Rotation.horizontalRotations()) { Side side = rot.rotate(Side.FRONT); blockMap.put(side, blockBuilder.constructTransformedBlock(definition, side.toString().toLowerCase(Locale.ENGLISH), rot, new BlockUri(definition.getUrn(), new Name(side.name())), this)); block.setRotation(Rotation.rotate(Pitch.CLOCKWISE_90)); blockMap.put(Side.BOTTOM, block);