fixed terrain scale bug

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8314 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 14 years ago
parent 210e4ad17b
commit ca628fe5d6
  1. 18
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java
  2. 2
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/PaintTerrainToolAction.java
  3. 10
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/RaiseTerrainToolAction.java

@ -922,8 +922,8 @@ public class TerrainQuad extends Node implements Terrain {
public float getHeightmapHeight(Vector2f xz) {
// offset
int halfSize = totalSize / 2;
int x = Math.round((xz.x / getLocalScale().x) + halfSize);
int z = Math.round((xz.y / getLocalScale().z) + halfSize);
int x = Math.round((xz.x / getWorldScale().x) + halfSize);
int z = Math.round((xz.y / getWorldScale().z) + halfSize);
return getHeightmapHeight(x, z);
}
@ -1024,10 +1024,10 @@ public class TerrainQuad extends Node implements Terrain {
public float getHeight(Vector2f xz) {
// offset
float x = (float)(((xz.x - getLocalTranslation().x) / getLocalScale().x) + (float)totalSize / 2f);
float z = (float)(((xz.y - getLocalTranslation().z) / getLocalScale().z) + (float)totalSize / 2f);
float x = (float)(((xz.x - getLocalTranslation().x) / getWorldScale().x) + (float)totalSize / 2f);
float z = (float)(((xz.y - getLocalTranslation().z) / getWorldScale().z) + (float)totalSize / 2f);
float height = getHeight(x, z);
height *= getLocalScale().y;
height *= getWorldScale().y;
return height;
}
@ -1064,8 +1064,8 @@ public class TerrainQuad extends Node implements Terrain {
public Vector3f getNormal(Vector2f xz) {
// offset
float x = (float)(((xz.x - getLocalTranslation().x) / getLocalScale().x) + (float)totalSize / 2f);
float z = (float)(((xz.y - getLocalTranslation().z) / getLocalScale().z) + (float)totalSize / 2f);
float x = (float)(((xz.x - getLocalTranslation().x) / getWorldScale().x) + (float)totalSize / 2f);
float z = (float)(((xz.y - getLocalTranslation().z) / getWorldScale().z) + (float)totalSize / 2f);
Vector3f normal = getNormal(x, z, xz);
return normal;
@ -1130,8 +1130,8 @@ public class TerrainQuad extends Node implements Terrain {
// offset
for (int i=0; i<xz.size(); i++) {
int x = Math.round((xz.get(i).x / getLocalScale().x) + halfSize);
int z = Math.round((xz.get(i).y / getLocalScale().z) + halfSize);
int x = Math.round((xz.get(i).x / getWorldScale().x) + halfSize);
int z = Math.round((xz.get(i).y / getWorldScale().z) + halfSize);
locations.add(new LocationHeight(x,z,height.get(i)));
}

@ -105,7 +105,7 @@ public class PaintTerrainToolAction extends AbstractTerrainToolAction {
Vector2f uv = new Vector2f(worldLoc.x,-worldLoc.z);
float scale = ((Node)terrain).getLocalScale().x;
uv.subtractLocal(((Node)terrain).getLocalTranslation().x*scale, ((Node)terrain).getLocalTranslation().z*scale); // center it on 0,0
uv.subtractLocal(((Node)terrain).getWorldTranslation().x*scale, ((Node)terrain).getWorldTranslation().z*scale); // center it on 0,0
float scaledSize = terrain.getTerrainSize()*scale;
uv.addLocal(scaledSize/2, scaledSize/2); // shift the bottom left corner up to 0,0
uv.divideLocal(scaledSize); // get the location as a percentage

@ -76,15 +76,15 @@ public class RaiseTerrainToolAction extends AbstractTerrainToolAction {
private void modifyHeight(Terrain terrain, float radius, float heightDir) {
int radiusStepsX = (int) (radius / ((Node)terrain).getLocalScale().x);
int radiusStepsZ = (int) (radius / ((Node)terrain).getLocalScale().z);
int radiusStepsX = (int) (radius / ((Node)terrain).getWorldScale().x);
int radiusStepsZ = (int) (radius / ((Node)terrain).getWorldScale().z);
float xStepAmount = ((Node)terrain).getLocalScale().x;
float zStepAmount = ((Node)terrain).getLocalScale().z;
float xStepAmount = ((Node)terrain).getWorldScale().x;
float zStepAmount = ((Node)terrain).getWorldScale().z;
List<Vector2f> locs = new ArrayList<Vector2f>();
List<Float> heights = new ArrayList<Float>();
for (int z=-radiusStepsZ; z<radiusStepsZ; z++) {
for (int x=-radiusStepsZ; x<radiusStepsX; x++) {

Loading…
Cancel
Save