OSDN Git Service

fixed a bug calculating camera cell
authoranthyon@gmail.com <anthyon@gmail.com@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Thu, 12 May 2011 18:20:23 +0000 (18:20 +0000)
committeranthyon@gmail.com <anthyon@gmail.com@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Thu, 12 May 2011 18:20:23 +0000 (18:20 +0000)
Test is updated to not use LOD and physics for testing purposes

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

engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java
engine/src/test/jme3test/terrain/TerrainGridTest.java

index 70827b2..bb3f3d6 100644 (file)
@@ -86,19 +86,19 @@ public class TerrainGrid extends TerrainQuad {
         // 2: grids are associated with locations, and no incremental update is done, we load new grids for new locations, and unload those that are not needed anymore
         Vector3f cam = locations.get(0);
         Vector3f camCell = this.getCell(cam);
-        if (!camCell.equals(this.currentCell)) {
+        if (camCell.x != this.currentCell.x || camCell.z != currentCell.z) {
             this.updateChildrens(camCell);
             for (TerrainGridListener l : this.listeners.values()) {
                 l.gridMoved(camCell);
             }
         }
 
-        super.update(locations);
+        //super.update(locations);
     }
 
     public Vector3f getCell(Vector3f location) {
         final Vector3f v = location.clone().divideLocal(this.getLocalScale().mult(this.quadSize)).add(0.5f, 0, 0.5f);
-        return new Vector3f(FastMath.floor(v.x), FastMath.floor(v.y), FastMath.floor(v.z));
+        return new Vector3f(FastMath.floor(v.x), 0, FastMath.floor(v.z));
     }
 
     protected void removeQuad(int idx) {
index a0b46aa..c1b2105 100644 (file)
@@ -31,6 +31,7 @@ public class TerrainGridTest extends SimpleApplication {
     private float grassScale = 64;
     private float dirtScale = 16;
     private float rockScale = 128;
+    private boolean usePhysics = false;
 
     public static void main(final String[] args) {
         TerrainGridTest app = new TerrainGridTest();
@@ -85,24 +86,25 @@ public class TerrainGridTest extends SimpleApplication {
         BulletAppState bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
 
-        RigidBodyControl body = new RigidBodyControl(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), 0);
-        terrain.addControl(body);
-        bulletAppState.getPhysicsSpace().add(terrain);
 
         this.getCamera().setLocation(new Vector3f(0, 256, 0));
 
         this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
 
-        CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1);
-        this.player3 = new CharacterControl(capsuleShape, 0.5f);
-        this.player3.setJumpSpeed(20);
-        this.player3.setFallSpeed(30);
-        this.player3.setGravity(30);
+        if (usePhysics) {
+            RigidBodyControl body = new RigidBodyControl(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), 0);
+            terrain.addControl(body);
+            bulletAppState.getPhysicsSpace().add(terrain);
+            CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1);
+            this.player3 = new CharacterControl(capsuleShape, 0.5f);
+            this.player3.setJumpSpeed(20);
+            this.player3.setFallSpeed(30);
+            this.player3.setGravity(30);
 
-        this.player3.setPhysicsLocation(new Vector3f(0, 256, 0));
-
-        bulletAppState.getPhysicsSpace().add(this.player3);
+            this.player3.setPhysicsLocation(new Vector3f(0, 256, 0));
 
+            bulletAppState.getPhysicsSpace().add(this.player3);
+        }
         this.initKeys();
     }
 
@@ -178,7 +180,9 @@ public class TerrainGridTest extends SimpleApplication {
             this.walkDirection.addLocal(camDir.negate());
         }
 
-        this.player3.setWalkDirection(this.walkDirection);
-        this.cam.setLocation(this.player3.getPhysicsLocation());
+        if (usePhysics) {
+            this.player3.setWalkDirection(this.walkDirection);
+            this.cam.setLocation(this.player3.getPhysicsLocation());
+        }
     }
 }