* fix terrain grid camera offset problem

* updated TerrainFractalGridTest to use physics again

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8569 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 13 years ago
parent 9bda4a288e
commit 0dddd8613f
  1. 6
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java
  2. 8
      engine/src/test/jme3test/terrain/TerrainFractalGridTest.java
  3. 2
      engine/src/test/jme3test/terrain/TerrainGridTest.java

@ -33,7 +33,6 @@ package com.jme3.terrain.geomipmap;
import com.jme3.scene.control.UpdateControl; import com.jme3.scene.control.UpdateControl;
import com.jme3.bullet.PhysicsSpace; import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape;
import com.jme3.bullet.control.RigidBodyControl; import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.terrain.heightmap.HeightMap; import com.jme3.terrain.heightmap.HeightMap;
import java.util.HashMap; import java.util.HashMap;
@ -47,8 +46,6 @@ import com.jme3.math.FastMath;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.terrain.geomipmap.lodcalc.LodCalculator; import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;
import com.jme3.terrain.geomipmap.lodcalc.LodCalculatorFactory;
import com.jme3.terrain.geomipmap.lodcalc.LodDistanceCalculatorFactory;
import com.jme3.terrain.heightmap.HeightMapGrid; import com.jme3.terrain.heightmap.HeightMapGrid;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -203,7 +200,8 @@ public class TerrainGrid extends TerrainQuad {
} }
public Vector3f getCell(Vector3f location) { public Vector3f getCell(Vector3f location) {
final Vector3f v = location.clone().divideLocal(this.getLocalScale().mult(this.quadSize - 1)).add(0.5f, 0, 0.5f); final Vector3f v = location.add(this.getWorldScale().mult((this.quadSize - 1)/2)).divide(this.getWorldScale().mult(this.quadSize - 1)).add(0.5f, 0, 0.5f);
return new Vector3f(FastMath.floor(v.x), 0, FastMath.floor(v.z)); return new Vector3f(FastMath.floor(v.x), 0, FastMath.floor(v.z));
} }

@ -42,7 +42,7 @@ public class TerrainFractalGridTest extends SimpleApplication {
private float grassScale = 64; private float grassScale = 64;
private float dirtScale = 16; private float dirtScale = 16;
private float rockScale = 128; private float rockScale = 128;
private boolean usePhysics = false; private boolean usePhysics = true;
public static void main(final String[] args) { public static void main(final String[] args) {
TerrainFractalGridTest app = new TerrainFractalGridTest(); TerrainFractalGridTest app = new TerrainFractalGridTest();
@ -143,9 +143,7 @@ public class TerrainFractalGridTest extends SimpleApplication {
this.terrain.setLocalScale(2f, 1f, 2f); this.terrain.setLocalScale(2f, 1f, 2f);
this.rootNode.attachChild(this.terrain); this.rootNode.attachChild(this.terrain);
List<Camera> cameras = new ArrayList<Camera>(); TerrainLodControl control = new TerrainLodControl(this.terrain, this.getCamera());
cameras.add(this.getCamera());
TerrainLodControl control = new TerrainLodControl(this.terrain, cameras);
control.setLodCalculator( new DistanceLodCalculator(33, 2.7f) ); // patch size, and a multiplier control.setLodCalculator( new DistanceLodCalculator(33, 2.7f) ); // patch size, and a multiplier
this.terrain.addControl(control); this.terrain.addControl(control);
@ -153,7 +151,7 @@ public class TerrainFractalGridTest extends SimpleApplication {
stateManager.attach(bulletAppState); stateManager.attach(bulletAppState);
this.getCamera().setLocation(new Vector3f(0, 0, 0)); this.getCamera().setLocation(new Vector3f(0, 300, 0));
this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f)); this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));

@ -103,7 +103,7 @@ public class TerrainGridTest extends SimpleApplication {
this.terrain.setMaterial(this.mat_terrain); this.terrain.setMaterial(this.mat_terrain);
this.terrain.setLocalTranslation(0, 0, 0); this.terrain.setLocalTranslation(0, 0, 0);
this.terrain.setLocalScale(2f, 1f, 2f); this.terrain.setLocalScale(1f, 1f, 1f);
this.rootNode.attachChild(this.terrain); this.rootNode.attachChild(this.terrain);
TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera()); TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera());

Loading…
Cancel
Save