Results 1 to 2 of 2

Thread: Sphere texture mapping

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Location
    Milan
    Posts
    3

    Sphere texture mapping

    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

    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:
    Code :
    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:

    [img:center]http://img841.imageshack.us/i/problemavt.png/[/img]

    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

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2010
    Location
    Milan
    Posts
    3

    Re: Sphere texture mapping

    P.S: I am working with Android OpenGLES

Similar Threads

  1. Sphere Texture Mapping
    By girish3110 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-07-2008, 11:21 AM
  2. Texture Mapping a Sphere
    By OGL_PGR in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-10-2006, 08:16 AM
  3. Mapping texture to an sphere
    By thorsan in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-23-2004, 12:10 PM
  4. Texture mapping a sphere?
    By UnderWear in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-18-2002, 07:43 PM
  5. Texture mapping on sphere
    By abhiboy007 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-19-2001, 02:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean