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.

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