Selaa lähdekoodia

* Plane.normal is now created by default and set instead of using references
* TerrainTestModifyHeight now uses mouse left/right buttons to raise/lower height

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7674 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

sha..rd 14 vuotta sitten
vanhempi
commit
c410fae0a6

+ 6 - 11
engine/src/core/com/jme3/math/Plane.java

@@ -63,7 +63,7 @@ public class Plane implements Savable, Cloneable {
     /** 
      * Vector normal to the plane.
      */
-    protected Vector3f normal;
+    protected Vector3f normal = new Vector3f();
 
     /** 
      * Constant of the plane. See formula in class definition.
@@ -75,7 +75,6 @@ public class Plane implements Savable, Cloneable {
      * default object and contains a normal of (0,0,0) and a constant of 0.
      */
     public Plane() {
-        normal = new Vector3f();
     }
 
     /**
@@ -89,10 +88,10 @@ public class Plane implements Savable, Cloneable {
      */
     public Plane(Vector3f normal, float constant) {
         if (normal == null) {
-            logger.warning("Normal was null, created default normal.");
-            normal = new Vector3f();
+            throw new IllegalArgumentException("normal cannot be null");
         }
-        this.normal = normal;
+
+        this.normal.set(normal);
         this.constant = constant;
     }
 
@@ -104,8 +103,7 @@ public class Plane implements Savable, Cloneable {
      */
     public void setNormal(Vector3f normal) {
         if (normal == null) {
-            logger.warning("Normal was null, created default normal.");
-            normal = new Vector3f();
+            throw new IllegalArgumentException("normal cannot be null");
         }
         this.normal.set(normal);
     }
@@ -113,13 +111,10 @@ public class Plane implements Savable, Cloneable {
     /**
      * <code>setNormal</code> sets the normal of the plane.
      *
-     * @param normal
-     *            the new normal of the plane.
      */
     public void setNormal(float x, float y, float z) {
         if (normal == null) {
-            logger.warning("Normal was null, created default normal.");
-            normal = new Vector3f();
+            throw new IllegalArgumentException("normal cannot be null");
         }
         this.normal.set(x,y,z);
     }

+ 8 - 9
engine/src/test/jme3test/terrain/TerrainTestModifyHeight.java

@@ -37,8 +37,10 @@ import com.jme3.collision.CollisionResult;
 import com.jme3.collision.CollisionResults;
 import com.jme3.font.BitmapText;
 import com.jme3.input.KeyInput;
+import com.jme3.input.MouseInput;
 import com.jme3.input.controls.ActionListener;
 import com.jme3.input.controls.KeyTrigger;
+import com.jme3.input.controls.MouseButtonTrigger;
 import com.jme3.light.AmbientLight;
 import com.jme3.light.DirectionalLight;
 import com.jme3.material.Material;
@@ -87,12 +89,12 @@ public class TerrainTestModifyHeight extends SimpleApplication {
         if (raiseTerrain){
             Vector3f intersection = getWorldIntersection();
             if (intersection != null) {
-                adjustHeight(intersection, 64, 1);
+                adjustHeight(intersection, 64, tpf * 60);
             }
         }else if (lowerTerrain){
             Vector3f intersection = getWorldIntersection();
             if (intersection != null) {
-                adjustHeight(intersection, 64, -1);
+                adjustHeight(intersection, 64, -tpf * 60);
             }
         }
     }
@@ -143,8 +145,6 @@ public class TerrainTestModifyHeight extends SimpleApplication {
         TerrainLodControl control = new TerrainLodControl(terrain, cameras);
         terrain.addControl(control);
         terrain.setMaterial(matTerrain);
-        terrain.setModelBound(new BoundingBox());
-        terrain.updateModelBound();
         terrain.setLocalTranslation(0, -100, 0);
         terrain.setLocalScale(2f, 1f, 2f);
         rootNode.attachChild(terrain);
@@ -163,7 +163,6 @@ public class TerrainTestModifyHeight extends SimpleApplication {
 
     public void loadHintText() {
         hintText = new BitmapText(guiFont, false);
-        hintText.setSize(guiFont.getCharSet().getRenderedSize());
         hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
         hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain");
         guiNode.attachChild(hintText);
@@ -173,11 +172,10 @@ public class TerrainTestModifyHeight extends SimpleApplication {
         int x = (int) getCamera().getLocation().x;
         int y = (int) getCamera().getLocation().y;
         int z = (int) getCamera().getLocation().z;
-        hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain.  " + x + "," + y + "," + z);
+        hintText.setText("Press left mouse button to raise terrain, press right mouse button to lower terrain.  " + x + "," + y + "," + z);
     }
 
     protected void initCrossHairs() {
-        //guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
         BitmapText ch = new BitmapText(guiFont, false);
         ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
         ch.setText("+"); // crosshairs
@@ -189,11 +187,12 @@ public class TerrainTestModifyHeight extends SimpleApplication {
 
     private void setupKeys() {
         flyCam.setMoveSpeed(100);
+        
         inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
         inputManager.addListener(actionListener, "wireframe");
-        inputManager.addMapping("Raise", new KeyTrigger(KeyInput.KEY_1));
+        inputManager.addMapping("Raise", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
         inputManager.addListener(actionListener, "Raise");
-        inputManager.addMapping("Lower", new KeyTrigger(KeyInput.KEY_2));
+        inputManager.addMapping("Lower", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
         inputManager.addListener(actionListener, "Lower");
     }
     private ActionListener actionListener = new ActionListener() {