From dfeff3c6af164b5e1444988bd403e2abffa93d7c Mon Sep 17 00:00:00 2001 From: "ant..om" Date: Wed, 22 Jun 2011 19:25:50 +0000 Subject: [PATCH] Fix major bug: TerrainGrid.getHeight returned always 0 after first grid change happened minor bug: updateModelBound missed from TerrainGrid update call, added collisionGroup check to physics, and failing with exception if material is not set before initialize() call git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7691 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/terrain/geomipmap/TerrainGrid.java | 7 +++++++ .../com/jme3/terrain/geomipmap/TerrainQuad.java | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java index 2c5973101..60a07a5be 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java @@ -120,6 +120,9 @@ public class TerrainGrid extends TerrainQuad { } public void initialize(Vector3f location) { + if(this.material == null){ + throw new RuntimeException("Material must be set prior to call of initialize"); + } Vector3f camCell = this.getCell(location); this.updateChildrens(camCell); for (TerrainGridListener l : this.listeners.values()) { @@ -243,9 +246,13 @@ public class TerrainGrid extends TerrainQuad { this.currentCell = cam; this.setLocalTranslation(cam.mult(this.getLocalScale().mult(this.quadSize))); + this.updateModelBound(); if (control != null) { + int currentCollisionGroup = control.getCollideWithGroups(); control = new RigidBodyControl(new HeightfieldCollisionShape(getHeightMap(), getLocalScale()), 0); + control.setCcdMotionThreshold(0.5f); + control.setCollisionGroup(currentCollisionGroup); this.addControl(control); space.add(this); } diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java index 089691ada..dc0b5d7d3 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java @@ -920,8 +920,8 @@ public class TerrainQuad extends Node implements Terrain { public float getHeight(Vector2f xz) { // offset - float x = (float)((xz.x / getLocalScale().x) + (float)totalSize / 2f); - float z = (float)((xz.y / getLocalScale().z) + (float)totalSize / 2f); + float x = (float)(((xz.x - getLocalTranslation().x) / getLocalScale().x) + (float)totalSize / 2f); + float z = (float)(((xz.y - getLocalTranslation().z) / getLocalScale().z) + (float)totalSize / 2f); return getHeight(x, z, xz); } @@ -953,7 +953,7 @@ public class TerrainQuad extends Node implements Terrain { coord.add(xz); List h = new ArrayList(); h.add(height); - + setHeight(coord, h); } @@ -1002,7 +1002,7 @@ public class TerrainQuad extends Node implements Terrain { float h; LocationHeight(){} - + LocationHeight(int x, int z, float h){ this.x = x; this.z = z; @@ -1077,7 +1077,7 @@ public class TerrainQuad extends Node implements Terrain { else if(quad1 instanceof TerrainPatch) ((TerrainPatch)quad1).setHeight(quadLH1, overrideHeight); } - + if (!quadLH2.isEmpty()) { if (quad2 instanceof TerrainQuad) ((TerrainQuad)quad2).setHeight(quadLH2, overrideHeight); @@ -1091,7 +1091,7 @@ public class TerrainQuad extends Node implements Terrain { else if(quad3 instanceof TerrainPatch) ((TerrainPatch)quad3).setHeight(quadLH3, overrideHeight); } - + if (!quadLH4.isEmpty()) { if (quad4 instanceof TerrainQuad) ((TerrainQuad)quad4).setHeight(quadLH4, overrideHeight);