#include #include #include /* Create a hemisphere with texture coordinates for mapping a fisheye image as texture. Only intended to illustrate/verify the mathematics. */ int N = 32; // Mesh resolution, must be multiple of 4 double radius = 1; typedef struct { double x,y,z; double nx,ny,nz; double u,v; } MESHVERTEX; int main(int argc,char **argv) { int i,j,index = 0; int i1,i2,i3,i4; double theta,phi,r; MESHVERTEX *p = NULL,n; double len; FILE *fptr; if (argc < 3) { fprintf(stderr,"Usage: %s res radius\n",argv[0]); exit(-1); } N = atoi(argv[1]); radius = atof(argv[2]); // Create data if ((p = malloc((N+1)*(N/4+1)*sizeof(MESHVERTEX))) == NULL) { fprintf(stderr,"malloc failed\n"); exit(-1); } for (j=0;j<=N/4;j++) { for (i=0;i<=N;i++) { theta = i * 2 * M_PI / N; phi = M_PI_2 - M_PI_2 * j / (N/4); p[index].x = radius * cos(phi) * cos(theta); p[index].y = radius * cos(phi) * sin(theta); p[index].z = radius * sin(phi); p[index].nx = p[index].x; p[index].ny = p[index].y; p[index].nz = p[index].z; index++; } } // Calculate texture coordinates for (i=0;i 1 || p[i].v < 0 || p[i].v > 1) fprintf(stderr,"u:%8.5f v:%8.5f phi:%8.5f theta:%8.5f r:%8.5f\n",p[i].u,p[i].v,phi,theta,r); } // Save as textured obj file fptr = fopen("fishtexture.obj","w"); fprintf(fptr,"mtllib fishtexture.mtl\n"); // Vertices for (i=0;i