LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: steelplume on July 25, 2010, 14:31:30

Title: UV mapping for a dome?
Post by: steelplume on July 25, 2010, 14:31:30
Hi,

it's my first post because I am a OpenGL/LWJGL newbie   ;D .

I am trying to understand how can I change UV mapping of a dome, I need a different texture map projection than this one coded below:



protected final void createDome(final float radius) {
int lats=16;
int longs=16;

GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textures2x4[0].getTextureID());

int i, j;
int halfLats = lats / 2;
for(i = 0; i <= halfLats; i++)
{
       double lat0 = MathUtils.PI * (-0.5 + (double) (i - 1) / lats);
       double z0 = Math.sin(lat0)* radius;
       double zr0 = Math.cos(lat0)* radius;

       double lat1 = MathUtils.PI * (-0.5 + (double) i / lats);
       double z1 = Math.sin(lat1)* radius;
       double zr1 = Math.cos(lat1)* radius;

       GL11.glBegin(GL11.GL_QUAD_STRIP);
       for(j = 0; j <= longs; j++)
  {
   double lng = 2 * MathUtils.PI * (double) (j - 1) / longs;
   double x = Math.cos(lng);
   double y = Math.sin(lng);

   double s1, s2, t;
   s1 = ((double) i) / halfLats;
   s2 = ((double) i + 1) / halfLats;
   t = ((double) j) / longs;

   GL11.glTexCoord2d(s1, t);
   GL11.glNormal3d(x * zr0, y * zr0, z0);
   GL11.glVertex3d(x * zr0, y * zr0, z0);

   GL11.glTexCoord2d(s2, t);
   GL11.glNormal3d(x * zr1, y * zr1, z1);
   GL11.glVertex3d(x * zr1, y * zr1, z1);
  }
       GL11.glEnd();
}

}




I attached the output image, pratically I need a UV mapping which places the Artic at the zenith/top
of the dome, and the Antartic streched on the bottom side of the dome... the Artic/Antartic map is only
used to figure out what I mean :P
Title: Re: UV mapping for a dome?
Post by: Luy on July 25, 2010, 23:15:45
Hi,

wikipedia explains how to do it on a sphere: http://en.wikipedia.org/wiki/UV_mapping#Finding_UV_on_a_sphere
By replacing phi (or theta) with twice that angle you should be able to get the desired result.