Oh here is a faster method - http://www.mvps.org/directx/articles/spheremap.htm

For each point (Assuming Y=up):

3DVec normal = (sphereCenter - point).normalize();
float U = asin(normal.x)/PI + 0.5
float V = asin(normal.y)/PI + 0.5

for z=up:
float U = asin(normal.x)/PI + 0.5
float V = asin(normal.z)/PI + 0.5

But in your code example I don't know if you were calculating normals
correctly.  Your normal should be a vector pointing from the center of
your sphere out the vertex, which is done by subtracting and then
normalizing to make it a unit-vector.

On Dec 22, 11:33 am, Robert Green <[email protected]> wrote:
> pedro,
>
> your problem has nothing to do with android.  I think you may need a
> 3D refresher to solve it.  Normals are not UVs.  Your UVs will depend
> on how you want to map, but the easiest way to do it is to map from
> the sphere center out using angles, like this.  Since GL has 2D
> texture coordinate 0,0 as upper left, you will want to define where
> upper left is on your sphere.  I'd use straight up and center as a
> unit vector, or (0, 0, 1) if z is up in your world.  If y is up, then
> (0,1,0) will be 0,0 in UVs.
>
> so starting with that, you can calculate the UV of any point by
> getting the difference of angle of that starting angle and the new
> point.  Remember that if they both come from the sphere center, you'll
> have complete 2PI radian coverage on both axis... so naturally
> dividing the resulting angle by 2PI will give you a UV number between
> 0 and 1.
>
> The process is like this (assuming z=up)
>
> For each point:
> // for U just look at the sphere from overhead
> U = (atan2(point.x - center.x, point.y - center.y) + PI) / (2PI)
> hyp = distance(point, center);
> V = ((point.z - center.z) / hyp) + 1) / 2
>
> I believe that is correct and there will be a more elegant way to do
> it but today my head is in 2D math world so I can't remember how to
> dot it out.  The idea though is that for every point, you can
> determine the angle needed for U by looking at the sphere from
> overhead and just using an arctan of the xy differences (assuming
> z=up) of the center to the point.  The resulting range is in radians (-
> PI to PI) so you have to add PI to change it from 0 to 2PI and then
> dividing by 2PI gives you 0 to 1.  Then for the V value, you can just
> examine the "height" (z) of the point and in conjunction with its
> distance from the center, you've got an opposite over hypotenuse which
> is the same as the sine of the angle, which is what you want to get a
> evenly distributed texture top to bottom.  The number will also be
> ranged from -1 to 1 so you need to add 1 and divide it by 2 to get the
> 0 to 1 range.  The texture should touch in the corners and if you use
> the right one, look seamless.
>
> If any of my math is wrong, please correct it after debugging, but at
> least this should get you going in the right direction.
>
> Cheers
>
> On Dec 22, 9:09 am, pedr0 <[email protected]> wrote:
>
>
>
>
>
>
>
> > Please see the link and reply inside  this post if you have not an
> > account on OpenGL forum, the question is over there.
>
> >http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&N...
>
> > Thanks a lot.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to