Search in sources :

Example 81 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class BlockSelectionSystem method onStartSelectionAtEntity.

@ReceiveEvent(components = { LocationComponent.class })
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity) {
    LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
    if (null == locationComponent) {
        // entity isn't LocationComponent, which shouldn't ever be the case
        return;
    }
    BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
    if (null == blockSelectionComponent) {
        // event did not provide a BlockSelection component to modify
        return;
    }
    Vector3f worldPosition = locationComponent.getWorldPosition();
    Vector3i startPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
    blockSelectionComponent.startPosition = startPosition;
    Vector3i endPosition = startPosition;
    blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 82 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class BlockSelectionSystem method onEndSelectionAtEntity.

@ReceiveEvent(components = { LocationComponent.class })
public void onEndSelectionAtEntity(SetBlockSelectionEndingPointEvent event, EntityRef entity) {
    LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
    if (null == locationComponent) {
        // entity isn't LocationComponent, which shouldn't ever be the case
        return;
    }
    BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
    if (null == blockSelectionComponent) {
        // event did not provide a BlockSelection component to modify
        return;
    }
    Vector3f worldPosition = locationComponent.getWorldPosition();
    Vector3i endPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
    Vector3i startPosition = blockSelectionComponent.startPosition;
    if (null == startPosition) {
        startPosition = endPosition;
    }
    blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 83 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class BlockItemSystem method canPlaceBlock.

private boolean canPlaceBlock(Block block, Vector3i targetBlock, Vector3i blockPos) {
    if (block == null) {
        return false;
    }
    Block centerBlock = worldProvider.getBlock(targetBlock.x, targetBlock.y, targetBlock.z);
    if (!centerBlock.isAttachmentAllowed()) {
        return false;
    }
    Block adjBlock = worldProvider.getBlock(blockPos.x, blockPos.y, blockPos.z);
    if (!adjBlock.isReplacementAllowed() || adjBlock.isTargetable()) {
        return false;
    }
    if (block.getBlockFamily().equals(adjBlock.getBlockFamily())) {
        return false;
    }
    // Prevent players from placing blocks inside their bounding boxes
    if (!block.isPenetrable()) {
        Physics physics = CoreRegistry.get(Physics.class);
        AABB blockBounds = block.getBounds(blockPos);
        Vector3f min = new Vector3f(blockBounds.getMin());
        Vector3f max = new Vector3f(blockBounds.getMax());
        /**
         * Characters can enter other solid objects/blocks for certain amount. This is does to detect collsion
         * start and end without noise. So if the user walked as close to a block as possible it is only natural
         * to let it place a block exactly above it even if that technically would mean a collision start.
         */
        min.x += KinematicCharacterMover.HORIZONTAL_PENETRATION;
        max.x -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
        min.y += KinematicCharacterMover.VERTICAL_PENETRATION;
        max.y -= KinematicCharacterMover.VERTICAL_PENETRATION;
        min.z += KinematicCharacterMover.HORIZONTAL_PENETRATION;
        max.z -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
        /*
             * Calculations aren't exact and in the corner cases it is better to let the user place the block.
             */
        // ignore small rounding mistakes
        float additionalAllowedPenetration = 0.04f;
        min.add(ADDITIONAL_ALLOWED_PENETRATION, ADDITIONAL_ALLOWED_PENETRATION, ADDITIONAL_ALLOWED_PENETRATION);
        max.sub(ADDITIONAL_ALLOWED_PENETRATION, ADDITIONAL_ALLOWED_PENETRATION, ADDITIONAL_ALLOWED_PENETRATION);
        AABB newBounds = AABB.createMinMax(min, max);
        return physics.scanArea(newBounds, StandardCollisionGroup.DEFAULT, StandardCollisionGroup.CHARACTER).isEmpty();
    }
    return true;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Block(org.terasology.world.block.Block) Physics(org.terasology.physics.Physics) AABB(org.terasology.math.AABB)

Example 84 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class HeadlessWorldRenderer method distanceToCamera.

private float distanceToCamera(RenderableChunk chunk) {
    Vector3f result = new Vector3f((chunk.getPosition().x + 0.5f) * ChunkConstants.SIZE_X, 0, (chunk.getPosition().z + 0.5f) * ChunkConstants.SIZE_Z);
    Vector3f cameraPos = getActiveCamera().getPosition();
    result.x -= cameraPos.x;
    result.z -= cameraPos.z;
    return result.length();
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Example 85 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class BlockShapeTest method testConvexHull.

@Test
public void testConvexHull() {
    BlockShape blockShape = assetManager.getAsset("engine:halfSlope", BlockShape.class).get();
    CollisionShape shape = blockShape.getCollisionShape(Rotation.rotate(Yaw.CLOCKWISE_90));
    Assert.assertEquals(shape instanceof ConvexHullShape, true);
    if (shape instanceof ConvexHullShape) {
        Vector3f[] test = new Vector3f[] { new Vector3f(0.49999997f, 0.0f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, 0.49999997f), new Vector3f(0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(0.49999997f, 0.0f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, -0.49999997f), new Vector3f(-0.49999997f, -0.49999997f, 0.49999997f), new Vector3f(0.49999997f, 0.0f, 0.49999997f) };
        BulletConvexHullShape bulletConvexHullShape = (BulletConvexHullShape) shape;
        ObjectArrayList<javax.vecmath.Vector3f> points = ((com.bulletphysics.collision.shapes.ConvexHullShape) bulletConvexHullShape.underlyingShape).getPoints();
        for (int x = 0; x < points.size(); x++) {
            fuzzVectorTest(test[x], VecMath.from(points.get(x)));
        }
    }
}
Also used : CollisionShape(org.terasology.physics.shapes.CollisionShape) BlockShape(org.terasology.world.block.shapes.BlockShape) Vector3f(org.terasology.math.geom.Vector3f) BulletConvexHullShape(org.terasology.physics.bullet.shapes.BulletConvexHullShape) ConvexHullShape(org.terasology.physics.shapes.ConvexHullShape) BulletConvexHullShape(org.terasology.physics.bullet.shapes.BulletConvexHullShape) Test(org.junit.Test)

Aggregations

Vector3f (org.terasology.math.geom.Vector3f)194 LocationComponent (org.terasology.logic.location.LocationComponent)45 EntityRef (org.terasology.entitySystem.entity.EntityRef)44 Quat4f (org.terasology.math.geom.Quat4f)33 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)26 Vector3i (org.terasology.math.geom.Vector3i)21 Test (org.junit.Test)20 ClientComponent (org.terasology.network.ClientComponent)15 Command (org.terasology.logic.console.commandSystem.annotations.Command)14 Matrix4f (org.terasology.math.geom.Matrix4f)13 BaseVector3f (org.terasology.math.geom.BaseVector3f)9 Block (org.terasology.world.block.Block)9 Vector2f (org.terasology.math.geom.Vector2f)8 HitResult (org.terasology.physics.HitResult)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 IOException (java.io.IOException)6 FloatBuffer (java.nio.FloatBuffer)6 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 AABB (org.terasology.math.AABB)5 ChunkMesh (org.terasology.rendering.primitives.ChunkMesh)5