OSDN Git Service

* Added smooth terrain editing to TerrainTestModifyHeight
authorshadowislord <shadowislord@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Fri, 17 Jun 2011 01:28:21 +0000 (01:28 +0000)
committershadowislord <shadowislord@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Fri, 17 Jun 2011 01:28:21 +0000 (01:28 +0000)
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7645 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

engine/src/test/jme3test/terrain/TerrainTestModifyHeight.java

index 057a07b..f8c7260 100644 (file)
@@ -49,13 +49,10 @@ import com.jme3.math.Vector3f;
 import com.jme3.renderer.Camera;
 import com.jme3.terrain.geomipmap.TerrainLodControl;
 import com.jme3.terrain.geomipmap.TerrainQuad;
-import com.jme3.terrain.heightmap.AbstractHeightMap;
-import com.jme3.terrain.heightmap.ImageBasedHeightMap;
 import com.jme3.texture.Texture;
 import com.jme3.texture.Texture.WrapMode;
 import java.util.ArrayList;
 import java.util.List;
-import jme3tools.converters.ImageToAwt;
 
 /**
  *
@@ -74,6 +71,9 @@ public class TerrainTestModifyHeight extends SimpleApplication {
     private float grassScale = 64;
     private float dirtScale = 16;
     private float rockScale = 128;
+    
+    private boolean raiseTerrain = false;
+    private boolean lowerTerrain = false;
 
     public static void main(String[] args) {
         TerrainTestModifyHeight app = new TerrainTestModifyHeight();
@@ -81,22 +81,26 @@ public class TerrainTestModifyHeight extends SimpleApplication {
     }
 
     @Override
-    public void initialize() {
-        super.initialize();
-
-        loadHintText();
-        initCrossHairs();
-    }
-
-    @Override
-    public void update() {
-        super.update();
-
+    public void simpleUpdate(float tpf){
         updateHintText();
+        
+        if (raiseTerrain){
+            Vector3f intersection = getWorldIntersection();
+            if (intersection != null) {
+                adjustHeight(intersection, 64, 1);
+            }
+        }else if (lowerTerrain){
+            Vector3f intersection = getWorldIntersection();
+            if (intersection != null) {
+                adjustHeight(intersection, 64, -1);
+            }
+        }
     }
-
+    
     @Override
     public void simpleInitApp() {
+        loadHintText();
+        initCrossHairs();
         setupKeys();
 
         // First, we load up our textures and the heightmap texture for the terrain
@@ -203,21 +207,10 @@ public class TerrainTestModifyHeight extends SimpleApplication {
                     terrain.setMaterial(matTerrain);
                 }
             } else if (name.equals("Raise")) {
-                if (pressed) {
-                    Vector3f intersection = getWorldIntersection();
-                    if (intersection != null) {
-                        adjustHeight(intersection, 64, 1);
-                    }
-                }
+                raiseTerrain = pressed;
             } else if (name.equals("Lower")) {
-                if (pressed) {
-                    Vector3f intersection = getWorldIntersection();
-                    if (intersection != null) {
-                        adjustHeight(intersection, 32, -1);
-                    }
-                }
+                lowerTerrain = pressed;
             }
-
         }
     };