Hello,
After doing some research without finding any good tutorials and only hints on how to proceed with my height map for a icosphere I started working on my own idea and this is what I came up with:
1. Take a image of the planet in question in greyscale and import it to a 2D array. I found a large HD image from NASA with a 8192x4096 pixels.
2. Calculate Longitude and Latitude for every vertex in my Icosphere, I started with 7 division but will try 8 divisons later on for more details.
Here is my code for getting my hand on Long and Lat cordinates.
float r = sqrtf(mPlanetMesh.vertices[i].position.x * mPlanetMesh.vertices[i].position.x + mPlanetMesh.vertices[i].position.y * mPlanetMesh.vertices[i].position.y + mPlanetMesh.vertices[i].position.z * mPlanetMesh.vertices[i].position.z);
float longitude = fmodf((270 + (atan2f(mPlanetMesh.vertices[i].position.x, mPlanetMesh.vertices[i].position.z)) * 180 / M_PI), 360.0f) - 180;
float latitude = (90 - acosf(mPlanetMesh.vertices[i].position.y / r) * (180 / M_PI));
This does give me values for Long between -180 and 180 and for Lat between -90 and 90. But I don't know if the calculations are correct.
3. Use this Long and Lat value to get the correct Pixel:
mHeightMap[(int)((180 + longitude) * (8192 / 360))][(int)((90 - latitude) * (4096 / 180))])
Again I am not sure this will work for my image to get the correct values.
4. Calculate the normals for every vertex:
mPlanetMesh.vertices[i].normal.x = cosf(latitude * (M_PI / 180)) * cosf(longitude * (M_PI / 180));
mPlanetMesh.vertices[i].normal.y = cosf(latitude * (M_PI / 180)) * sinf(longitude * (M_PI / 180));
mPlanetMesh.vertices[i].normal.z = sinf(latitude * (M_PI / 180));
Once again I am not sure this calculations are correct since they are depending on both that they are correct by themself but also that the Long and Lat calculations are correct.
5. Multiply the normal vector with the height vector(the height vector have of course been recalculated to represent values betweeen the lowest and highest point on the planet)
6. Add the multiplied vector to the vertex.
7. Render
Now on 7 divisions I get something that looks like a landscape even tho the details is very low and it looks kinda crapy in general. On 8 divisions I get a lot off lines going through the middle of the planet for some reason.
My plan was to make sure the calculations are correct before going into detail of what might be the problem there. The caluclations might solve it(It should atleast since without the calculations the sphere looks like a spehere.)
I might be approaching this from the wrong direction and it might be a easier way to solve this. please enligthen me if thats the case :)
Best regards and thanks in advance
Toastmastern