Converting x, y, z coordinates to spherical my Lord

I didn't expect it to be this hard..

Now I came to the point where I was supposed to create the world map for the player to build, create and move around on which would have been easy if the terrain would have been flatland all the way. I worked for a couple of weeks with this to make the box move around on the spherical terrain and not in weird movements.

I found the solution, actually the equation that I had to translate into code to make my cartesian to spherical translation and back to cartesian again work.

When the player is picking a figure on the planet we'll get the figure's caresian coordinates (x, y, z) and when the player picks a destination with the mouse on the planet we will have to translate the movement from these two points into spherical coordinates to make the figure move around the curved shape of the planet.

Here's a draft of the function doing that in C#

private Vector3 moveFromTo(Vector3 a, Vector3 b, float t)
{
            float theta = (float)Math.Acos(Vector3.Dot(Vector3.Normalize(a), Vector3.Normalize(b)));
            return (float)(Math.Sin((1 - t) * theta) / Math.Sin(theta)) * a + (float)(Math.Sin(t * theta) / Math.Sin(theta)) * b;
}

Where we will get theta from the angle between the start (a) and destination (b) vectors, and with this angle we will get the new cartesian coordinate in a specific delta time (t which goes from 0 to 1 where 0 is the start point and 1 is the end)

After fighting through this pain a couple of weeks and late nights with my dignity shattered; I came to my next point which was the animations. Lord, this wasn't easy either!
Since XNA was put to rest so had the export plugin in Blender, you can't make animations anymore in an easy manner because the bones in your 3D objects will not rotate and translate like they should in XNA. I tried to kill this bug and make my own converting function for this which took me a week but all in vain.
My final decision was to move on from here creating my own animations the old way with translations and rotations.

After my decision with the animations; I came to the point where the player should be able to select the figure on the planet with the mouse, finally something easy to do again. I made an object handling this, for selecting a figure and selecting a destination on the planet to move to.
I've also made a function that is making a point map over the sphere so that the objects wont move to the same positions that are already taken by other figures or buildings (there will be buildings later).

And then there was lights; time to make som lights with shadows, I made my shader in HLSL for the GPU to handle directly, fast and furious. The idea in the game is that the player must shoot up and out an artificial sun into space orbiting the planet so that there will be lights shone down on a part of the terrain.

Well the figures are still boxes but this is how it looks like now..


As you can see in this image, the planet is lit up by the orbiting artificial sun that is slowly rotating around the planet. The player can only see what he/she is doing on the part where it's lit making it harder for the player to build and work. You'll understand why later while I'm reviling more and more of the game.

I guess you'll have to wait for the next part, because I'll have to code now.

See you later!

Kommentarer