Leaked source code of windows server 2003
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.

164 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 <math.h>
  39. #include <stdio.h>
  40. #include <GL/gl.h>
  41. #include "3d.h"
  42. #define static
  43. #define STACKDEPTH 10
  44. typedef struct {
  45. GLdouble mat[4][4];
  46. GLdouble norm[3][3];
  47. } mat_t;
  48. static mat_t matstack[STACKDEPTH] = {
  49. {{{1.0, 0.0, 0.0, 0.0},
  50. {0.0, 1.0, 0.0, 0.0},
  51. {0.0, 0.0, 1.0, 0.0},
  52. {0.0, 0.0, 0.0, 1.0}},
  53. {{1.0, 0.0, 0.0},
  54. {0.0, 1.0, 0.0},
  55. {0.0, 0.0, 1.0}}}
  56. };
  57. static int identitymat = 1;
  58. static int mattop = 0;
  59. void m_xformpt(GLdouble pin[3], GLdouble pout[3],
  60. GLdouble nin[3], GLdouble nout[3])
  61. {
  62. int i;
  63. GLdouble ptemp[3], ntemp[3];
  64. mat_t *m = &matstack[mattop];
  65. if (identitymat) {
  66. for (i = 0; i < 3; i++) {
  67. pout[i] = pin[i];
  68. nout[i] = nin[i];
  69. }
  70. return;
  71. }
  72. for (i = 0; i < 3; i++) {
  73. ptemp[i] = pin[0]*m->mat[0][i] +
  74. pin[1]*m->mat[1][i] +
  75. pin[2]*m->mat[2][i] +
  76. m->mat[3][i];
  77. ntemp[i] = nin[0]*m->norm[0][i] +
  78. nin[1]*m->norm[1][i] +
  79. nin[2]*m->norm[2][i];
  80. }
  81. for (i = 0; i < 3; i++) {
  82. pout[i] = ptemp[i];
  83. nout[i] = ntemp[i];
  84. }
  85. normalize(nout);
  86. }
  87. void m_xformptonly(GLdouble pin[3], GLdouble pout[3])
  88. {
  89. int i;
  90. GLdouble ptemp[3];
  91. mat_t *m = &matstack[mattop];
  92. if (identitymat) {
  93. for (i = 0; i < 3; i++) {
  94. pout[i] = pin[i];
  95. }
  96. return;
  97. }
  98. for (i = 0; i < 3; i++) {
  99. ptemp[i] = pin[0]*m->mat[0][i] +
  100. pin[1]*m->mat[1][i] +
  101. pin[2]*m->mat[2][i] +
  102. m->mat[3][i];
  103. }
  104. for (i = 0; i < 3; i++) {
  105. pout[i] = ptemp[i];
  106. }
  107. }
  108. void m_pushmatrix(void)
  109. {
  110. if (mattop < STACKDEPTH-1) {
  111. matstack[mattop+1] = matstack[mattop];
  112. mattop++;
  113. } else
  114. error("m_pushmatrix: stack overflow\n");
  115. }
  116. void m_popmatrix(void)
  117. {
  118. if (mattop > 0)
  119. mattop--;
  120. else
  121. error("m_popmatrix: stack underflow\n");
  122. }
  123. void m_translate(GLdouble x, GLdouble y, GLdouble z)
  124. {
  125. int i;
  126. mat_t *m = &matstack[mattop];
  127. identitymat = 0;
  128. for (i = 0; i < 4; i++)
  129. m->mat[3][i] = x*m->mat[0][i] +
  130. y*m->mat[1][i] +
  131. z*m->mat[2][i] +
  132. m->mat[3][i];
  133. }
  134. void m_scale(GLdouble x, GLdouble y, GLdouble z)
  135. {
  136. int i;
  137. mat_t *m = &matstack[mattop];
  138. identitymat = 0;
  139. for (i = 0; i < 3; i++) {
  140. m->mat[0][i] *= x;
  141. m->mat[1][i] *= y;
  142. m->mat[2][i] *= z;
  143. }
  144. for (i = 0; i < 3; i++) {
  145. m->norm[0][i] /= x;
  146. m->norm[1][i] /= y;
  147. m->norm[2][i] /= z;
  148. }
  149. }