New TerrainManager class implemented
This commit is contained in:
parent
7966d86a2d
commit
33258c7820
5 changed files with 211 additions and 23 deletions
75
core/test/se/cookery/gfx/terrain/TerrainManagerTest.java
Normal file
75
core/test/se/cookery/gfx/terrain/TerrainManagerTest.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package se.cookery.gfx.terrain;
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TerrainManagerTest {
|
||||
|
||||
private static class TerrainHeightMapImpl implements TerrainHeightMap {
|
||||
public int getSquareCountWidth() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getSquareCountHeight() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void initialization() {
|
||||
TerrainManager manager = new TerrainManager(1, 1, new TerrainHeightMapImpl(), null);
|
||||
Node node = manager.getNode();
|
||||
|
||||
assertEquals(TerrainManager.BUFFER_SIZE*TerrainManager.BUFFER_SIZE, node.getChildren().size());
|
||||
|
||||
for (int x=0; x<TerrainManager.BUFFER_SIZE; x++) {
|
||||
for (int y=0; y<TerrainManager.BUFFER_SIZE; y++) {
|
||||
assertNotNull(node.getChild("TerrainMesh " + x + "x" + y), "TerrainMesh missing: TerrainMesh " + x + "x" + y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void setTerrainCenter() {
|
||||
TerrainManager manager = new TerrainManager(1, 1, new TerrainHeightMapImpl(), null);
|
||||
Node node = manager.getNode();
|
||||
|
||||
assertEquals(new Vector3f(-1, 0, -1), node.getChild("TerrainMesh 0x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 0, 0, -1), node.getChild("TerrainMesh 1x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 1, 0, -1), node.getChild("TerrainMesh 2x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f(-1, 0, 0), node.getChild("TerrainMesh 0x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 0, 0, 0), node.getChild("TerrainMesh 1x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 1, 0, 0), node.getChild("TerrainMesh 2x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f(-1, 0, 1), node.getChild("TerrainMesh 0x2").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 0, 0, 1), node.getChild("TerrainMesh 1x2").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 1, 0, 1), node.getChild("TerrainMesh 2x2").getLocalTranslation());
|
||||
|
||||
manager.setTerrainCenter(new Vector3f(10, 0, 10));
|
||||
|
||||
assertEquals(new Vector3f( 9, 0, 9), node.getChild("TerrainMesh 0x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f(10, 0, 9), node.getChild("TerrainMesh 1x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f(11, 0, 9), node.getChild("TerrainMesh 2x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 9, 0, 10), node.getChild("TerrainMesh 0x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f(10, 0, 10), node.getChild("TerrainMesh 1x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f(11, 0, 10), node.getChild("TerrainMesh 2x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 9, 0, 11), node.getChild("TerrainMesh 0x2").getLocalTranslation());
|
||||
assertEquals(new Vector3f(10, 0, 11), node.getChild("TerrainMesh 1x2").getLocalTranslation());
|
||||
assertEquals(new Vector3f(11, 0, 11), node.getChild("TerrainMesh 2x2").getLocalTranslation());
|
||||
|
||||
manager.setTerrainCenter(new Vector3f(0.1f, 0, 0.1f));
|
||||
|
||||
assertEquals(new Vector3f(-1, 0, -1), node.getChild("TerrainMesh 0x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 0, 0, -1), node.getChild("TerrainMesh 1x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 1, 0, -1), node.getChild("TerrainMesh 2x0").getLocalTranslation());
|
||||
assertEquals(new Vector3f(-1, 0, 0), node.getChild("TerrainMesh 0x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 0, 0, 0), node.getChild("TerrainMesh 1x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 1, 0, 0), node.getChild("TerrainMesh 2x1").getLocalTranslation());
|
||||
assertEquals(new Vector3f(-1, 0, 1), node.getChild("TerrainMesh 0x2").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 0, 0, 1), node.getChild("TerrainMesh 1x2").getLocalTranslation());
|
||||
assertEquals(new Vector3f( 1, 0, 1), node.getChild("TerrainMesh 2x2").getLocalTranslation());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue