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.

129 lines
3.1 KiB

  1. /**************************************************************************
  2. * *
  3. * Copyright (C) 1989, Silicon Graphics, Inc. *
  4. * *
  5. * These coded instructions, statements, and computer programs contain *
  6. * unpublished proprietary information of Silicon Graphics, Inc., and *
  7. * are protected by Federal copyright law. They may not be disclosed *
  8. * to third parties or copied or duplicated in any form, in whole or *
  9. * in part, without the prior written consent of Silicon Graphics, Inc. *
  10. * *
  11. **************************************************************************/
  12. /* class.c */
  13. /* Derrick Burns - 1989 */
  14. #include <glos.h>
  15. #include <GL/gl.h>
  16. #include <GL/glu.h>
  17. #include "monotone.h"
  18. /*----------------------------------------------------------------------------
  19. * classify - classify a vertex
  20. *----------------------------------------------------------------------------
  21. */
  22. static Vertclass
  23. classify( Vert *vert )
  24. {
  25. float det;
  26. float ps, pt, ns, nt, ms, mt;
  27. ps = vert->prev->s;
  28. pt = vert->prev->t;
  29. ms = vert->s;
  30. mt = vert->t;
  31. ns = vert->next->s;
  32. nt = vert->next->t;
  33. if ((ps < ms) && (ms < ns)) return VC_OK_TOP;
  34. if ((ps > ms) && (ms > ns)) return VC_OK_BOTTOM;
  35. if (ps == ms) {
  36. if (ms == ns) {
  37. if (pt < mt)
  38. return VC_OK_TOP;
  39. else if( pt == mt )
  40. return VC_BAD_LONE;
  41. else
  42. return VC_OK_BOTTOM;
  43. }
  44. if (pt < mt) {
  45. if (ns < ms) return VC_OK_LEFT;
  46. return VC_OK_TOP;
  47. }
  48. if (pt > mt) {
  49. if (ns <= ms) return VC_OK_BOTTOM;
  50. return VC_OK_RIGHT;
  51. }
  52. return VC_BAD_ERROR;
  53. }
  54. if (ms == ns) {
  55. if (nt < mt) {
  56. if (ps >= ms) return VC_OK_BOTTOM;
  57. return VC_BAD_RIGHT;
  58. }
  59. if (nt > mt) {
  60. if (ms >= ps) return VC_OK_TOP;
  61. return VC_BAD_LEFT;
  62. }
  63. return VC_BAD_ERROR;
  64. }
  65. /* Calculate determinant of:
  66. *
  67. * | ps pt 1 |
  68. * | ms mt 1 |
  69. * | ns nt 1 |
  70. */
  71. det = ms*(nt-pt)+ns*(pt-mt)+ps*(mt-nt);
  72. if ((ps < ms) && (ns < ms)) {
  73. if (det < (float)0) return VC_BAD_RIGHT;
  74. if (det > (float)0) return VC_OK_LEFT;
  75. if (det == (float)0) return VC_BAD_ERROR;
  76. }
  77. if ((ps > ms) && (ns > ms)) {
  78. if (det < (float)0) return VC_BAD_LEFT;
  79. if (det > (float)0) return VC_OK_RIGHT;
  80. if (det == (float)0) return VC_BAD_ERROR;
  81. }
  82. return VC_BAD_ERROR;
  83. }
  84. /*----------------------------------------------------------------------------
  85. * unclassify_all - unclassify all vertices in a loop
  86. *----------------------------------------------------------------------------
  87. */
  88. void
  89. __gl_unclassify_all( Vert *vert )
  90. {
  91. Vert *last = vert;
  92. do {
  93. vert->vclass = VC_NO_CLASS;
  94. vert = vert->next;
  95. } while( vert != last );
  96. }
  97. /*----------------------------------------------------------------------------
  98. * classify_all - classify all vertices in a loop
  99. *----------------------------------------------------------------------------
  100. */
  101. int
  102. __gl_classify_all( Vert *vert )
  103. {
  104. int f = 0;
  105. Vert *last = vert;
  106. do {
  107. vert->nextid = vert->next->myid;
  108. vert->vclass = classify( vert );
  109. f |= vert->vclass;
  110. vert = vert->next;
  111. } while( vert != last );
  112. return f;
  113. }