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.

176 lines
5.6 KiB

  1. /*
  2. * (c) Copyright 1993, Silicon Graphics, Inc.
  3. * ALL RIGHTS RESERVED
  4. * Permission to use, copy, modify, and distribute this software for
  5. * any purpose and without fee is hereby granted, provided that the above
  6. * copyright notice appear in all copies and that both the copyright notice
  7. * and this permission notice appear in supporting documentation, and that
  8. * the name of Silicon Graphics, Inc. not be used in advertising
  9. * or publicity pertaining to distribution of the software without specific,
  10. * written prior permission.
  11. *
  12. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  16. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  21. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24. *
  25. * US Government Users Restricted Rights
  26. * Use, duplication, or disclosure by the Government is subject to
  27. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29. * clause at DFARS 252.227-7013 and/or in similar or successor
  30. * clauses in the FAR or the DOD or NASA FAR Supplement.
  31. * Unpublished-- rights reserved under the copyright laws of the
  32. * United States. Contractor/manufacturer is Silicon Graphics,
  33. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  34. *
  35. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36. */
  37. #ifndef UNITDISK_H
  38. #define UNITDISK_H
  39. #define M_PI 3.141592654
  40. #define M_2_PI 6.283185307
  41. #include "color.hxx"
  42. #include "scene.hxx"
  43. /* Disks are sort of like spheres that have been flattened into
  44. * the xy plane without changing the normals */
  45. /* They are always made up of quadrilaterals */
  46. class Unitdisk {
  47. public:
  48. Unitdisk();
  49. ~Unitdisk();
  50. inline Unitdisk operator=(Unitdisk a);
  51. void draw();
  52. void draw_by_perimeter(int pass_colors = 0,
  53. int pass_norms = 0,
  54. int pass_tex = 0);
  55. void set_divisions(int new_rdivisions, int new_tdivisions);
  56. int get_rdivisions();
  57. int get_tdivisions();
  58. /* How big the section of the sphere is */
  59. void set_angle(float new_angle);
  60. GLfloat get_angle();
  61. /* This comes from the angle */
  62. GLfloat get_radius();
  63. /* Allocate points to hold the right number of things */
  64. void alloc_points();
  65. void alloc_normals();
  66. void alloc_points_normals();
  67. void free_points();
  68. void free_normals();
  69. void free_points_normals();
  70. /* Fill the points / normals with the appropriate sin and cos values */
  71. void fill_points();
  72. void fill_normals();
  73. void fill_points_normals();
  74. /* These are mallocing */
  75. void copy_points(Unitdisk src);
  76. void copy_normals(Unitdisk src);
  77. void copy_normals_from_points(Unitdisk src);
  78. void copy_normals_from_points();
  79. /* These transform all the points */
  80. void translate(Point trans);
  81. void scale(float s);
  82. void scale_translate(float s, Point trans);
  83. /* Project all points into xy plane along normal or through projpt */
  84. void project();
  85. void project_borrow_points(Unitdisk src);
  86. void project(Point projpt);
  87. /* Change all normals from their original direction (NOT their current
  88. * direction) to refracted direction. Normals do not have to be computed
  89. * before calling this. However, the disk must still be in the xy plane
  90. * and the light must be on the z axis*/
  91. void refract_normals(Point light, float I);
  92. /* Points the disk (meaning the normal at the center of the disk)
  93. * in direction d */
  94. void face_direction(Point d);
  95. void face_direction(Point d, Unitdisk src);
  96. /* Allocate colors */
  97. void alloc_colors();
  98. void free_colors();
  99. void set_colors(Color c);
  100. void add_colors(Color c);
  101. void map_normals_to_colors();
  102. void map_z_to_colors();
  103. void scale_colors_by_z();
  104. void scale_alpha_by_z();
  105. void scale_colors_by_normals(Point light);
  106. void scale_colors_by_normals(Point light, Unitdisk src_normals);
  107. void scale_colors_by_points(Point light, Unitdisk src_points);
  108. /* Computes how much the area of a section differs from the corresponding
  109. * section in disk and scales the color by this amount.*/
  110. void scale_colors_by_darea(Unitdisk disk);
  111. private:
  112. int rdivisions, tdivisions;
  113. Point *points, *normals;
  114. int points_size, normals_size;
  115. Color *colors;
  116. int colors_size;
  117. Point sphere;
  118. GLfloat angle;
  119. Point zaxis;
  120. int still_in_xy;
  121. float *sintable, *costable;
  122. void draw_nocolors();
  123. void draw_colors_normals();
  124. void draw_colors_nonormals();
  125. void scale_colors_by_either(Point dlight, Point *what);
  126. int get_npoints();
  127. void copy_either(Point *dpt, Point *spt);
  128. void fill_either(Point *what);
  129. void fill_points_strip1();
  130. void fill_normals_strip1();
  131. void fill_either_strip1(Point *what);
  132. void fill_trig_tables();
  133. inline float Unitdisk::area_triangle(Point a, Point b, Point c);
  134. inline float Unitdisk::area_triangle(GLfloat *a, GLfloat *b, GLfloat *c);
  135. inline float Unitdisk::area_2triangle(GLfloat *a, GLfloat *b, GLfloat *c);
  136. };
  137. inline Unitdisk Unitdisk::operator=(Unitdisk a)
  138. {
  139. rdivisions = a.rdivisions;
  140. tdivisions = a.tdivisions;
  141. points = a.points;
  142. normals = a.normals;
  143. colors = a.colors;
  144. sphere = a.sphere;
  145. angle = a.angle;
  146. zaxis = a.zaxis;
  147. return *this;
  148. }
  149. #endif