I am extending the HillHeightMap
class to customize it. I want to be able to place things on the terrain after its generated. In HillHeightMap
I saw this code in the load()
method
// transfer temporary buffer to final heightmap
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
setHeightAtPoint(tempBuffer[i][j], j, i);
}
}
So I used the same loop in my class that is extending HillHeightMap
private val heightMapData: MutableMap<String, Float> = TreeMap()
for (z in 0 until size) {
for (x in 0 until size) {
heightMapData["${z.toFloat()},${x.toFloat()}"] = heightMap[x + (z * size)]
}
}
I thought that the height would corelate directly to a y
value that I could use. My function below does not even come close to being on the terrain.
fun placeOnTerrain(light: Light, x: Float, z: Float) {
when (light.type) {
Light.Type.Probe -> {
val lightProbe = (light as LightProbe)
val height = heightMap.getHeightAt("$z","$x")
lightProbe.position = Vector3f(x, height, z)
}
Light.Type.Directional -> {}
Light.Type.Point -> {}
Light.Type.Spot -> {}
Light.Type.Ambient -> {}
null -> {}
}
}
Does the height value directly corelate to a y value? If so what am I missing? Is there a better way to accomplish this task? Is there a formula I can use to get the y
from the height as I see this in the setHeightAtPoint()
?
public void setHeightAtPoint(float height, int x, int z) {
heightData[x + (z * size)] = height;
}