I'm currently working on building a game which is on a planet, the way in which I'm planning to store the data is in 6 2dimensional arrays, which are heightmaps around the sphere (on the faces of a cube).
The problem I have is this, given a normalised vector which points outwards from the centre of the sphere how can I determine these two things:
1) The plane which it intersects
2) The x/y coordinates I should look up in my 2d array to get the height.
My current solution is this (using XNA):
1) Construct a ray pointing out from [0,0] along the direction vector supplied. Loop through each surface and do a ray/plane intersection (which is a method supplied by the XNA framework) to get the distance to the intersection point. Select the closest plane (shortest distance to intersection)
2) Take the 3D point, and convert it to a 2D point which can be used as an array lookup to find the radius (this is the bit I cannot work out the maths for, or find any references to through google).
A helpful constraint is that the sphere/cube system is around the origin.
So, the problem which needs solving is this: Given a direction vector, how do I determine where it intersects the surrounding cube. Using this result how do I then get the correct value in a 2D array which is "painted" on the face of this cube?