#ifdef HAVE_CONFIG_H # include #endif #ifdef HAVE_WINDOWS_H # include #endif #include #include #include #include #if defined( __APPLE__) # include # include #else # include # ifdef HAVE_GLUT_H # include # endif #endif #define TEXRES_X 256 #define TEXRES_Y 256 #ifdef HAVE_GLUT_H unsigned char env_map[TEXRES_X][TEXRES_Y][4]; GLuint texName; int window_x = 640, window_y = 480; float alpha = 0.0, beta = 0.0; /*****************************************************************/ /*****************************************************************/ /*****************************************************************/ void setColor(float x, float y, float z, float angular_size, float r, float g, float b, float a) { //normalize float inv_length = 1.0 / sqrt(x*x + y*y + z*z); x *= inv_length; y *= inv_length; z *= inv_length; printf("x = %f, y = %f, z = %f\n", x, y, z); float cos_angular_size = cos(angular_size*3.1415/180.0); printf("cos_angular_size = %f\n", cos_angular_size); for(float tz_sign = -1.0; tz_sign < 3.0; tz_sign += 2.0) { for(float tx = -1.0; tx <= 1.0; tx += 0.01) { for(float ty = -1.0; ty <= 1.0; ty += 0.01) { if ((1.0 - tx*tx - ty*ty)<0.0) continue; float tz = tz_sign * sqrt(1.0 - tx*tx - ty*ty); float cos_phi = x*tx + y*ty + z*tz; if (cos_angular_size < cos_phi) { float rx = tx; //mirroring on the z=0 plane float ry = ty; float rz = -tz; float inv_m = 1.0 / (2.0 * sqrt(rx*rx + ry*ry + (rz + 1)*(rz + 1))); int s = (int)(TEXRES_X * (rx * inv_m + 0.5)); int t = (int)(TEXRES_Y * (ry * inv_m + 0.5)); //seg_fault protection: if (s<0) s=0; if (s>=TEXRES_X) s=TEXRES_X-1; if (t<0) t=0; if (t>=TEXRES_Y) t=TEXRES_Y-1; env_map[s][t][0] = (unsigned char)(r * 255); env_map[s][t][1] = (unsigned char)(g * 255); env_map[s][t][2] = (unsigned char)(b * 255); env_map[s][t][3] = (unsigned char)(a * 255); } } } } } /*****************************************************************/ /*****************************************************************/ /*****************************************************************/ void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); for(int x=0; x= 360.0) alpha -= 360.0; break; case '2': alpha -= 1.0; if (alpha < 0.0) alpha += 360.0; break; case '4': beta -= 1.0; if (beta <= -90.0) beta = -90.0; break; case '6': beta += 1.0; if (beta >= 90.0) beta = 90.0; break; case '5': alpha = 0.0; beta = 0.0; break; } } #endif /* HAVE_GLUT_H */ int main(int argc, char** argv) { #ifdef HAVE_GLUT_H glutInitWindowSize(window_x, window_y); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); #else printf("GL Utility Toolkit (glut) was not found on this system.\n"); #endif return 0; }