Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WorldTerrain extends TerrainQuad {
- public static final String NAME = "terrain";
- public static final int PATCH_SIZE = 9;
- public static final int TOTAL_SIZE = 33;
- private static Vector3f spawnLocation = new Vector3f(13, 3, 16);
- private Material mat_terrain;
- private void loadText(AssetManager assetManager) {
- /**
- * 1. Create terrain material and load four textures into it.
- */
- mat_terrain = new Material(assetManager,
- "Common/MatDefs/Terrain/Terrain.j3md");
- /**
- * 1.1) Add ALPHA map (for red-blue-green coded splat textures)
- */
- mat_terrain.setTexture("Alpha", assetManager.loadTexture(
- "Textures/Terrain/splat/alphamap.png"));
- /**
- * 1.2) Add GRASS texture into the red layer (Tex1).
- */
- Texture grass = assetManager.loadTexture(
- "Textures/Terrain/splat/grass.jpg");
- grass.setWrap(WrapMode.Repeat);
- mat_terrain.setTexture("Tex1", grass);
- mat_terrain.setFloat("Tex1Scale", 64f);
- /**
- * 1.3) Add DIRT texture into the green layer (Tex2)
- */
- Texture dirt = assetManager.loadTexture(
- "Textures/GrassRocky.png");
- dirt.setWrap(WrapMode.Repeat);
- mat_terrain.setTexture("Tex2", dirt);
- mat_terrain.setFloat("Tex2Scale", 32f);
- /**
- * 1.4) Add ROAD texture into the blue layer (Tex3)
- */
- Texture rock = assetManager.loadTexture(
- "Textures/Terrain/splat/road.jpg");
- rock.setWrap(WrapMode.Repeat);
- mat_terrain.setTexture("Tex3", rock);
- mat_terrain.setFloat("Tex3Scale", 128f);
- }
- private static float[] generateHeightMap(AssetManager assetManager) {
- AbstractHeightMap heightmap = null;
- try {
- heightmap = new HillHeightMap(1024, 100, 2, 10, 1);
- } catch (Exception ex) {
- Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
- }
- return heightmap.getHeightMap();
- }
- public static Vector3f getSpawnLocation() {
- return spawnLocation;
- }
- public WorldTerrain(Interface app) {
- super(NAME, PATCH_SIZE, TOTAL_SIZE, generateHeightMap(app.getAssetManager()));
- loadText(app.getAssetManager());
- setMaterial(mat_terrain);
- setModelBound(new BoundingBox());
- setLocalTranslation(32f, 0f, 32f);
- List<Camera> cameras = new ArrayList<Camera>();
- cameras.add(app.getCamera());
- RigidBodyControl landscape = new RigidBodyControl(0.0f);
- addControl(landscape);
- public class Interface extends SimpleApplication {
- private TerrainQuad terrain;
- Material mat_terrain;
- public static void main(String[] args) {
- Interface app = new Interface();
- app.start();
- }
- @Override
- public void simpleInitApp() {
- flyCam.setMoveSpeed(50);
- terrain = new WorldTerrain(this);
- rootNode.attachChild(terrain);
- }
- int x=0;
- @Override
- public void simpleUpdate(float tpf) {
- for(int i=0;i<1000;i++){
- terrain.setHeight(new Vector2f(x,i), (float) (10*Math.random()));
- }
- x++;
- }
- private Ray getMouseRay() {
- Vector2f mouseCoords = new Vector2f(inputManager.getCursorPosition());
- Vector3f origin = cam.getWorldCoordinates(mouseCoords, 0).normalizeLocal();
- Ray mouseRay = new Ray(origin, cam.getWorldCoordinates(mouseCoords, 1).subtractLocal(origin).normalizeLocal());
- return mouseRay;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement