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.

147 lines
4.4 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. #include <windows.h>
  38. #include <GL/gl.h>
  39. #include <math.h>
  40. #include <stdio.h>
  41. #ifdef WIN32
  42. #include "stonehen.h"
  43. #endif
  44. #define POINT_EXTERN
  45. #include "Point.h"
  46. Point Point::rotate_abouty(GLfloat c, GLfloat s)
  47. {
  48. val.pt[0] = c*pt[0] + s*pt[2];
  49. val.pt[1] = pt[1];
  50. val.pt[2] = -s*pt[0] + c*pt[2];
  51. return val;
  52. }
  53. Point Point::rotate_aboutz(GLfloat c, GLfloat s)
  54. {
  55. val.pt[0] = c*pt[0] - s*pt[1];
  56. val.pt[1] = s*pt[0] + c*pt[1];
  57. val.pt[2] = pt[2];
  58. return val;
  59. }
  60. void Point::refract_self(Point light, Point N, GLfloat I)
  61. {
  62. GLfloat t;
  63. Point dlight;
  64. dlight = refract_direction(light, N, I);
  65. t = -pt[2] / dlight.pt[2];
  66. pt[0] = pt[0] + dlight.pt[0]*t;
  67. pt[1] = pt[1] + dlight.pt[1]*t;
  68. pt[2] = 0;
  69. }
  70. Point Point::refract_direction(Point light, Point N, GLfloat I)
  71. {
  72. GLfloat cos1, sin1, cos2, sin2, m;
  73. GLfloat dlight[3], dN[3], axis[3];
  74. /* dlight = (light - *this).unit() * -1.0; */
  75. dlight[0] = pt[0] - light.pt[0];
  76. dlight[1] = pt[1] - light.pt[1];
  77. dlight[2] = pt[2] - light.pt[2];
  78. m = sqrt(dlight[0]*dlight[0] + dlight[1]*dlight[1] + dlight[2]*dlight[2]);
  79. dlight[0] /= m;
  80. dlight[1] /= m;
  81. dlight[2] /= m;
  82. // dN = N * -1.0;
  83. dN[0] = -N.pt[0];
  84. dN[1] = -N.pt[1];
  85. dN[2] = -N.pt[2];
  86. // cos1 = dN.dot(dlight);
  87. cos1 = dN[0]*dlight[0] + dN[1]*dlight[1] + dN[2]*dlight[2];
  88. if (1.0 - cos1*cos1 < point_fudge) {
  89. val = dN;
  90. return val;
  91. }
  92. // axis = ((dN * dlight) * dN).unit();
  93. val.pt[0] = dN[1]*dlight[2] - dlight[1]*dN[2];
  94. val.pt[1] = dN[2]*dlight[0] - dlight[2]*dN[0];
  95. val.pt[2] = dN[0]*dlight[1] - dN[1]*dlight[0];
  96. axis[0] = val.pt[1]*dN[2] - dN[1]*val.pt[2];
  97. axis[1] = val.pt[2]*dN[0] - dN[2]*val.pt[0];
  98. axis[2] = val.pt[0]*dN[1] - val.pt[1]*dN[0];
  99. m = sqrt(axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2]);
  100. axis[0] /= m;
  101. axis[1] /= m;
  102. axis[2] /= m;
  103. if (axis[0]*axis[0] > point_fudge)
  104. sin1 = (dlight[0] - dN[0] * cos1) / axis[0];
  105. else if (axis[1]*axis[1] > point_fudge)
  106. sin1 = (dlight[1] - dN[1] * cos1) / axis[1];
  107. else sin1 = dlight[2] - dN[2] * cos1;
  108. sin2 = sin1 / I;
  109. cos2 = (sin1*sin1 < 1.0) ? sqrt(1.0 - sin2*sin2) : 0;
  110. dlight[0] = dN[0]*cos2 + axis[0]*sin2;
  111. dlight[1] = dN[1]*cos2 + axis[1]*sin2;
  112. dlight[2] = dN[2]*cos2 + axis[2]*sin2;
  113. /* I'm not sure this is quite legal */
  114. if (dlight[2] > 0.0) dlight[2] = -dlight[2];
  115. val = dlight;
  116. return val;
  117. }
  118. void Point::print()
  119. {
  120. print("%f %f %f\n");
  121. }
  122. void Point::print(const char *format)
  123. {
  124. printf(format, this->pt[0], this->pt[1], this->pt[2], 1.0);
  125. }