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