Thursday, October 1, 2009

Cube to Sphere mapping

Whooah...

Finaly I have managed to solve all bugs in my way to map coordinates for each vertex from primary cube so to form a sphere. Planet should look like a sphere, because nobody likes cubic planets :)

The main equations for transforming coordinates of cube to spherical are the following:

9C401787-51AE-4B7D-BDD8-0D5BD4B522FE.jpg


For that reasons I have made a "final" class called c_MyMath for keeping all the future equation functions there.

HelloWorld.png


After a bit of testing I found that it was a bad idea to store spherical coordinates of each vertex multiplied by planetary scale factor (the radius of the planet) because while doing scaling in the node's constructor, I needed to take care of scaling during quad splitting also. I thought it's whatever if I do the scaling for each vertex in the constructor and in splitting procedure, and doing it just before the prerender function, which finds all the quads that should be rendered and then apply the scaling. I understand that it's better to handle everything from the start (not just before th rendering) but for now I have decided to leave things as they were.

HelloWorld-1.png


Now the protoplanet looks finally like a sphere!

No comments:

Post a Comment