Search in sources :

Example 1 with AABBfc

use of org.terasology.joml.geom.AABBfc in project Terasology by MovingBlocks.

the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.

@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
    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();
    AABBfc aabb = chunk.getAABB();
    Vector3f positionInChunk = new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ());
    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, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    restored.restoreEntities();
    EntityRef ref = newEntityManager.getEntity(id);
    assertTrue(ref.exists());
    assertTrue(ref.isActive());
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3f(org.joml.Vector3f) StorageManager(org.terasology.engine.persistence.StorageManager) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 2 with AABBfc

use of org.terasology.joml.geom.AABBfc in project Terasology by MovingBlocks.

the class ChunkTest method testGetAabb.

@Test
public void testGetAabb() {
    AABBfc aabb = chunk.getAABB();
    assertEquals(new Vector3f(-.5f, -.5f, -.5f), new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ()));
    assertEquals(new Vector3f(Chunks.SIZE_X - .5f, Chunks.SIZE_Y - .5f, Chunks.SIZE_Z - .5f), new Vector3f(aabb.maxX(), aabb.maxY(), aabb.maxZ()));
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) Vector3f(org.joml.Vector3f) Test(org.junit.jupiter.api.Test)

Example 3 with AABBfc

use of org.terasology.joml.geom.AABBfc in project Terasology by MovingBlocks.

the class AbstractStorageManager method getEntitiesOfChunk.

protected Collection<EntityRef> getEntitiesOfChunk(Chunk chunk) {
    List<EntityRef> entitiesToStore = Lists.newArrayList();
    AABBfc aabb = chunk.getAABB();
    for (EntityRef entity : getEntityManager().getEntitiesWith(LocationComponent.class)) {
        if (!entity.getOwner().exists() && !entity.isAlwaysRelevant() && !entity.hasComponent(ClientComponent.class)) {
            LocationComponent loc = entity.getComponent(LocationComponent.class);
            if (loc == null) {
                continue;
            }
            Vector3f pos = loc.getWorldPosition(new Vector3f());
            if (pos.isFinite()) {
                if (aabb.containsPoint(loc.getWorldPosition(new Vector3f()))) {
                    entitiesToStore.add(entity);
                }
            }
        }
    }
    return entitiesToStore;
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 4 with AABBfc

use of org.terasology.joml.geom.AABBfc in project Terasology by MovingBlocks.

the class LwjglCanvasRenderer method drawMesh.

@Override
public void drawMesh(Mesh mesh, Material material, Rectanglei drawRegion, Rectanglei cropRegion, Quaternionfc rotation, Vector3fc offset, float scale, float alpha) {
    if (!material.isRenderable()) {
        return;
    }
    AABBfc meshAABB = mesh.getAABB();
    Vector3f meshExtents = meshAABB.extent(new Vector3f());
    float fitScale = 0.35f * Math.min(drawRegion.getSizeX(), drawRegion.getSizeY()) / Math.max(meshExtents.x, Math.max(meshExtents.y, meshExtents.z));
    Vector3f centerOffset = meshAABB.center(new Vector3f());
    centerOffset.mul(-1.0f);
    Matrix4f centerTransform = new Matrix4f().translationRotateScale(centerOffset, new Quaternionf(), 1);
    Matrix4f userTransform = new Matrix4f().translationRotateScale(offset, rotation, -fitScale * scale);
    Matrix4f translateTransform = new Matrix4f().translationRotateScale(new Vector3f((drawRegion.minX + drawRegion.getSizeX() / 2) * uiScale, (drawRegion.minY + drawRegion.getSizeY() / 2) * uiScale, 0), new Quaternionf(), 1);
    userTransform.mul(centerTransform);
    translateTransform.mul(userTransform);
    Matrix4f finalMat = new Matrix4f().setTranslation(0, 0, -1024f);
    finalMat.mul(translateTransform);
    material.setFloat4(CROPPING_BOUNDARIES_PARAM, cropRegion.minX * uiScale, cropRegion.maxX * uiScale, cropRegion.minY * uiScale, cropRegion.maxY * uiScale);
    glEnable(GL11.GL_DEPTH_TEST);
    glClear(GL11.GL_DEPTH_BUFFER_BIT);
    modelMatrixStack.pushMatrix();
    modelMatrixStack.set(finalMat);
    modelMatrixStack.scale(this.uiScale, this.uiScale, this.uiScale);
    material.setMatrix4("posMatrix", translateTransform);
    material.setMatrix4("projectionMatrix", projMatrix);
    material.setMatrix4("modelViewMatrix", modelMatrixStack);
    material.setMatrix3("normalMatrix", modelMatrixStack.normal(new Matrix3f()));
    material.setFloat("alpha", alpha);
    material.bindTextures();
    mesh.render();
    modelMatrixStack.popMatrix();
    glDisable(GL11.GL_DEPTH_TEST);
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) Matrix4f(org.joml.Matrix4f) Matrix3f(org.joml.Matrix3f) Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf)

Aggregations

Vector3f (org.joml.Vector3f)4 AABBfc (org.terasology.joml.geom.AABBfc)4 Test (org.junit.jupiter.api.Test)2 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 LocationComponent (org.terasology.engine.logic.location.LocationComponent)2 Matrix3f (org.joml.Matrix3f)1 Matrix4f (org.joml.Matrix4f)1 Quaternionf (org.joml.Quaternionf)1 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)1 ChunkStore (org.terasology.engine.persistence.ChunkStore)1 StorageManager (org.terasology.engine.persistence.StorageManager)1 Chunk (org.terasology.engine.world.chunks.Chunk)1 ChunkProvider (org.terasology.engine.world.chunks.ChunkProvider)1 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)1