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.

115 lines
2.0 KiB

  1. #include <windows.h>
  2. #include <GL/glu.h>
  3. #ifdef X11
  4. #include <GL/glx.h>
  5. #endif
  6. #include <math.h>
  7. #include <stdio.h>
  8. #ifdef WIN32
  9. #include "stonehen.h"
  10. #endif
  11. #include "Ring.h"
  12. inline float radians(float a) {return a * M_PI / 180.0;};
  13. Ring::Ring()
  14. {
  15. Point sar_dim, lin_dim;
  16. radius = 10;
  17. nstones = 30;
  18. sar_dim.set(.2, .5, 1);
  19. sarcen.set_dimensions(sar_dim);
  20. sarcen.translate(radius, 0, sar_dim.pt[2]);
  21. angle = 360.0 / (float)nstones;
  22. lin_dim.set(.2, .99 * tan(2.0 * M_PI / (float)nstones) *
  23. (radius - sar_dim.pt[0]) / 2.0, .2);
  24. lintel.set_dimensions(lin_dim);
  25. lintel.translate(radius, 0, 2.*sar_dim.pt[2] + lin_dim.pt[2]);
  26. }
  27. Ring::~Ring()
  28. {
  29. }
  30. void Ring::erode(float p)
  31. {
  32. sarcen.erode(p);
  33. lintel.erode(p);
  34. }
  35. void Ring::draw()
  36. {
  37. draw_sarcens();
  38. draw_lintels();
  39. }
  40. void Ring::draw_sarcens()
  41. {
  42. int i;
  43. for (i = 0; i < nstones; i++) {
  44. glPushMatrix();
  45. glRotatef(i * angle, 0, 0, 1);
  46. sarcen.draw();
  47. glPopMatrix();
  48. }
  49. }
  50. void Ring::draw_lintels()
  51. {
  52. int i;
  53. glPushMatrix();
  54. glRotatef(angle / 2.0, 0, 0, 1);
  55. for (i = 0; i < nstones; i++) {
  56. glPushMatrix();
  57. glRotatef(i * angle, 0, 0, 1);
  58. lintel.draw();
  59. glPopMatrix();
  60. }
  61. glPopMatrix();
  62. }
  63. void Ring::draw_shadow(Point dlight, GLfloat blur,
  64. Color color, Color diffuse)
  65. {
  66. draw_sarcens_shadows(dlight, blur, color, diffuse);
  67. draw_lintels_shadows(dlight, blur, color, diffuse);
  68. }
  69. void Ring::draw_sarcens_shadows(Point dlight, GLfloat blur,
  70. Color color, Color diffuse)
  71. {
  72. int i;
  73. Stone proto;
  74. proto = sarcen;
  75. for (i = 0; i < nstones; i++) {
  76. proto.rotate_self_aboutz(angle);
  77. proto.draw_shadow(dlight, blur, color, diffuse);
  78. }
  79. }
  80. void Ring::draw_lintels_shadows(Point dlight, GLfloat blur,
  81. Color color, Color diffuse)
  82. {
  83. int i;
  84. Stone proto;
  85. proto = lintel;
  86. proto.rotate_self_aboutz(angle / 2.0);
  87. for (i = 0; i < nstones; i++) {
  88. proto.rotate_self_aboutz(angle);
  89. proto.draw_shadow(dlight, blur, color, diffuse);
  90. }
  91. }