use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class ChunkViewTest method testSimpleWorldView.
@Test
public void testSimpleWorldView() {
Chunk chunk = createChunk(0, 0, 0);
chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
ChunkViewCore chunkView = new ChunkViewCoreImpl(new Chunk[] { chunk }, new BlockRegion(0, 0, 0), new Vector3i(), airBlock);
assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class ChunkViewTest method testLocalToWorld.
@Test
public void testLocalToWorld() {
Chunk chunk = createChunk(1, 0, 1);
chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
Chunk[] chunks = new Chunk[] { createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2) };
ChunkViewCoreImpl chunkView = new ChunkViewCoreImpl(chunks, new BlockRegion(1, 0, 1).expand(1, 0, 1), new Vector3i(1, 1, 1), airBlock);
assertEquals(new Vector3i(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z), chunkView.toWorldPos(new Vector3i()));
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class ChunkViewTest method testOffsetChunksWorldView.
@Test
public void testOffsetChunksWorldView() {
Chunk chunk = createChunk(1, 0, 1);
chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
Chunk[] chunks = new Chunk[] { createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2) };
ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, new BlockRegion(1, 0, 1).expand(1, 0, 1), new Vector3i(1, 0, 1), airBlock);
assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class RegionOutlineRenderer method renderOverlay.
@Override
public void renderOverlay() {
if (entityToRegionOutlineMap.isEmpty()) {
// skip everything if there is nothing to do to avoid possibly costly draw mode changes
return;
}
GL33.glDepthFunc(GL33.GL_ALWAYS);
Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition();
Vector3f worldPos = new Vector3f();
Vector3f worldPositionCameraSpace = new Vector3f();
worldPos.sub(cameraPosition, worldPositionCameraSpace);
Matrix4f matrixCameraSpace = new Matrix4f().translationRotateScale(worldPositionCameraSpace, new Quaternionf(), 1.0f);
Matrix4f modelViewMatrix = new Matrix4f(worldRenderer.getActiveCamera().getViewMatrix()).mul(matrixCameraSpace);
material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix());
material.setMatrix4("modelViewMatrix", modelViewMatrix, true);
meshData.reallocate(0, 0);
meshData.indices.rewind();
meshData.position.rewind();
meshData.color0.rewind();
int index = 0;
Vector3f pos = new Vector3f();
for (RegionOutlineComponent regionOutline : entityToRegionOutlineMap.values()) {
if (regionOutline.corner1 == null || regionOutline.corner2 == null) {
continue;
}
BlockRegion region = new BlockRegion(regionOutline.corner1).union(regionOutline.corner2);
AABBf bounds = region.getBounds(new AABBf());
meshData.position.put(pos.set(bounds.minX, bounds.minY, bounds.minZ));
meshData.position.put(pos.set(bounds.maxX, bounds.minY, bounds.minZ));
meshData.position.put(pos.set(bounds.maxX, bounds.minY, bounds.maxZ));
meshData.position.put(pos.set(bounds.minX, bounds.minY, bounds.maxZ));
meshData.position.put(pos.set(bounds.minX, bounds.maxY, bounds.minZ));
meshData.position.put(pos.set(bounds.maxX, bounds.maxY, bounds.minZ));
meshData.position.put(pos.set(bounds.maxX, bounds.maxY, bounds.maxZ));
meshData.position.put(pos.set(bounds.minX, bounds.maxY, bounds.maxZ));
meshData.color0.put(regionOutline.color);
meshData.color0.put(regionOutline.color);
meshData.color0.put(regionOutline.color);
meshData.color0.put(regionOutline.color);
meshData.color0.put(regionOutline.color);
meshData.color0.put(regionOutline.color);
meshData.color0.put(regionOutline.color);
meshData.color0.put(regionOutline.color);
meshData.indices.putAll(new int[] { // top loop
index, index + 1, index + 1, index + 2, index + 2, index + 3, index + 3, index, // connecting edges between top and bottom
index, index + 4, index + 1, index + 5, index + 2, index + 6, index + 3, index + 7, // bottom loop
index + 4, index + 5, index + 5, index + 6, index + 6, index + 7, index + 7, index + 4 });
index += 8;
}
material.enable();
mesh.reload(meshData);
mesh.render();
GL33.glDepthFunc(GL33.GL_LEQUAL);
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class InternalLightGeneratorTest method testBlockedSunlightRegenPropagationResets.
@Test
public void testBlockedSunlightRegenPropagationResets() {
Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
for (Vector3ic pos : new BlockRegion(0, 60, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
chunk.setBlock(pos, solidBlock);
}
InternalLightProcessor.generateInternalLighting(chunk);
for (Vector3ic pos : new BlockRegion(0, 61, 0).setSize(Chunks.SIZE_X, 3, Chunks.SIZE_Z)) {
byte expectedRegen = (byte) Math.min(Chunks.SIZE_Y - pos.y() - 1, Chunks.MAX_SUNLIGHT_REGEN);
assertEquals(expectedRegen, chunk.getSunlightRegen(pos));
}
for (Vector3ic pos : new BlockRegion(0, 60, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
assertEquals(0, chunk.getSunlightRegen(pos));
}
for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 59, Chunks.SIZE_Z)) {
byte expectedRegen = (byte) Math.min(60 - pos.y() - 1, Chunks.MAX_SUNLIGHT_REGEN);
assertEquals(expectedRegen, chunk.getSunlightRegen(pos));
}
}
Aggregations