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.

145 lines
3.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 "Color.h"
  12. #include "Telescop.h"
  13. inline float radians(float a) {return M_PI * a / 180.0;}
  14. Telescope::Telescope(GLfloat x, GLfloat y)
  15. {
  16. xpos = x;
  17. ypos = y;
  18. divisions = 20;
  19. radius = .1;
  20. disk = gluNewQuadric();
  21. cylinder = gluNewQuadric();
  22. gluQuadricNormals(disk, GLU_FLAT);
  23. gluQuadricNormals(cylinder, GLU_SMOOTH);
  24. gluQuadricTexture(disk, GL_TRUE);
  25. gluQuadricTexture(cylinder, GL_TRUE);
  26. }
  27. Telescope::~Telescope()
  28. {
  29. gluDeleteQuadric(disk);
  30. gluDeleteQuadric(cylinder);
  31. }
  32. void Telescope::draw_setup(GLfloat fov, GLfloat aspect, int perspective)
  33. {
  34. GLfloat near_plane;
  35. /* Worry about the aspect ratio later */
  36. near_plane = .5 / tan(radians(fov / 2.0));
  37. glMatrixMode(GL_PROJECTION);
  38. glPushMatrix();
  39. glLoadIdentity();
  40. if (perspective) gluPerspective(fov, aspect, near_plane - .01, 10.0);
  41. else
  42. fprintf(stderr,
  43. "Warning: Drawing telescope using orthographic projection.\n");
  44. gluLookAt(0, 0, -near_plane,
  45. 0, 0, 1,
  46. 0, 1, 0);
  47. glMatrixMode(GL_MODELVIEW);
  48. glPushMatrix();
  49. glLoadIdentity();
  50. glTranslatef(xpos, ypos, 0);
  51. }
  52. void Telescope::draw_fake()
  53. {
  54. glBegin(GL_QUADS);
  55. glColor3f(1, 1, 1);
  56. glVertex3f(-radius, -radius, .01);
  57. glVertex3f(radius, -radius, .01);
  58. glVertex3f(radius, radius, .01);
  59. glVertex3f(-radius, radius, .01);
  60. glEnd();
  61. }
  62. void Telescope::draw_body()
  63. {
  64. Color c;
  65. glPushMatrix();
  66. glColor3f(1, 1, 0);
  67. gluDisk(disk, radius, 1.1 * radius, divisions, 1);
  68. gluCylinder(cylinder, 1.1 * radius, 1.1 * radius, .1 * radius, divisions, 1);
  69. glTranslatef(0, 0, .1*radius);
  70. gluDisk(disk, radius, 1.1 * radius, divisions, 1);
  71. glPushAttrib(GL_ENABLE_BIT);
  72. glDisable(GL_TEXTURE_2D);
  73. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white.c);
  74. glColor3f(0, 0, 0);
  75. gluCylinder(cylinder, 1.05 * radius, .95 * radius, .25, divisions, 1);
  76. glPopAttrib();
  77. /* Would just do this with a push / pop, but that seems to be broken.
  78. * glGetMaterialfv also seems to be broken, so we can't use that either. */
  79. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black.c);
  80. glTranslatef(0, 0, .25);
  81. glColor3f(1, 1, 0);
  82. gluDisk(disk, .95 * radius, 1.05 * radius, divisions, 1);
  83. gluCylinder(cylinder, 1.05 * radius, 1.05 * radius, .1 * radius,
  84. divisions, 1);
  85. glTranslatef(0, 0, .1*radius);
  86. gluDisk(disk, .95 * radius, 1.05 * radius, divisions, 1);
  87. glPopMatrix();
  88. }
  89. void Telescope::draw_takedown()
  90. {
  91. glMatrixMode(GL_PROJECTION);
  92. glPopMatrix();
  93. glMatrixMode(GL_MODELVIEW);
  94. glPopMatrix();
  95. }
  96. void Telescope::draw_lens()
  97. {
  98. gluDisk(disk, 0, radius, divisions, 1);
  99. }
  100. void Telescope::set_divisions(int d)
  101. {
  102. // Someday we'll put all the quadric stuff in display lists...
  103. divisions = d;
  104. }
  105. int Telescope::get_divisions()
  106. {
  107. return divisions;
  108. }
  109. void Telescope::set_radius(GLfloat r)
  110. {
  111. // Someday this might have to update some display lists
  112. radius = r;
  113. }
  114. GLfloat Telescope::get_radius()
  115. {
  116. return radius;
  117. }