Apply heightmap to a sphere

Hi all i have the heightmap (gray scale image) and i have all the dot of an sphere, now i want to apply the heightmap to the modify the surface of the sphere with the dara form the highmap with



float[] hm = heightmap.getHeightMap();



but i don’t know how to apply this height map to the sphere point , any clue on that?



thanks in advance!

It depends on how you map the sphere. Most probably you would want to use the same mapping as the texture so then it would be checking the texture coord of each vertex and displacing it along a line through the center and the vertex. The question is how to best lay out the sphere faces so that it actually looks like terrain and not like a mace ^^

ok thanks i see… but how to map the height with the dot in the sphere i mean

in pseudo code

sphere.y = hm[indx];





i dont know hoy to calculate the indx, can you help me on that?

regars

If the spheres vertices are all located around the center then it should be pretty easy, somehow like this (pseudo-code):

[java]Vector3f vertexNewLoc = vertexLoc.mult(getHeight(texCoordX, texCoordY));

[/java]

Thanks normen, but it dosn’t work anyway :frowning:

i use



heightmap.getTrueHeightAtPoint((int)dotX, (int)dotY);



and i get and OutOfBoudException i think the problem is i need to translate the sphere (x,y) to a rectagle (x,y) coordinate and i don’t know how to do it, it’s correct my theorical approach ? any clue or tutorial on how to make spherical world with and apply a heighmap to them?

thanks in advance…!!

Again, you have to use the texture coords and then map them to your vertices, so to get the x/y location in the heightmap its:

HeightMap.getHeight(vertex.textureCoord.xheightmapSizeX / vertext.textureCoord.yheightmapSizeY);

I’ve worked on this problem and tried out two different solutions:


  1. Directly map each vertex of the sphere to a height-map value, as normen suggested.



    Example here.



    Pros:

    Simple



    Cons:

    Distortion at the pole region of the sphere


  2. Create 6 height-map planes and arrange them in a cube. Then normalize all the vertexes around a common center turning the cube into a sphere.



    Example here



    Pros:

    No distortion in the pole regions



    Cons:

    More complex



    In both my examples I used random height maps, but it should be fairly trivial to use a pre-computed one.
1 Like