|
@@ -76,50 +76,50 @@ public class HelloTerrainCollision extends SimpleApplication
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void simpleInitApp() {
|
|
public void simpleInitApp() {
|
|
- /** Set up Physics */
|
|
|
|
|
|
+ /* Set up physics */
|
|
bulletAppState = new BulletAppState();
|
|
bulletAppState = new BulletAppState();
|
|
stateManager.attach(bulletAppState);
|
|
stateManager.attach(bulletAppState);
|
|
|
|
|
|
flyCam.setMoveSpeed(100);
|
|
flyCam.setMoveSpeed(100);
|
|
setUpKeys();
|
|
setUpKeys();
|
|
|
|
|
|
- /** 1. Create terrain material and load four textures into it. */
|
|
|
|
|
|
+ /* 1. Create terrain material and load four textures into it. */
|
|
Material mat_terrain = new Material(assetManager,
|
|
Material mat_terrain = new Material(assetManager,
|
|
"Common/MatDefs/Terrain/Terrain.j3md");
|
|
"Common/MatDefs/Terrain/Terrain.j3md");
|
|
|
|
|
|
- /** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
|
|
|
|
|
|
+ /* 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
|
|
mat_terrain.setTexture("Alpha", assetManager.loadTexture(
|
|
mat_terrain.setTexture("Alpha", assetManager.loadTexture(
|
|
"Textures/Terrain/splat/alphamap.png"));
|
|
"Textures/Terrain/splat/alphamap.png"));
|
|
|
|
|
|
- /** 1.2) Add GRASS texture into the red layer (Tex1). */
|
|
|
|
|
|
+ /* 1.2) Add GRASS texture into the red layer (Tex1). */
|
|
Texture grass = assetManager.loadTexture(
|
|
Texture grass = assetManager.loadTexture(
|
|
"Textures/Terrain/splat/grass.jpg");
|
|
"Textures/Terrain/splat/grass.jpg");
|
|
grass.setWrap(WrapMode.Repeat);
|
|
grass.setWrap(WrapMode.Repeat);
|
|
mat_terrain.setTexture("Tex1", grass);
|
|
mat_terrain.setTexture("Tex1", grass);
|
|
mat_terrain.setFloat("Tex1Scale", 64f);
|
|
mat_terrain.setFloat("Tex1Scale", 64f);
|
|
|
|
|
|
- /** 1.3) Add DIRT texture into the green layer (Tex2) */
|
|
|
|
|
|
+ /* 1.3) Add DIRT texture into the green layer (Tex2) */
|
|
Texture dirt = assetManager.loadTexture(
|
|
Texture dirt = assetManager.loadTexture(
|
|
"Textures/Terrain/splat/dirt.jpg");
|
|
"Textures/Terrain/splat/dirt.jpg");
|
|
dirt.setWrap(WrapMode.Repeat);
|
|
dirt.setWrap(WrapMode.Repeat);
|
|
mat_terrain.setTexture("Tex2", dirt);
|
|
mat_terrain.setTexture("Tex2", dirt);
|
|
mat_terrain.setFloat("Tex2Scale", 32f);
|
|
mat_terrain.setFloat("Tex2Scale", 32f);
|
|
|
|
|
|
- /** 1.4) Add ROAD texture into the blue layer (Tex3) */
|
|
|
|
|
|
+ /* 1.4) Add ROAD texture into the blue layer (Tex3) */
|
|
Texture rock = assetManager.loadTexture(
|
|
Texture rock = assetManager.loadTexture(
|
|
"Textures/Terrain/splat/road.jpg");
|
|
"Textures/Terrain/splat/road.jpg");
|
|
rock.setWrap(WrapMode.Repeat);
|
|
rock.setWrap(WrapMode.Repeat);
|
|
mat_terrain.setTexture("Tex3", rock);
|
|
mat_terrain.setTexture("Tex3", rock);
|
|
mat_terrain.setFloat("Tex3Scale", 128f);
|
|
mat_terrain.setFloat("Tex3Scale", 128f);
|
|
|
|
|
|
- /** 2. Create the height map */
|
|
|
|
|
|
+ /* 2. Create the height map */
|
|
AbstractHeightMap heightmap = null;
|
|
AbstractHeightMap heightmap = null;
|
|
Texture heightMapImage = assetManager.loadTexture(
|
|
Texture heightMapImage = assetManager.loadTexture(
|
|
"Textures/Terrain/splat/mountains512.png");
|
|
"Textures/Terrain/splat/mountains512.png");
|
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
|
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
|
|
heightmap.load();
|
|
heightmap.load();
|
|
|
|
|
|
- /** 3. We have prepared material and heightmap.
|
|
|
|
|
|
+ /* 3. We have prepared material and heightmap.
|
|
* Now we create the actual terrain:
|
|
* Now we create the actual terrain:
|
|
* 3.1) Create a TerrainQuad and name it "my terrain".
|
|
* 3.1) Create a TerrainQuad and name it "my terrain".
|
|
* 3.2) A good value for terrain tiles is 64x64 -- so we supply 64+1=65.
|
|
* 3.2) A good value for terrain tiles is 64x64 -- so we supply 64+1=65.
|
|
@@ -130,19 +130,19 @@ public class HelloTerrainCollision extends SimpleApplication
|
|
TerrainQuad terrain
|
|
TerrainQuad terrain
|
|
= new TerrainQuad("my terrain", 65, 513, heightmap.getHeightMap());
|
|
= new TerrainQuad("my terrain", 65, 513, heightmap.getHeightMap());
|
|
|
|
|
|
- /** 4. We give the terrain its material, position & scale it, and attach it. */
|
|
|
|
|
|
+ /* 4. We give the terrain its material, position & scale it, and attach it. */
|
|
terrain.setMaterial(mat_terrain);
|
|
terrain.setMaterial(mat_terrain);
|
|
terrain.setLocalTranslation(0, -100, 0);
|
|
terrain.setLocalTranslation(0, -100, 0);
|
|
terrain.setLocalScale(2f, 1f, 2f);
|
|
terrain.setLocalScale(2f, 1f, 2f);
|
|
rootNode.attachChild(terrain);
|
|
rootNode.attachChild(terrain);
|
|
|
|
|
|
- /** 5. The LOD (level of detail) depends on were the camera is: */
|
|
|
|
|
|
+ /* 5. The LOD (level of detail) depends on were the camera is: */
|
|
List<Camera> cameras = new ArrayList<>();
|
|
List<Camera> cameras = new ArrayList<>();
|
|
cameras.add(getCamera());
|
|
cameras.add(getCamera());
|
|
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
|
|
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
|
|
terrain.addControl(control);
|
|
terrain.addControl(control);
|
|
|
|
|
|
- /** 6. Add physics: */
|
|
|
|
|
|
+ /* 6. Add physics: */
|
|
/* We set up collision detection for the scene by creating a static
|
|
/* We set up collision detection for the scene by creating a static
|
|
* RigidBodyControl with mass zero.*/
|
|
* RigidBodyControl with mass zero.*/
|
|
terrain.addControl(new RigidBodyControl(0));
|
|
terrain.addControl(new RigidBodyControl(0));
|