Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
2.7 KiB

  1. #include <windows.h>
  2. #include <GL/glu.h>
  3. #ifdef X11
  4. #include <GL/glx.h>
  5. #endif
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #ifdef WIN32
  10. #include "stonehen.h"
  11. #endif
  12. #define ATMOSPHERE_EXTERN
  13. #include "atmosphe.h"
  14. const Weather clear("Clear", 0.);
  15. const Weather foggy("Foggy", .04, .5, white, Color(.6, .6, 1), white);
  16. const Weather very_foggy("Very Foggy", .25, .5, white, white, white);
  17. const Weather rainy("Rainy", .01, 1., black, Color(.35, .35, .35), black);
  18. Weather weathers[nweathers] = {clear, foggy, very_foggy, rainy};
  19. const float root3_2 = sqrt(3.) / 2.;
  20. inline float clamp(float a, float min = 0, float max = 1)
  21. {
  22. if (a < min) return min;
  23. else if (a > max) return max;
  24. else return a;
  25. }
  26. Weather::Weather()
  27. {
  28. strcpy(name, "No name");
  29. fog_density = 0;
  30. fog_color = white;
  31. fog_spread = 1;
  32. sun_brightness = 1;
  33. light_sun = GL_LIGHT0;
  34. light_ambient = GL_LIGHT1;
  35. sky_top = blue;
  36. sky_bottom = white;
  37. }
  38. Weather::Weather(const char *n, GLfloat fd, GLfloat fs, Color fc,
  39. Color s1, Color s2, GLfloat sb,
  40. GLenum ls, GLenum la)
  41. {
  42. strcpy(name, n);
  43. fog_density = fd;
  44. fog_color = fc;
  45. fog_spread = fs;
  46. sun_brightness = sb;
  47. light_sun = ls;
  48. light_ambient = la;
  49. sky_top = s1;
  50. sky_bottom = s2;
  51. }
  52. Weather::~Weather()
  53. {
  54. }
  55. Weather Weather::operator=(Weather a)
  56. {
  57. strcpy(name, a.name);
  58. fog_density = a.fog_density;
  59. fog_color = a.fog_color;
  60. fog_spread = a.fog_spread;
  61. sun_brightness = a.sun_brightness;
  62. light_sun = a.light_sun;
  63. light_ambient = a.light_ambient;
  64. sky_top = a.sky_top;
  65. sky_bottom = a.sky_bottom;
  66. return *this;
  67. }
  68. void Weather::apply(Point sun)
  69. {
  70. Color c;
  71. if (fog_density != 0) {
  72. glFogf(GL_FOG_DENSITY, fog_density);
  73. glFogfv(GL_FOG_COLOR, fog_color.c);
  74. glFogi(GL_FOG_MODE, GL_EXP2);
  75. }
  76. glLightfv(light_sun, GL_AMBIENT, black.c);
  77. c = white;
  78. c *= sun_brightness;
  79. glLightfv(light_sun, GL_DIFFUSE, c.c);
  80. glLightfv(light_sun, GL_SPECULAR, white.c);
  81. if (sun.pt[2] >= 0.0) glEnable(light_sun);
  82. else glDisable(light_sun);
  83. c = white;
  84. c *= .25;
  85. glLightfv(light_ambient, GL_AMBIENT, c.c);
  86. glLightfv(light_ambient, GL_DIFFUSE, black.c);
  87. glLightfv(light_ambient, GL_SPECULAR, black.c);
  88. glEnable(light_ambient);
  89. }
  90. void Weather::draw_sky(Point sun)
  91. {
  92. Point p;
  93. float c;
  94. Color bottom, top;
  95. if (sun.pt[2] >= .5) c = 1.;
  96. else if (sun.pt[2] >= -.5)
  97. c = sqrt(1. - sun.pt[2]*sun.pt[2])*.5 + sun.pt[2]*root3_2;
  98. else c = 0;
  99. bottom = sky_bottom * c;
  100. top = sky_top * c;
  101. /* This is drawn as a far-away quad */
  102. glBegin(GL_QUADS);
  103. glColor3fv(bottom.c);
  104. glVertex3f(-1, -1, -1);
  105. glVertex3f(1, -1, -1);
  106. glColor3fv(top.c);
  107. glVertex3f(1, 1, -1);
  108. glVertex3f(-1, 1, -1);
  109. glEnd();
  110. }
  111. GLfloat Weather::shadow_blur()
  112. {
  113. return clamp(fog_density * 10.);
  114. }