views:

55

answers:

1

Hi,

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;

            // HERE: I don't know how to calculate the UV mapping
            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 linked the output image and the original map. 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, my need it's not to fit a globe emisphere

Output image

Source map

+1  A: 

Take a look at this function calls (disclaimer: untested - I haven't used LWJGL, but the concept should be identical):

GL11.glMatrixMode(GL11.GL_TEXTURE);
GL11.glRotate(90, 0, 0, 1);    // (1) Here you transform texture space
GL11.glMatrixMode(GL11.GL_MODELVIEW);
// and so on

Basically, you need to rotate texture on object. And that's the way you do it - transform texture projection matrix. The line (1) rotates texture 90 degrees along Z axis (perpendicular to texture plane). It's Z axis, because the last argument is 1. Last three arguments denote X, Y and Z respectively (I'll leave the whole explanation for later if you're interested).

The best You can do is to grasp all the basic stuff (projection, texture space, normal vectors, triangulation, continuity, particle systems and a lot more) is to download some trial version of a 3d package and play with it. I learned a lot just out of playing with 3D Studio Max (trial version available, and many more for free). If you have some free time and will to learn something new I strongly advise to look into it. In the end, if You're really interested in 3D graphics You'll end up using one any way - be it 3d package or game engine level editor.

EDIT: After more reading I recognized my own code... Basically you could only swap some of the coordinates to reflect symmetrically along diagonal. You might end up upside down, but that can also be fixed with additional tweaking (or transforming the view axis). Here is my untested guess:

// tweaked to get pole right
s1 = ((double) j) / longs;
s2 = ((double) j + 1) / longs;
t  = ((double) i) / halfLats;

Try swapping s1 with s2 if it's not right.

Rekin
Yes, it's defintively your code! after get the code working I missed the link where I found it, sorry
Steel Plume