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);
}
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);
}
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;
}
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();
}
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)));
}
}
}
Aggregations