Archived

This topic is now archived and is closed to further replies.

RustyTulip

Texture mapping onto spheres

Recommended Posts

Hi, Can someone give me any pointers on how to map a texture onto a sphere? The 4 points on the sphere are: point sphere[]={{0.0, 0.0, 1.0}, {0.0, 0.942809, -0.33333}, {-0.816497, -0.471405, -0.333333}, {0.816497, -0.471405, -0.333333}}; The sphere was formed using recursive subdivision too. If anyone can help me it would be much appreciated, or any webpages which describe how to do it. Many thanks, Russ.

Share this post


Link to post
Share on other sites
at the smallest size the sphere will contain 20 triangles right?

unwrapped the sphere will look like so

... 5 tris here
|\________
|/|/|/|/|/|
----------
|/ .. 5 tris here

NOTE this will still result in texture distortion in the sphere.
check paul bourkes site for more info on texturing a sphere though IIRC the sphere is constructed differently

Share this post


Link to post
Share on other sites
Cheers Zedzeek, but I still have no clue.

The recusive subdivision was taken from "Interactive Computer Graphics: A Top-Down Approach with OpenGL " by Edward Angel.

It takes the form:

void divide_triangle(point a, point b, point c, int m)
{

// triangle subdivision using vertex numbers righthand rule applied to create outward pointing faces
//Uses recursive calls to subdivide the triangle

point v1, v2, v3;
int j;
if(m>0)
{
for(j=0; j<3; j++) v1[j]=a[j]+b[j];
normal(v1);
for(j=0; j<3; j++) v2[j]=a[j]+c[j];
normal(v2);
for(j=0; j<3; j++) v3[j]=b[j]+c[j];
normal(v3);
divide_triangle(a, v1, v2, m-1);
divide_triangle(c, v2, v3, m-1);
divide_triangle(b, v3, v1, m-1);
divide_triangle(v1, v3, v2, m-1);
}
else(triangle(a,b,c)); // draw triangle at end of recursion
}

The project is to design a solar system model. The lighting and perspective work ok, just mapping a texture on the earth is the problem. Anyone any other ideas?

Cheers,

Russ.

Share this post


Link to post
Share on other sites
yes that approach is in the red book as well.
the BIG problem with the recursive sphere is that u wont be able to take say a photo of jupiter and map it onto the sphere without first doing major fiddling with the original photo, benifits are that all the tris are equal size.
use the stacks/slices method of sphere generation for doing this (see paul bourkes site) though the problem there is the polygons get smaller at the poles, also another benift over the recursive is u have greater control over how many polygons will appear in the final sphere whereas the recursive method each successive sphere has exactlly 4x the number of tris.

Share this post


Link to post
Share on other sites
Are you by any chance studying Multimedia Technologies or Computer Graphics in UMIST, Manchester, UK? ))) I was there 2 years ago, had the exact same assignment, and used the exact same book as a starting point )) Fortunately, we didnt have to use recursive subdivision, so I built my spheres using typical sin/cos calculations... the method is by far slower, but it allows far easier mapping of texels onto the sphere... I would be really interested in seeing an opinion on how it can be done using recursive subdivision, since this would be the ideal solution to the problem in terms of speed. I wonder how this is done in the industry... is there a commonly accepted fast and accurate method?

Madanasta

Share this post


Link to post
Share on other sites
Actually it isn''t that difficlut - like someone said look at Paul Bourke''s Site.

I have a little program (VERY rough and ready) which tesselates an octohedron, and generates normals and texture coordinates for the vertices.

If you want the (VB) source code mail me

mark.shaxted@btinternet.com

Or if you just want the .exe, mail me the same!

Share this post


Link to post
Share on other sites
i couldnt find much info on splitting faces to make a sphere. So i did a bit of DIY, i''d heard of a geodesic sphere, so i read up on mathworld about them then set to doing it in gl, this is the result..

http://www.playbeing.co.uk/pics/geo_i.png

i''ve yet to go onto texture mapping it

Share this post


Link to post
Share on other sites
Thanks again guys,

I''ve had a look at Paul B''s web-site, and it gives a good tutorial on how to load a bitmap, but I''ve still no clue on how to map it to a sphere. Everything seems to be geared towards Cubes / squares.

ZedZeek, I don''t think it matters about being distorted at the poles, just as long as theres a texture on it.

Madanasta, I do go to UMIST yes, doing the Software Engineering though.

Shag, Its written in C++, so I don''t know whether the VB version would be of any use to me! Thanks anyhoo.

Anything else anyone?

Cheers,

Russ.

Share this post


Link to post
Share on other sites