use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class AudioSystem method playTestSound.
/**
* Plays a test dig sound at an offset from the player in the x and z axis.
*
* @param sender The entity sending the sound request
* @param xOffset The x axis offset from the player to play the sound at.
* @param zOffset The z axis offset from the player to play the sound at.
*/
@Command(shortDescription = "Plays a test sound")
public void playTestSound(@Sender EntityRef sender, @CommandParam("xOffset") float xOffset, @CommandParam("zOffset") float zOffset) {
Vector3f position = localPlayer.getPosition();
position.x += xOffset;
position.z += zOffset;
audioManager.playSound(Assets.getSound("engine:dig").get(), position);
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class CameraTargetSystem method updateFocalDistance.
private void updateFocalDistance(HitResult hitInfo, float delta) {
// how fast the focus distance is updated
float focusRate = 4.0f;
// if the hit result from a trace has a recorded a hit
if (hitInfo.isHit()) {
Vector3f playerToTargetRay = new Vector3f();
// calculate the distance from the player to the hit point
playerToTargetRay.sub(hitInfo.getHitPoint(), localPlayer.getViewPosition());
// gradually adjust focalDistance from it's current value to the hit point distance
focalDistance = TeraMath.lerp(focalDistance, playerToTargetRay.length(), delta * focusRate);
// if nothing was hit, gradually adjust the focusDistance to the maximum length of the update function trace
} else {
focalDistance = TeraMath.lerp(focalDistance, targetDistance, delta * focusRate);
}
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class SimpleAISystem method update.
@Override
public void update(float delta) {
for (EntityRef entity : entityManager.getEntitiesWith(SimpleAIComponent.class, CharacterMovementComponent.class, LocationComponent.class)) {
LocationComponent location = entity.getComponent(LocationComponent.class);
Vector3f worldPos = location.getWorldPosition();
// Skip this AI if not in a loaded chunk
if (!worldProvider.isBlockRelevant(worldPos)) {
continue;
}
SimpleAIComponent ai = entity.getComponent(SimpleAIComponent.class);
Vector3f drive = new Vector3f();
// TODO: shouldn't use local player, need some way to find nearest player
if (localPlayer != null) {
Vector3f dist = new Vector3f(worldPos);
dist.sub(localPlayer.getPosition());
double distanceToPlayer = dist.lengthSquared();
if (distanceToPlayer > 6 && distanceToPlayer < 16) {
// Head to player
ai.movementTarget.set(localPlayer.getPosition());
ai.followingPlayer = true;
entity.saveComponent(ai);
} else {
// Random walk
if (time.getGameTimeInMs() - ai.lastChangeOfDirectionAt > 12000 || ai.followingPlayer) {
ai.movementTarget.set(worldPos.x + random.nextFloat(-500.0f, 500.0f), worldPos.y, worldPos.z + random.nextFloat(-500.0f, 500.0f));
ai.lastChangeOfDirectionAt = time.getGameTimeInMs();
ai.followingPlayer = false;
entity.saveComponent(ai);
}
}
Vector3f targetDirection = new Vector3f();
targetDirection.sub(ai.movementTarget, worldPos);
targetDirection.normalize();
drive.set(targetDirection);
float yaw = (float) Math.atan2(targetDirection.x, targetDirection.z);
location.getLocalRotation().set(new Vector3f(0, 1, 0), yaw);
entity.saveComponent(location);
}
entity.send(new CharacterMoveInputEvent(0, 0, 0, drive, false, false, time.getGameDeltaInMs()));
}
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class Vector3iTest method testOffsetConstructorWithNegatives.
@Test
public void testOffsetConstructorWithNegatives() {
Vector3f vOrig = new Vector3f(-0.1f, -0.6f, -1.4f);
Vector3i v = new Vector3i(vOrig, 0.5f);
assertEquals(new Vector3i(0, -1, -1), v);
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.
@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager);
chunk.setBlock(0, 0, 0, testBlock);
chunk.markReady();
ChunkProvider chunkProvider = mock(ChunkProvider.class);
when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
CoreRegistry.put(ChunkProvider.class, chunkProvider);
EntityRef entity = entityManager.create();
long id = entity.getId();
LocationComponent locationComponent = new LocationComponent();
Vector3f positionInChunk = new Vector3f(chunk.getAABB().getMin());
positionInChunk.x += 1;
positionInChunk.y += 1;
positionInChunk.z += 1;
locationComponent.setWorldPosition(positionInChunk);
entity.addComponent(locationComponent);
esm.waitForCompletionOfPreviousSaveAndStartSaving();
esm.finishSavingAndShutdown();
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, false);
newSM.loadGlobalStore();
ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
restored.restoreEntities();
EntityRef ref = newEntityManager.getEntity(id);
assertTrue(ref.exists());
assertTrue(ref.isActive());
}
Aggregations