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.

67 lines
1.1 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. #ifdef WIN32
  8. #include "stonehen.h"
  9. #endif
  10. #include "Roundwal.h"
  11. Roundwall::Roundwall()
  12. {
  13. height = 2;
  14. radius = 20;
  15. divisions = 20;
  16. sint = cost = NULL;
  17. }
  18. void Roundwall::draw()
  19. {
  20. float texx = 0;
  21. int i;
  22. if (sint == NULL) compute_tables();
  23. glBegin(GL_QUAD_STRIP);
  24. for (i = 0; i <= divisions; i++, texx += 1.) {
  25. glTexCoord2f(texx, 0);
  26. glNormal3f(-cost[i], -sint[i], 0);
  27. glVertex3f(radius * cost[i], radius * sint[i], 0);
  28. glTexCoord2f(texx, 1);
  29. glVertex3f(radius * cost[i], radius * sint[i], height);
  30. }
  31. glEnd();
  32. }
  33. void Roundwall::set_divisions(int d)
  34. {
  35. if (divisions != d) delete_tables();
  36. divisions = d;
  37. }
  38. void Roundwall::delete_tables()
  39. {
  40. delete sint;
  41. delete cost;
  42. sint = cost = NULL;
  43. }
  44. void Roundwall::compute_tables()
  45. {
  46. int i;
  47. float t, dt;
  48. delete_tables();
  49. cost = new float[divisions + 1];
  50. sint = new float[divisions + 1];
  51. dt = 2. * M_PI / divisions;
  52. for (i = 0, t = 0.; i <= divisions; i++, t += dt) {
  53. cost[i] = cos(t);
  54. sint[i] = sin(t);
  55. }
  56. }