PDA

View Full Version : Sphere texture mapping



pedr0
12-22-2010, 03:20 AM
Hi at all,

I am a newbye developer on OpenGL and I have to develop an sphere with texture mapping for have a result like this:

Virtual Tour (http://panora.it/)

I am making a porting of a application and the code I am using isn't totally write by me, for this reason I have some doubts.
This is the code for the sphere generation:


public Sphere(int space, float radius, float H,float K,float Z, Bitmap image){

this.totalVertexCount = (((90 / space) * (360 / space) * 4) * 2);
this.pVertices = Vertice.getArray(totalVertexCount);
this.pNormal = Texture.getArray(totalVertexCount);
this.textures_ids = IntBuffer.allocate(2);
this.image = image;
int n;
double a;
double b;
int tcount;
n = 0;


for( b = 0; b <= 180 - space; b+=space){
tcount = 360;
for( a = 0; a <= 360 - space; a+=space, tcount-=space){

pVertices[n].X = (float) (radius * Math.sin((a) / 180 * Math.PI) * Math.sin((b) / 180 * Math.PI) - H);
pVertices[n].Z = (float) (radius * Math.cos((a) / 180 * Math.PI) * Math.sin((b) / 180 * Math.PI) + K);
pVertices[n].Y = (float) (radius * Math.cos((b) / 180 * Math.PI) - Z);
pNormal[n].V = (float) ((2.0f * b) / 360.0f);
pNormal[n].U = (float) ((2.0* tcount) / 360.0f);

if(pNormal[n].U>=1.0 &amp;&amp; a<=180-space)
pNormal[n].U -= 1.0;



n++;

pVertices[n].X = (float) (radius * Math.sin((a) / 180 * Math.PI) * Math.sin((b + space) / 180 * Math.PI) - H);
pVertices[n].Z = (float) (radius * Math.cos((a) / 180 * Math.PI) * Math.sin((b + space) / 180 * Math.PI) + K);
pVertices[n].Y = (float) (radius * Math.cos((b + space) / 180 * Math.PI) - Z);

pNormal[n].V = (float) ((2.0f * (b + space)) / 360.0f);
pNormal[n].U = (float) ((2.0* tcount) / 360.0f);

if(pNormal[n].U>=1.0 &amp;&amp; a<=180-space)
pNormal[n].U -= 1.0;

n++;

pVertices[n].X = (float) (radius * Math.sin((a + space) / 180 * Math.PI) * Math.sin((b) / 180 * Math.PI) - H);
pVertices[n].Z = (float) (radius * Math.cos((a + space) / 180 * Math.PI) * Math.sin((b) / 180 * Math.PI) + K);
pVertices[n].Y = (float) (radius * Math.cos((b) / 180 * Math.PI) - Z);
pNormal[n].V = (float) ((2.0f * b) / 360.0f);
pNormal[n].U = (float) (2.0*( tcount - space) / 360.0f);

if(pNormal[n].U>=1.0 &amp;&amp; a<=180-space)
pNormal[n].U -= 1.0;

n++;

pVertices[n].X = (float) (radius * Math.sin((a + space) / 180 * Math.PI) * Math.sin((b + space) / 180 * Math.PI) - H);
pVertices[n].Z = (float) (radius * Math.cos((a + space) / 180 * Math.PI) * Math.sin((b + space) / 180 * Math.PI) + K);
pVertices[n].Y = (float) (radius * Math.cos((b + space) / 180 * Math.PI) - Z);
pNormal[n].V = (float) ((2.0f * (b + space)) / 360.0f);
pNormal[n].U = (float) (2.0*( tcount - space) / 360.0f);

if(pNormal[n].U>=1.0 &amp;&amp; a<=180-space)
pNormal[n].U -= 1.0;

n++;

}


}
[fill buffer and other stuff]
}

I am really sure that the points are correct but I am not sure about normal, the problems is result:

http://img841.imageshack.us/i/problemavt.png/

What's wrong:

1) Points or Normal vector?
2) Order with points of the sphere are generated?
3) Some other stuff?


Thanks a lot in advanced.
pedr0

pedr0
12-22-2010, 05:04 AM
P.S: I am working with Android OpenGLES