opengl - UV mapping for a dome? -
i trying understand how can change uv mapping of dome, need different texture map projection 1 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; <= 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) / 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) + 1) / halflats; t = ((double) j) / longs; // here: don't know how calculate 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 output image , original map. pratically need uv mapping places artic @ zenith/top of dome, , antartic streched on bottom side of dome... artic/antartic map used figure out mean, need it's not fit globe emisphere
output image http://img831.imageshack.us/img831/3481/lwjgl.png
source map http://img203.imageshack.us/img203/4930/earthc.png
take @ function calls (disclaimer: untested - haven't used lwjgl, concept should identical):
gl11.glmatrixmode(gl11.gl_texture); gl11.glrotate(90, 0, 0, 1); // (1) here transform texture space gl11.glmatrixmode(gl11.gl_modelview); // , on
basically, need rotate texture on object. , that's way - transform texture projection matrix. line (1) rotates texture 90 degrees along z axis (perpendicular texture plane). it's z axis, because last argument 1. last 3 arguments denote x, y , z respectively (i'll leave whole explanation later if you're interested).
the best can grasp basic stuff (projection, texture space, normal vectors, triangulation, continuity, particle systems , lot more) download trial version of 3d package , play it. learned lot out of playing 3d studio max (trial version available, , many more free). if have free time , learn new advise it. in end, if you're interested in 3d graphics you'll end using 1 way - 3d package or game engine level editor.
edit: after more reading recognized own code... swap of coordinates reflect symmetrically along diagonal. might end upside down, can fixed additional tweaking (or transforming view axis). here untested guess:
// tweaked pole right s1 = ((double) j) / longs; s2 = ((double) j + 1) / longs; t = ((double) i) / halflats;
try swapping s1 s2 if it's not right.
Comments
Post a Comment