Sign in to follow this  

Spherical projection problem

This topic is 2107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am attempting to write code to take a rectangular, orthographic image of a planet and draw it as a sphere.

My code attempts to iterate through every pixel on the destination and determine A) whether it is part of the planet or not, and B) if so, which pixel to copy the color from off of the source image.

Here is the C++ pseudo-code. Note that pSrcData and pDestData are both arrays of uint32 ABGR color values, ordered from the top left corner and top to bottom, just like text on a page.

[code]void DrawPlanet( uint32* pSrcData,uint32 srcWidth, uint32 srcHeight, uint32 pDestData, uint32 destWidth, uint32 destHeight )
{
for ( uint32 iy = 0; iy < destHeight; ++iy )
{
for ( uint32 ix = 0; ix < destWidth; ++ix )
{
int destIndex = ix + ( destWidth * iy );
if ( PointIsOnPlanet( ix, iy, destWidth, destHeight ) == false )
{
pDestData[ destIndex ] = 0;
}
else
{
int srcIndex = CalculateSourceIndex( ix, iy, destWidth, destHeight, srcWidth, srcHeight );
pDestData[ destIndex ] = pSrcData[ srcIndex ];
}
}
}
}[/code]

What should CalculateSourceIndex() look like? I.e. assuming we are not (yet) attempting to make the sphere rotate, and it's never turned at an angle, how would you determine which pixel on the source image to use for any given pixel of the spherical projection image?

Share this post


Link to post
Share on other sites
First, take the ray that goes from your eye to the pixel and find the first intersection with the sphere. Then I am sure you can find formulas to convert standard Euclidean coordinates to spherical coordinates in about 10 seconds of searching the web. Or you can do it yourself: Computing the latitude is easy because it only depends on y, and the longitude is atan2(z,x) or something of that sort.

Share this post


Link to post
Share on other sites

This topic is 2107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this