TerrainPage.getHeightFromWorld and TerrainBlock.getHeightFromWorld problem

I’m casting a ray into a TerrainPage which returns the child TerrainBlock hit. Problem is I can’t seem to get the height from the child TerrainBlock. I’m assuming this is a local co-ordinate problem but you can see the issue in the following simpleUpdate(). I perform a height test on the root TerrainPage then perform the same test against the TerrainBlock both using getHeightFromWorld(). TerrainPage works fine but TerrainBlock produces a NaN. Any ideas?



[java]

import com.jme.app.SimpleGame;

import com.jme.bounding.BoundingBox;

import com.jme.input.NodeHandler;

import com.jme.intersection.TrianglePickResults;

import com.jme.light.DirectionalLight;

import com.jme.math.Vector3f;

import com.jme.renderer.ColorRGBA;

import com.jme.scene.CameraNode;

import com.jme.scene.state.CullState;

import com.jmex.terrain.TerrainBlock;

import com.jmex.terrain.TerrainPage;

import com.jmex.terrain.util.HillHeightMap;



public class TestGetHeightFromWorld extends SimpleGame

{

public static void main(String[] args) {

TestGetHeightFromWorld app = new TestGetHeightFromWorld();

app.setConfigShowMode(ConfigShowMode.AlwaysShow);

app.start();

}



@Override

protected void simpleUpdate()

{

super.simpleUpdate();



float X = 20f;

float Y = 20f;



System.out.println("From Root: " + terrain.getHeightFromWorld(new Vector3f(X,0f,Y)));



TrianglePickResults results = new TrianglePickResults();

results.clear();



com.jme.math.Ray ray = new com.jme.math.Ray();

ray.setOrigin(new Vector3f(X,500f,Y));

ray.setDirection(new Vector3f(0f,-500f,0f));



rootNode.findPick(ray,results);



for(int pickIndex = 0; pickIndex < results.getNumber(); pickIndex++)

{

com.jme.scene.Spatial mesh = results.getPickData(pickIndex).getTargetMesh();



if( mesh instanceof TerrainBlock)

{

TerrainBlock terrainBlock = (TerrainBlock) mesh;

System.out.println("From Leaf: " + (terrainBlock.getHeightFromWorld(new Vector3f(X,0f,Y))));

}

}

}



/**

  • Sets up the test.

    */

    @Override

    protected void simpleInitGame() {

    display.setTitle("Hill Heightmap");



    // Set cam above terrain

    CameraNode camNode = new CameraNode("Camera Node", cam);

    camNode.setLocalTranslation(new Vector3f(0, 550, 0));

    camNode.getCamera().setFrustumFar(5000);

    camNode.updateWorldData(0);

    input = new NodeHandler(camNode, 150, 1);

    rootNode.attachChild(camNode);



    // Set basic render states

    CullState cs = display.getRenderer().createCullState();

    cs.setCullFace(CullState.Face.Back);

    cs.setEnabled(true);

    rootNode.setRenderState(cs);



    // Some light

    DirectionalLight dl = new DirectionalLight();

    dl.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));

    dl.setDirection(new Vector3f(1, -0.5f, 1));

    dl.setEnabled(true);

    lightState.attach(dl);



    // The terrain

    HillHeightMap heightMap = new HillHeightMap(513, 4000, 25.0f, 40.0f,

    (byte) 1);

    heightMap.setHeightScale(10.001f);

    Vector3f terrainScale = new Vector3f(33, 4, 66);

    terrain = new TerrainPage("Terrain", 128, heightMap

    .getSize(), terrainScale, heightMap.getHeightMap());

    terrain.setDetailTexture(1, 16);

    boundingbox = new BoundingBox();

    terrain.setModelBound(boundingbox);

    terrain.updateModelBound();



    rootNode.attachChild(terrain);

    }



    private TerrainPage terrain;

    private BoundingBox boundingbox;

    }

    [/java]

I dont think getHeightFromWorld() is meant for user height checks… Also, why do you need it? You got the collision point?

I dont think getHeightFromWorld() is meant for user height checks


I see others using it for height checks.

Also, why do you need it? You got the collision point?


Run that prog. The triangle pick data is completely empty. Just get a target mesh which is the TerrainBlock.