draw_cappolys_ogl.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include <stdio.h>
  2. #include "vizual.h"
  3. #define COLOR3
  4. int draw_cappolys(Headp, D_spec, D_Cap, poly, x, y, direction, index)
  5. file_info *Headp;
  6. struct dspec *D_spec;
  7. struct Cap *D_Cap;
  8. struct poly_info *poly;
  9. int x;
  10. int y;
  11. int direction;
  12. int index;
  13. {
  14. int yloc, xloc;
  15. int t;
  16. double *vertices;
  17. double tmpvt[20][3]; /* these are going to be sent to v3d */
  18. float norm[3];
  19. int nverts;
  20. short color[3];
  21. /* RECONSTRUCT ACTUAL LOCATION OF POLYGONS */
  22. int start, stop;
  23. vertices = poly->verts;
  24. nverts = poly->vnum;
  25. if (!direction) {
  26. direction = -1; /* was 0,1, now -1,1 */
  27. start = nverts - 1;
  28. stop = -1;
  29. }
  30. else {
  31. start = 0;
  32. stop = nverts;
  33. }
  34. xloc = x;
  35. yloc = y;
  36. switch (D_Cap->side) {
  37. case 0:
  38. case 1:
  39. norm[2] = D_Cap->side ? -1.0 : 1.0;
  40. norm[0] = norm[1] = 0.0;
  41. for (t = start; t != stop; t += direction) {
  42. tmpvt[t][0] = (vertices[t << 1] + xloc) * D_spec->xscale;
  43. tmpvt[t][1] = (vertices[(t << 1) + 1] + yloc) * D_spec->yscale;
  44. tmpvt[t][2] = (D_Cap->z) * D_spec->zscale;
  45. }
  46. break;
  47. case 2:
  48. case 3:
  49. norm[0] = D_Cap->side == 2 ? 1.0 : -1.0;
  50. norm[1] = norm[2] = 0.0;
  51. for (t = start; t != stop; t += direction) {
  52. tmpvt[t][0] = (D_Cap->z) * D_spec->xscale;
  53. tmpvt[t][1] = (vertices[t << 1] + xloc) * D_spec->yscale;
  54. tmpvt[t][2] = (vertices[(t << 1) + 1] + yloc) * D_spec->zscale;
  55. }
  56. break;
  57. case 4:
  58. case 5:
  59. norm[1] = D_Cap->side == 4 ? 1.0 : -1.0;
  60. norm[0] = norm[2] = 0.0;
  61. for (t = start; t != stop; t += direction) {
  62. tmpvt[t][0] = (vertices[t << 1] + xloc) * D_spec->xscale;
  63. tmpvt[t][1] = (D_Cap->z) * D_spec->yscale;
  64. tmpvt[t][2] = (vertices[(t << 1) + 1] + yloc) * D_spec->zscale;
  65. }
  66. break;
  67. }
  68. /*now ready to draw the polygons, not going to worry about reversing
  69. the polygon ordering at this time */
  70. get_cat_color(Headp->linefax.tvalue[index], D_spec->ctable, color);
  71. glColor3sv(color);
  72. glBegin(GL_POLYGON);
  73. if (Headp->linefax.litmodel != 1)
  74. /* if not flat shade */
  75. glNormal3fv(norm);
  76. #ifdef CLOCKWISE
  77. for (t = 0; t < nverts; t++) {
  78. glVertex3dv(tmpvt[t]);
  79. }
  80. #else
  81. for (t = nverts - 1; t >= 0; t--) {
  82. glVertex3dv(tmpvt[t]);
  83. }
  84. #endif
  85. glEnd();
  86. return;
  87. }