How to find clicked point in terrain coordinates?

@desertrunner… can you please post your solution?

I would, if I had one. :slight_smile: I'm still working on it. But at the moment I'm concentrating on GUI parts. Maybe I can post my solution in a few days.

i have solved it now by myself



i added following functions to TerrainBlock.java

       /**
    * <code>setHeight</code> sets the height of an arbitrary point on the
    * terrain.
    *
    * @param x
    *            the x coordinate to check.
    * @param z
    *            the z coordinate to check.
    * @param height
    *            the new height
    * @return the height at the provided location.
    */
   public void setHeight(float x, float z, int height) {
      x /= stepScale.x;
      z /= stepScale.z;
      float col = FastMath.floor(x);
      float row = FastMath.floor(z);

      if (col < 0 || row < 0 || col >= size - 1 || row >= size - 1) {
         return;
      }

      // calculate hight map point
      int focalSpot = (int) (col + row * size);

      // set heightmap point
      heightMap[focalSpot] = height;
   }



and the following to TerrainPage.java

   /**
    * <code>setHeight</code> sets the height of an arbitrary point on the
    * terrain.
    *
    * @param x
    *            the x coordinate to check.
    * @param z
    *            the z coordinate to check.
    * @param height
    *            the new height
    */

   public void setHeight(float x, float z, int height) {
      // determine which quadrant this is in.
      Spatial child = null;
      int split = (getSize() - 1) >> 1;
      float halfmapx = split * getStepScale().x, halfmapz = split
            * getStepScale().z;
      float newX = 0, newZ = 0;
      if (x == 0)
         x += .001f;
      if (z == 0)
         z += .001f;
      if (x > 0) {
         if (z > 0) {
            // upper right
            child = getChild(3);
            newX = x;
            newZ = z;
         } else {
            // lower right
            child = getChild(2);
            newX = x;
            newZ = z + halfmapz;
         }
      } else {
         if (z > 0) {
            // upper left
            child = getChild(1);
            newX = x + halfmapx;
            newZ = z;
         } else {
            // lower left...
            child = getChild(0);
            if (x == 0)
               x -= .1f;
            if (z == 0)
               z -= .1f;
            newX = x + halfmapx;
            newZ = z + halfmapz;
         }
      }
      if ((child.getType() & SceneElement.TERRAIN_BLOCK) != 0)
         ((TerrainBlock) child).setHeight(newX,newZ,
               height);
      else if ((child.getType() & SceneElement.TERRAIN_PAGE) != 0)
         ((TerrainPage) child).setHeight(x
               - ((TerrainPage) child).getLocalTranslation().x, z
               - ((TerrainPage) child).getLocalTranslation().z, height);
   }

   /**
    * <code>setHeightFromWorld</code> sets the height of an arbitrary point
    * on the terrain when given world coordinates.
    *
    * @param height
    *            new height
    * @param position
    *            the vector representing the height location to check.
    */
   public void setHeightFromWorld(int height, Vector3f position) {
      Vector3f calcVec1 = new Vector3f();
      Vector3f locationPos = calcVec1.set(position).subtractLocal(
            localTranslation).divideLocal(getStepScale());
      locationPos.multLocal(getStepScale());

      setHeight(locationPos.x, locationPos.z, height);
   }



the code to find the points is copied from the getheight functions.