home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / VIEW3.C < prev    next >
C/C++ Source or Header  |  1996-06-05  |  32KB  |  1,291 lines

  1. /*
  2.  *        表示
  3.  *
  4.  *        Copyright    Koabayashi    1993.10.24
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <math.h>
  11. #include <assert.h>
  12.  
  13. #define    VIEW_LOCAL
  14.  
  15. #include "matrix.h"
  16. #include "poly.h"
  17. #include "view.h"
  18. #include "model.h"
  19.  
  20. #include "graph.h"
  21. #include "input.h"
  22.  
  23. static    short    UpArrow[] = {
  24.     0xCC00, 0xCC00, 0x8400, 0x8400, 0x0000, 0x0000,
  25. };
  26. static    short    DownArrow[] = {
  27.     0x0000, 0x0000, 0x8400, 0x8400, 0xCC00, 0xCC00,
  28. };
  29. static    short    LeftArrow[] = {
  30.     0xF000, 0xC000, 0x0000, 0x0000, 0xC000, 0xF000,
  31. };
  32. static    short    RightArrow[] = {
  33.     0x3C00, 0x0C00, 0x0000, 0x0000, 0x0C00, 0x3C00,
  34. };
  35.  
  36. static    int            ViewX1 = 0 ;            /*    ビューポート    */
  37. static    int            ViewY1 = 0 ;
  38. static    int            ViewX2 = 4096;
  39. static    int            ViewY2 = 4096 ;
  40.  
  41. #ifdef    X68K
  42. static    int            TmpClear = TRUE ;
  43. #elif defined(PC98) || defined(PC) || defined(WINDOWS)
  44. static    int            TmpClear = FALSE ;
  45. #else
  46. #error    "X68K or PC98 or PC or WINDOWS must be defined"
  47. #endif
  48.  
  49. #define    swap( a, b )    { int _w ; _w = a ; a = b ; b = _w ; }
  50.  
  51. #define MAXTEMPLINE 4096
  52. typedef struct {
  53.     short x1, y1, z1;
  54.     short x2, y2, z2;
  55.     short px1, py1, pz1;
  56.     short px2, py2, pz2;
  57. }    TempEdge;
  58.  
  59. TempEdge tempedge[MAXTEMPLINE];
  60. static int tempedgecount;
  61.  
  62. typedef struct {
  63.     short x, y, z;
  64.     short px, py, pz;
  65. } TempVertex;
  66.  
  67. TempVertex    tempvertex[MAXTEMPLINE];
  68. static int tempvertexcount;
  69.  
  70. static    void    DisplayFrame( ViewWindow*, int );
  71. static    void    DisplayGrid( ViewWindow*, int, int, int );
  72. static    void    ClearWin( ViewWindow*, int );
  73. static    int        ViewIn( ViewWindow*, int, int, int, int );
  74. static    void    DrawVertexWin( Polygon*, int );
  75. static    void    DrawVertexPers( Polygon*, int );
  76. static    void    DrawVector( Polygon*, int );
  77. static    void    DrawPolyVector( Polygon*, int );
  78.  
  79. extern    int    viewbox_drawflag;
  80. extern    Vertex viewbox_p1, viewbox_p2;
  81. extern    Matrix    viewbox_mat;
  82.  
  83. extern int viewbox2d_x1, viewbox2d_y1, viewbox2d_x2, viewbox2d_y2;
  84. extern int viewbox2d_drawflag ;
  85.  
  86. /*    フレーム表示    */
  87. void    ViewFrame()
  88. {
  89.     /*graph_cls( 0 );*/
  90.  
  91.     if ( ViewMode & VIEW_XY )
  92.         DisplayFrame( &WinXY, TRUE );
  93.  
  94.     if ( ViewMode & VIEW_YZ )
  95.         DisplayFrame( &WinYZ, TRUE );
  96.  
  97.     if ( ViewMode & VIEW_ZX )
  98.         DisplayFrame( &WinZX, TRUE );
  99.  
  100.     if ( ViewMode & VIEW_PERS )
  101.         DisplayFrame( &WinPers, FALSE );
  102. }
  103.  
  104. static    void    DisplayFrame( win, sw )
  105. ViewWindow    *win ;
  106. int            sw ;
  107. {
  108.     int        x1, y1, x2, y2 ;
  109.  
  110.     x1 = win->x ;
  111.     y1 = win->y ;
  112.     x2 = win->x + win->h - 1 ;
  113.     y2 = win->y + win->v - 1 ;
  114.  
  115.     graph_fill( x1, y1, x2, y1+(FRAME_WIDTH-2), FRAME_COLOR );
  116.     graph_fill( x1, y2-(FRAME_WIDTH-2), x2, y2, FRAME_COLOR );
  117.     graph_fill( x1, y1, x1+(FRAME_WIDTH-2), y2, FRAME_COLOR );
  118.     graph_fill( x2-(FRAME_WIDTH-2), y1, x2, y2, FRAME_COLOR );
  119.  
  120.     if ( sw )
  121.     {
  122.         graph_pattern( ( x1 + x2 ) / 2 - 3, y1 + 3, FRAME_COLOR, UpArrow, 6, 6 );
  123.         graph_pattern( ( x1 + x2 ) / 2 - 3, y2 - 9, FRAME_COLOR, DownArrow, 6, 6 );
  124.         graph_pattern( x1 + 3, ( y1 + y2 ) / 2 - 3, FRAME_COLOR, LeftArrow, 6, 6 );
  125.         graph_pattern( x2 - 9, ( y1 + y2 ) / 2 - 3, FRAME_COLOR, RightArrow, 6, 6 );
  126.     }
  127.     graph_box( x1, y1, x2, y2, TRUE );
  128.  
  129.     x1 += FRAME_WIDTH - 1 ;
  130.     y1 += FRAME_WIDTH - 1 ;
  131.     x2 -= FRAME_WIDTH - 1 ;
  132.     y2 -= FRAME_WIDTH - 1 ;
  133.     graph_box( x1, y1, x2, y2, FALSE );
  134. }
  135.  
  136. static    void    DisplayGrid( win, cx, cy, col )
  137. ViewWindow    *win ;
  138. int            cx, cy ;
  139. int            col ;
  140. {
  141.     int        x, y, size, grid ;
  142.     int        start, end, sx, sy ;
  143.  
  144.     ClearWin( win, BG_COLOR );
  145. #ifdef    X68K
  146.     ClearWin( win, TMP_COLOR );
  147. #endif
  148.  
  149.     grid = GridDisplay * ZoomPlus / ZoomMinus ;
  150.     if ( grid <= 2 )
  151.         return ;
  152.     size = ( win->h - FRAME_WIDTH * 2 ) / grid
  153.          + ( win->v - FRAME_WIDTH * 2 ) / grid + 4 ;
  154.     start = ( ( - win->h / 2 + FRAME_WIDTH ) * ZoomMinus / ZoomPlus ) + cx ;
  155.     start = start / GridDisplay * GridDisplay ;
  156.     end = ( ( win->h / 2 - FRAME_WIDTH ) * ZoomMinus / ZoomPlus ) + cx ;
  157.  
  158.     for( x = start ; x < end ; x += GridDisplay )
  159.     {
  160.         sx = ( ( x - cx ) * ZoomPlus / ZoomMinus ) + win->x + win->h / 2 ;
  161. /*        ClipLine( win, sx, win->y+FRAME_WIDTH, sx, win->y+win->v-FRAME_WIDTH-1, col );*/
  162.         if (win->x + FRAME_WIDTH <= sx && sx < win->x + win->h - FRAME_WIDTH) {
  163.             if (x == 0) {
  164.                 graph_line(sx, win->y+FRAME_WIDTH, sx, win->y+win->v-FRAME_WIDTH-1, col );
  165.             } else {
  166.                 graph_dashline(sx, win->y+FRAME_WIDTH, sx, win->y+win->v-FRAME_WIDTH-1, col );
  167.             }
  168.         }
  169.     }
  170.  
  171.     start = ( ( - win->v / 2 + FRAME_WIDTH ) * ZoomMinus / ZoomPlus ) + cy ;
  172.     start = start / GridDisplay * GridDisplay ;
  173.     end = ( ( win->v / 2 - FRAME_WIDTH ) * ZoomMinus / ZoomPlus ) + cy ;
  174.     for( y = start ; y < end ; y += GridDisplay )
  175.     {
  176.         sy = ( -( y - cy ) * ZoomPlus / ZoomMinus ) + win->y + win->v / 2 ;
  177. /*        ClipLine( win, win->x+FRAME_WIDTH, sy, win->x+win->h-FRAME_WIDTH-1, sy, col );*/
  178.         if (win->y + FRAME_WIDTH <= sy && sy < win->y + win->v - FRAME_WIDTH) {
  179.             if (y == 0) {
  180.                 graph_line(win->x+FRAME_WIDTH, sy, win->x+win->h-FRAME_WIDTH-1, sy, col );
  181.             } else {
  182.                 graph_dashline(win->x+FRAME_WIDTH, sy, win->x+win->h-FRAME_WIDTH-1, sy, col );
  183.             }
  184.         }
  185.     }
  186. }
  187.  
  188. static void ViewTempLine(int pos)
  189. {
  190.     int i;
  191.     int fxy, fyz, fzx;
  192.     int px1, px2, py1, py2, pz1, pz2;
  193.     px1 = tempedge[pos].px1;
  194.     py1 = tempedge[pos].py1;
  195.     pz1 = tempedge[pos].pz1;
  196.     px2 = tempedge[pos].px2;
  197.     py2 = tempedge[pos].py2;
  198.     pz2 = tempedge[pos].pz2;
  199.     fxy = fyz = fzx = TRUE;
  200.  
  201.     for (i = 0; i < pos; ++i) {
  202.         if (fxy) {
  203.             if ((tempedge[i].px1 == px1 && tempedge[i].py1 == py1
  204.               && tempedge[i].px2 == px2 && tempedge[i].py2 == py2)
  205.              || (tempedge[i].px1 == px2 && tempedge[i].py1 == py2
  206.               && tempedge[i].px2 == px1 && tempedge[i].py2 == py1)) {
  207.                 fxy = FALSE;
  208.             }
  209.         }
  210.         if (fyz) {
  211.             if ((tempedge[i].py1 == py1 && tempedge[i].pz1 == pz1
  212.               && tempedge[i].py2 == py2 && tempedge[i].pz2 == pz2)
  213.              || (tempedge[i].py1 == py2 && tempedge[i].pz1 == pz2
  214.               && tempedge[i].py2 == py1 && tempedge[i].pz2 == pz1)) {
  215.                 fyz = FALSE;
  216.             }
  217.         }
  218.         if (fzx) {
  219.             if ((tempedge[i].px1 == px1 && tempedge[i].pz1 == pz1
  220.               && tempedge[i].px2 == px2 && tempedge[i].pz2 == pz2)
  221.              || (tempedge[i].px1 == px2 && tempedge[i].pz1 == pz2
  222.               && tempedge[i].px2 == px1 && tempedge[i].pz2 == pz1)) {
  223.                 fzx = FALSE;
  224.             }
  225.         }
  226.         if (fxy == FALSE && fyz == FALSE && fzx == FALSE) {
  227.             return;
  228.         }
  229.     }
  230.     if (fxy && (ViewMode & VIEW_XY) != 0) {
  231.         ClipLine( &WinXY, px1+WinXY.offx, -py1+WinXY.offy,
  232.                           px2+WinXY.offx, -py2+WinXY.offy, CURSOR_COLOR );
  233.     }
  234.     if (fyz && (ViewMode & VIEW_YZ) != 0) {
  235.         ClipLine( &WinYZ, py1+WinYZ.offx, -pz1+WinYZ.offy,
  236.                           py2+WinYZ.offx, -pz2+WinYZ.offy, CURSOR_COLOR );
  237.     }
  238.     if (fzx && (ViewMode & VIEW_ZX) != 0) {
  239.         ClipLine( &WinZX, px1+WinZX.offx, -pz1+WinZX.offy,
  240.                           px2+WinZX.offx, -pz2+WinZX.offy, CURSOR_COLOR );
  241.     }
  242. }
  243.  
  244. static void ViewTempVertex(int pos)
  245. {
  246.     int i;
  247.     int fxy, fyz, fzx;
  248.     int px, py, pz;
  249.     px = tempvertex[pos].px;
  250.     py = tempvertex[pos].py;
  251.     pz = tempvertex[pos].pz;
  252.     fxy = (ViewMode & VIEW_XY) != 0;
  253.     fyz = (ViewMode & VIEW_YZ) != 0;
  254.     fzx = (ViewMode & VIEW_ZX) != 0;
  255.  
  256.     for (i = 0; i < pos; ++i) {
  257.         if (fxy && tempvertex[i].px == px && tempvertex[i].py == py) {
  258.             fxy = FALSE;
  259.         }
  260.         if (fyz && tempvertex[i].py == py && tempvertex[i].pz == pz) {
  261.             fyz = FALSE;
  262.         }
  263.         if (fzx && tempvertex[i].px == px && tempvertex[i].pz == pz) {
  264.             fzx = FALSE;
  265.         }
  266.         if (fxy == FALSE && fyz == FALSE && fzx == FALSE) {
  267.             return;
  268.         }
  269.     }
  270.     if (fxy) {
  271.         ClipBox( &WinXY,
  272.             px+WinXY.offx - VisibleVertex, - py+WinXY.offy - VisibleVertex,
  273.             px+WinXY.offx + VisibleVertex, - py+WinXY.offy + VisibleVertex, CURSOR_COLOR );
  274.     }
  275.     if (fyz) {
  276.         ClipBox( &WinYZ,
  277.             py+WinYZ.offx - VisibleVertex, - pz+WinYZ.offy - VisibleVertex,
  278.             py+WinYZ.offx + VisibleVertex, - pz+WinYZ.offy + VisibleVertex, CURSOR_COLOR );
  279.     }
  280.     if (fzx) {
  281.         ClipBox( &WinZX,
  282.             px+WinZX.offx - VisibleVertex, - pz+WinZX.offy - VisibleVertex,
  283.             px+WinZX.offx + VisibleVertex, - pz+WinZX.offy + VisibleVertex, CURSOR_COLOR );
  284.     }
  285. }
  286.  
  287. void ViewTempForWin(void)
  288. {
  289.     int i;
  290.     int ov;
  291.     int        pos1[3], pos2[3] ;
  292.     Vertex p1, p2;
  293.  
  294.     for (i = 0; i < tempedgecount; ++i) {
  295.         p1.x = tempedge[i].x1;p1.y = tempedge[i].y1;p1.z = tempedge[i].z1;
  296.         p2.x = tempedge[i].x2;p2.y = tempedge[i].y2;p2.z = tempedge[i].z2;
  297.         ToScreen( pos1, &p1 );
  298.         ToScreen( pos2, &p2 );
  299.         tempedge[i].px1 = pos1[0]; tempedge[i].py1 = pos1[1]; tempedge[i].pz1 = pos1[2];
  300.         tempedge[i].px2 = pos2[0]; tempedge[i].py2 = pos2[1]; tempedge[i].pz2 = pos2[2];
  301.         ViewTempLine(i);
  302.     }
  303.  
  304.     ov = VisibleVertex;
  305.     if (VisibleVertex < 1) VisibleVertex = 1;
  306.     for (i = 0; i < tempvertexcount; ++i) {
  307.         p1.x = tempvertex[i].x;
  308.         p1.y = tempvertex[i].y;
  309.         p1.z = tempvertex[i].z;
  310.         ToScreen( pos1, &p1 );
  311.         tempvertex[i].px = pos1[0];
  312.         tempvertex[i].py = pos1[1];
  313.         tempvertex[i].pz = pos1[2];
  314.         ViewTempVertex(i);
  315.     }
  316.     VisibleVertex = ov;
  317. }
  318.  
  319. void ViewTempForPers(void)
  320. {
  321.     int i;
  322.     int ov;
  323.     Vertex p1, p2;
  324.     if ( ( ViewMode & VIEW_PERS ) == 0) {
  325.         return;
  326.     }
  327.  
  328.     for (i = 0; i < tempedgecount; ++i) {
  329.         p1.x = tempedge[i].x1;p1.y = tempedge[i].y1;p1.z = tempedge[i].z1;
  330.         p2.x = tempedge[i].x2;p2.y = tempedge[i].y2;p2.z = tempedge[i].z2;
  331.         DrawLineForPers( &p1, &p2, CURSOR_COLOR);
  332.     }
  333.  
  334.     ov = VisibleVertex;
  335.     if (ov < 1) ov = 1;
  336.     for (i = 0; i < tempvertexcount; ++i) {
  337.         int    scr[2] ;
  338.         p1.x = tempvertex[i].x;
  339.         p1.y = tempvertex[i].y;
  340.         p1.z = tempvertex[i].z;
  341.         if (ToScreenPers( scr, &p1 )) {
  342.             ClipBox( &WinPers, scr[0] - ov, scr[1] - ov, scr[0] + ov, scr[1] + ov, CURSOR_COLOR );
  343.         }
  344.     }
  345. }
  346.  
  347.  
  348. static int AddTemp(Vertex *p1, Vertex *p2)
  349. {
  350.     int i;
  351.     for (i = 0; i < tempedgecount; ++i) {
  352.         if ((tempedge[i].x1 == p1->x
  353.           && tempedge[i].y1 == p1->y
  354.           && tempedge[i].z1 == p1->z
  355.           && tempedge[i].x2 == p2->x
  356.           && tempedge[i].y2 == p2->y
  357.           && tempedge[i].z2 == p2->z)
  358.          || (tempedge[i].x1 == p2->x
  359.           && tempedge[i].y1 == p2->y
  360.           && tempedge[i].z1 == p2->z
  361.           && tempedge[i].x2 == p1->x
  362.           && tempedge[i].y2 == p1->y
  363.           && tempedge[i].z2 == p1->z)) {
  364.             if (i != tempedgecount-1) {
  365.                 tempedge[i] = tempedge[tempedgecount-1];
  366.             }
  367.             tempedgecount--;
  368.             return -1;
  369.          }
  370.     }
  371.     if (tempedgecount < MAXTEMPLINE-1) {
  372.         tempedge[tempedgecount].x1 = p1->x;
  373.         tempedge[tempedgecount].y1 = p1->y;
  374.         tempedge[tempedgecount].z1 = p1->z;
  375.         tempedge[tempedgecount].x2 = p2->x;
  376.         tempedge[tempedgecount].y2 = p2->y;
  377.         tempedge[tempedgecount].z2 = p2->z;
  378.         tempedgecount++;
  379.         return tempedgecount-1;
  380.     }
  381.     return -1;
  382. }
  383.  
  384. static int AddTempVertex(Vertex *p1)
  385. {
  386.     int i;
  387.     for (i = 0; i < tempvertexcount; ++i) {
  388.         if (tempvertex[i].x == p1->x
  389.          && tempvertex[i].y == p1->y
  390.          && tempvertex[i].z == p1->z) {
  391.             if (i != tempvertexcount-1) {
  392.                 tempvertex[i] = tempvertex[tempvertexcount-1];
  393.             }
  394.             tempvertexcount--;
  395.             return -1;
  396.          }
  397.     }
  398.     if (tempvertexcount < MAXTEMPLINE-1) {
  399.         tempvertex[tempvertexcount].x = p1->x;
  400.         tempvertex[tempvertexcount].y = p1->y;
  401.         tempvertex[tempvertexcount].z = p1->z;
  402.         tempvertexcount++;
  403.         return tempvertexcount-1;
  404.     }
  405.     return -1;
  406. }
  407.  
  408. /*    ウインドウのクリア    */
  409. void    ViewClear( color )
  410. int        color ;
  411. {
  412.     int        savemstat ;
  413.  
  414.     if (color < 0) {
  415.         ViewTempForWin();
  416.         ViewTempForPers();
  417.         tempedgecount = 0;
  418.         tempvertexcount = 0;
  419.         if (viewbox_drawflag) {
  420.             ViewBox(&viewbox_p1, &viewbox_p2, viewbox_mat);
  421.             viewbox_drawflag = FALSE;
  422.         }
  423.         if (viewbox2d_drawflag) {
  424.             ViewBox2D(viewbox2d_x1, viewbox2d_y1, viewbox2d_x2, viewbox2d_y2);
  425.             viewbox2d_drawflag = FALSE;
  426.         }
  427.         return;
  428.     }
  429.  
  430.     savemstat = Mstat ;
  431.     if ( Mstat == ON )
  432.         ViewCursor( OFF );
  433.  
  434.     tempedgecount = 0;
  435.     tempvertexcount = 0;
  436.     viewbox_drawflag = FALSE;
  437.     viewbox2d_drawflag = FALSE;
  438.  
  439.     if ( TmpClear == FALSE && color == TMP_COLOR )
  440.     {
  441.         ViewFrame();
  442.         ViewLineAll( 0, 0, DISPLAY_X, DISPLAY_Y, TRUE );
  443.     }
  444.     else
  445.     {
  446.         if ( ViewMode & VIEW_XY )
  447.             ClearWin( &WinXY, color );
  448.         if ( ViewMode & VIEW_YZ )
  449.             ClearWin( &WinYZ, color );
  450.         if ( ViewMode & VIEW_ZX )
  451.             ClearWin( &WinZX, color );
  452.         if ( ViewMode & VIEW_PERS )
  453.             ClearWin( &WinPers, color );
  454.     }
  455.  
  456.     ViewCursor( savemstat );
  457. }
  458.  
  459. static    void    ClearWin( win, color )
  460. ViewWindow    *win ;
  461. int        color ;
  462. {
  463.     int        vx1, vy1, vx2, vy2 ;
  464.  
  465.     vx1 = win->x + FRAME_WIDTH ;
  466.     vy1 = win->y + FRAME_WIDTH ;
  467.     vx2 = win->x + win->h - FRAME_WIDTH - 1 ;
  468.     vy2 = win->y + win->v - FRAME_WIDTH - 1 ;
  469.  
  470.     if ( vx1 < ViewX1 )
  471.         vx1 = ViewX1 ;
  472.     if ( vy1 < ViewY1 )
  473.         vy1 = ViewY1 ;
  474.     if ( vx2 > ViewX2 )
  475.         vx2 = ViewX2 ;
  476.     if ( vy2 > ViewY2 )
  477.         vy2 = ViewY2 ;
  478.     if ( vx1 > vx2 || vy1 > vy2 )
  479.         return ;
  480.  
  481.     graph_fill( vx1, vy1, vx2, vy2, color );
  482. }
  483.  
  484. /*    全データ描画    */
  485. void    ViewLineAll( minx, miny, maxx, maxy, sw )
  486. int        minx, miny, maxx, maxy ;
  487. int        sw ;
  488. {
  489.     int        i, code, flag ;
  490.     int        vmode ;
  491.     int        pos[2][3] ;
  492.     int        vx1, vy1, vx2, vy2 ;
  493.     int        sflag ;
  494.     Polygon    *poly ;
  495.     int        savemstat ;
  496.  
  497.  
  498.     savemstat = Mstat ;
  499.     if ( Mstat == ON )
  500.         ViewCursor( OFF );
  501.  
  502.     vmode = ViewMode ;
  503.     flag = ViewIn( &WinXY, minx, miny, maxx, maxy ) ? VIEW_XY : 0 ;
  504.     flag |= ViewIn( &WinYZ, minx, miny, maxx, maxy ) ? VIEW_YZ : 0 ;
  505.     flag |= ViewIn( &WinZX, minx, miny, maxx, maxy ) ? VIEW_ZX : 0 ;
  506.     flag |= ViewIn( &WinPers, minx, miny, maxx, maxy ) ? VIEW_PERS : 0 ;
  507.     ViewMode &= flag ;
  508.  
  509.     vx1 = ViewX1 ;
  510.     vy1 = ViewY1 ;
  511.     vx2 = ViewX2 ;
  512.     vy2 = ViewY2 ;
  513.     ViewX1 = minx ;
  514.     ViewY1 = miny ;
  515.     ViewX2 = maxx ;
  516.     ViewY2 = maxy ;
  517.  
  518.     graph_buffer_start();
  519.  
  520.     if ( ViewMode & ( VIEW_XY | VIEW_YZ | VIEW_ZX ) )
  521.     {
  522.         if ( sw )
  523.         {
  524.             if ( ViewMode & VIEW_XY )
  525.                 DisplayGrid( &WinXY, Cx, Cy, GRID_COLOR );
  526.             if ( ViewMode & VIEW_YZ )
  527.                 DisplayGrid( &WinYZ, Cy, Cz, GRID_COLOR );
  528.             if ( ViewMode & VIEW_ZX )
  529.                 DisplayGrid( &WinZX, Cx, Cz, GRID_COLOR );
  530.         }
  531.  
  532.         sflag = FALSE ;
  533.  
  534.         if (InvisibleDraw) {
  535.             poly = BufferTop();
  536.             while( poly != NULL )
  537.             {
  538.                 if ( poly->mode & MODE_INVISIBLE) {
  539.                     code = INVISIBLE_COLOR ;
  540.                     ToScreen( pos[0], &poly->ver[0] );
  541.                     for( i = 1 ; i < poly->vers ; i++ )
  542.                     {
  543.                         ToScreen( pos[i&1], &poly->ver[i] );
  544.                         DrawLineForWin( pos[0], pos[1], code );
  545.                     }
  546.                     ToScreen( pos[i&1], &poly->ver[0] );
  547.                     DrawLineForWin( pos[0], pos[1], code );
  548.                 }
  549.                 poly = BufferNext( poly );
  550.             }
  551.         }
  552.         poly = BufferTop();
  553.         while( poly != NULL )
  554.         {
  555.             if ( poly->select == ON )
  556.                 sflag = TRUE ;
  557.             else if ( ( poly->mode & MODE_INVISIBLE ) == 0 )
  558.             {
  559.                 code = AttrData[poly->atr].code ;
  560.  
  561.                 ToScreen( pos[0], &poly->ver[0] );
  562.  
  563.                 for( i = 1 ; i < poly->vers ; i++ )
  564.                 {
  565.                     ToScreen( pos[i&1], &poly->ver[i] );
  566.                     DrawLineForWin( pos[0], pos[1], code );
  567.                 }
  568.                 ToScreen( pos[i&1], &poly->ver[0] );
  569.                 DrawLineForWin( pos[0], pos[1], code );
  570.                 if (VisibleVertex > 0) {
  571.                     DrawVertexWin( poly, code);
  572.                 }
  573.  
  574.             }
  575.             poly = BufferNext( poly );
  576.         }
  577.         if ( sflag )
  578.         {
  579.             poly = BufferTop();
  580.             while( poly != NULL )
  581.             {
  582.                 if ( poly->select == ON )
  583.                 {
  584.                     code = SELECT_COLOR ;
  585.                     ToScreen( pos[0], &poly->ver[0] );
  586.                     for( i = 1 ; i < poly->vers ; i++ )
  587.                     {
  588.                         ToScreen( pos[i&1], &poly->ver[i] );
  589.                         DrawLineForWin( pos[0], pos[1], code );
  590.                     }
  591.                     ToScreen( pos[i&1], &poly->ver[0] );
  592.                     DrawLineForWin( pos[0], pos[1], code );
  593.                     if (VisibleVertex > 0) {
  594.                         DrawVertexWin( poly, code);
  595.                     }
  596.                 }
  597.                 poly = BufferNext( poly );
  598.             }
  599.         }
  600.         ViewTempForWin();
  601.  
  602.         if (viewbox_drawflag) {
  603.             int oldview;
  604.             oldview = ViewMode;
  605.             ViewMode &= (VIEW_XY | VIEW_YZ | VIEW_ZX);
  606.             ViewBox(&viewbox_p1, &viewbox_p2, viewbox_mat);
  607.             ViewMode = oldview;
  608.             viewbox_drawflag = TRUE;
  609.         }
  610.     }
  611.     if ( ViewMode & VIEW_PERS )
  612.         ViewLinePersAll( sw );
  613.  
  614.     graph_buffer_end();
  615.  
  616.     ViewMode = vmode ;
  617.  
  618.     ViewX1 = vx1 ;
  619.     ViewY1 = vy1 ;
  620.     ViewX2 = vx2 ;
  621.     ViewY2 = vy2 ;
  622.  
  623.     ViewCursor( savemstat );
  624. }
  625.  
  626.  
  627. /*    全データ描画    */
  628. void    ViewLineSelectAll(void)
  629. {
  630.     int        i, code, flag ;
  631.     int        pos[2][3] ;
  632.     int        scr[2][2] ;
  633.     Polygon    *poly ;
  634.     int        savemstat ;
  635.  
  636.  
  637.     savemstat = Mstat ;
  638.     if ( Mstat == ON )
  639.         ViewCursor( OFF );
  640.  
  641.     graph_buffer_start();
  642.  
  643.     ViewTempForWin();
  644.     ViewTempForPers();
  645.     if (viewbox_drawflag) {
  646.         ViewBox(&viewbox_p1, &viewbox_p2, viewbox_mat);
  647.         viewbox_drawflag = TRUE;
  648.     }
  649.  
  650.     if ( ViewMode & ( VIEW_XY | VIEW_YZ | VIEW_ZX ) )
  651.     {
  652.         poly = BufferTop();
  653.         while( poly != NULL )
  654.         {
  655.             if ( poly->select == ON )
  656.             {
  657.                 code = SELECT_COLOR ;
  658.                 ToScreen( pos[0], &poly->ver[0] );
  659.                 for( i = 1 ; i < poly->vers ; i++ )
  660.                 {
  661.                     ToScreen( pos[i&1], &poly->ver[i] );
  662.                     DrawLineForWin( pos[0], pos[1], code );
  663.                 }
  664.                 ToScreen( pos[i&1], &poly->ver[0] );
  665.                 DrawLineForWin( pos[0], pos[1], code );
  666.                 if (VisibleVertex > 0) {
  667.                     DrawVertexWin( poly, code);
  668.                 }
  669.                 poly = BufferNext( poly );
  670.             }
  671.         }
  672.     }
  673.     if ( ViewMode & VIEW_PERS ) {
  674.         poly = BufferTop();
  675.         while( poly != NULL )
  676.         {
  677.             if ( poly->select == ON )
  678.             {
  679.                 int f1, f2;
  680.                 f2 = ToScreenPers( scr[0], &poly->ver[0] );
  681.                 for( i = 1 ; i < poly->vers ; i++ )
  682.                 {
  683.                     f1 = f2;
  684.                     f2 = ToScreenPers( scr[i&1], &poly->ver[i] );
  685.                     if (f1 && f2) {
  686.                         ClipLine( &WinPers, scr[0][0], scr[0][1],
  687.                                             scr[1][0], scr[1][1], SELECT_COLOR );
  688.                     }
  689.                 }
  690.                 if (f2 && ToScreenPers( scr[i&1], &poly->ver[0] )) {
  691.                     ClipLine( &WinPers, scr[0][0], scr[0][1], scr[1][0], scr[1][1], SELECT_COLOR );
  692.                 }
  693.                 if ( VisibleVertex > 0 )
  694.                     DrawVertexPers( poly, SELECT_COLOR );
  695.                 if ( VisibleVector )
  696.                     DrawVector( poly, SELECT_COLOR );
  697.                 if ( VisiblePolyVector )
  698.                     DrawPolyVector( poly, SELECT_COLOR );
  699.             }
  700.             poly = BufferNext( poly );
  701.         }
  702.     }
  703.  
  704.     ViewTempForWin();
  705.     ViewTempForPers();
  706.     if (viewbox_drawflag) {
  707.         ViewBox(&viewbox_p1, &viewbox_p2, viewbox_mat);
  708.         viewbox_drawflag = TRUE;
  709.     }
  710.  
  711.     graph_buffer_end();
  712.  
  713.     ViewCursor( savemstat );
  714. }
  715.  
  716.  
  717. static    int        ViewIn( win, minx, miny, maxx, maxy )
  718. ViewWindow    *win ;
  719. int        minx, miny, maxx, maxy ;
  720. {
  721.     return win->x <= maxx && minx < win->x+win->h && win->y <= maxy && miny < win->y+win->v ;
  722. }
  723.  
  724. void    ViewCurrent()
  725. {
  726.     int        i, code ;
  727.     int old_viewmode;
  728.     old_viewmode = ViewMode;
  729.  
  730.     if (DrawFrontOnlyFlag && ScreenFront(CurrentPoly->vec) == FALSE) {
  731.         ViewMode &= ~VIEW_PERS;
  732.     }
  733.     if ( CurrentPoly->select )
  734.         code = SELECT_COLOR ;
  735.     else
  736.         code = AttrData[CurrentPoly->atr].code ;
  737.  
  738.     graph_buffer_start();
  739.  
  740.     for( i = 0 ; i < CurrentPoly->vers - 1 ; i++ )
  741.         ViewLine3D( &CurrentPoly->ver[i], &CurrentPoly->ver[i+1], code );
  742.     ViewLine3D( &CurrentPoly->ver[i], &CurrentPoly->ver[0], code );
  743.     if ( VisibleVertex > 0 ) {
  744.         DrawVertexWin( CurrentPoly, code );
  745.         if (ViewMode & VIEW_PERS) {
  746.             DrawVertexPers( CurrentPoly, code );
  747.         }
  748.     }
  749.     if ( VisibleVector )
  750.         DrawVector( CurrentPoly, code );
  751.     if ( VisiblePolyVector )
  752.         DrawPolyVector( CurrentPoly, code);
  753.     if ( VisibleVector )
  754.         DrawVector( CurrentPoly, code );
  755.     if ( VisiblePolyVector )
  756.         DrawPolyVector( CurrentPoly, code);
  757.     graph_buffer_end();
  758.     ViewMode = old_viewmode;
  759.  
  760. }
  761.  
  762. /*    直線描画    */
  763. void    ViewLine3D( p1, p2, color )
  764. Vertex    *p1, *p2 ;
  765. int        color ;
  766. {
  767.     int        pos1[3], pos2[3] ;
  768.     int        pos;
  769.  
  770.     if (p1->x == p2->x && p1->y == p2->y && p1->z == p2->z) {
  771.         return;
  772.     }
  773.     ToScreen( pos1, p1 );
  774.     ToScreen( pos2, p2 );
  775.     if (color == CURSOR_COLOR) {
  776.         if ((pos = AddTemp(p1, p2)) < 0) {
  777.             pos = tempedgecount;
  778.         }
  779.         tempedge[pos].px1 = pos1[0]; tempedge[pos].py1 = pos1[1]; tempedge[pos].pz1 = pos1[2];
  780.         tempedge[pos].px2 = pos2[0]; tempedge[pos].py2 = pos2[1]; tempedge[pos].pz2 = pos2[2];
  781.         ViewTempLine(pos);
  782.     } else {
  783.         DrawLineForWin( pos1, pos2, color );
  784.     }
  785.     DrawLineForPers( p1, p2, color );
  786. }
  787.  
  788. /*    頂点描画    */
  789. void    ViewVertex(Vertex *p1, int color)
  790. {
  791.     int        pos1[3];
  792.     int        scr[2];
  793.     int        pos;
  794.     int        ov;
  795.  
  796.     ToScreen( pos1, p1 );
  797.  
  798.     ov = VisibleVertex;
  799.     if (VisibleVertex < 1) VisibleVertex = 1;
  800.  
  801.     if (color == CURSOR_COLOR) {
  802.         if ((pos = AddTempVertex(p1)) < 0) {
  803.             pos = tempvertexcount;
  804.         }
  805.         tempvertex[pos].px = pos1[0];
  806.         tempvertex[pos].py = pos1[1];
  807.         tempvertex[pos].pz = pos1[2];
  808.         ViewTempVertex(pos);
  809.     } else {
  810.         if ( ViewMode & VIEW_XY )
  811.         {
  812.             ClipBox( &WinXY,
  813.                 pos1[0]+WinXY.offx - VisibleVertex, - pos1[1]+WinXY.offy - VisibleVertex,
  814.                 pos1[0]+WinXY.offx + VisibleVertex, - pos1[1]+WinXY.offy + VisibleVertex,color);
  815.         }
  816.         if ( ViewMode & VIEW_YZ )
  817.         {
  818.             ClipBox( &WinYZ,
  819.                 pos1[1]+WinYZ.offx - VisibleVertex, - pos1[2]+WinYZ.offy - VisibleVertex,
  820.                 pos1[1]+WinYZ.offx + VisibleVertex, - pos1[2]+WinYZ.offy + VisibleVertex, color );
  821.         }
  822.         if ( ViewMode & VIEW_ZX )
  823.         {
  824.             ClipBox( &WinZX,
  825.                 pos1[0]+WinZX.offx - VisibleVertex, - pos1[2]+WinZX.offy - VisibleVertex,
  826.                 pos1[0]+WinZX.offx + VisibleVertex, - pos1[2]+WinZX.offy + VisibleVertex, color);
  827.         }
  828.     }
  829.     if ((ViewMode & VIEW_PERS ) && ToScreenPers( scr, p1 )) {
  830.         ClipBox( &WinPers,
  831.             scr[0] - VisibleVertex, scr[1] - VisibleVertex,
  832.             scr[0] + VisibleVertex, scr[1] + VisibleVertex, color );
  833.     }
  834.     VisibleVertex = ov;
  835. }
  836.  
  837.  
  838. /*    透視図描画    */
  839. void    ViewLinePersAll( sw )
  840. int        sw ;
  841. {
  842.     int        i, code ;
  843.     int        scr[2][2] ;
  844.     Polygon    *poly ;
  845.     int        savemstat ;
  846.     int        sflag ;
  847.  
  848.     if ((ViewMode & VIEW_PERS) == 0) {
  849.         return;
  850.     }
  851.  
  852.     savemstat = PersMstat ;
  853.     if ( PersMstat != PERS_CURSOR_OFF )
  854.         ViewCursorPers( PERS_CURSOR_OFF );
  855.  
  856.     graph_buffer_start();
  857.  
  858.     if ( sw )
  859.     {
  860.         if ( ViewMode & VIEW_PERS )
  861.         {
  862.             ClearWin( &WinPers, BG_COLOR );
  863. #ifdef    X68K
  864.             ClearWin( &WinPers, TMP_COLOR );
  865. #endif
  866. #ifdef    PC98
  867. /*            ClearWin( &WinPers, 16 );*/
  868. #endif
  869.         }
  870.     }
  871.  
  872.     if (InvisibleDraw)
  873.     {
  874.         poly = BufferTop();
  875.         while( poly != NULL )
  876.         {
  877.             if ( poly->mode & MODE_INVISIBLE
  878.              && (!DrawFrontOnlyFlag || ScreenFront(poly->vec)))
  879.             {
  880.                 int f1, f2;
  881.                 f2 = ToScreenPers( scr[0], &poly->ver[0] );
  882.                 for( i = 1 ; i < poly->vers ; i++ )
  883.                 {
  884.                     f1 = f2;
  885.                     f2 = ToScreenPers( scr[i&1], &poly->ver[i] );
  886.                     if (f1 && f2) {
  887.                         ClipLine( &WinPers, scr[0][0], scr[0][1],
  888.                                             scr[1][0], scr[1][1], INVISIBLE_COLOR );
  889.                     }
  890.                 }
  891.                 if (f2 && ToScreenPers( scr[i&1], &poly->ver[0] )) {
  892.                     ClipLine( &WinPers, scr[0][0], scr[0][1], scr[1][0], scr[1][1], INVISIBLE_COLOR );
  893.                 }
  894.             }
  895.             poly = BufferNext( poly );
  896.         }
  897.     }
  898.  
  899.     sflag = FALSE ;
  900.     poly = BufferTop();
  901.     while( poly != NULL )
  902.     {
  903.         if ( poly->select == ON )
  904.         {
  905.             sflag = TRUE ;
  906.         }
  907.         else if ( (poly->mode & MODE_INVISIBLE ) == 0
  908.          && (!DrawFrontOnlyFlag || ScreenFront(poly->vec)))
  909.         {
  910.             int f1, f2;
  911.             code = AttrData[poly->atr].code ;
  912.  
  913.             f2 = ToScreenPers( scr[0], &poly->ver[0] );
  914.             for( i = 1 ; i < poly->vers ; i++ )
  915.             {
  916.                 f1 = f2;
  917.                 f2 = ToScreenPers( scr[i&1], &poly->ver[i] );
  918.                 if (f1 && f2) {
  919.                     ClipLine( &WinPers, scr[0][0], scr[0][1],
  920.                                         scr[1][0], scr[1][1], code );
  921.                 }
  922.             }
  923.             if (f2 && ToScreenPers( scr[i&1], &poly->ver[0] )) {
  924.                 ClipLine( &WinPers, scr[0][0], scr[0][1], scr[1][0], scr[1][1], code );
  925.             }
  926.             if ( VisibleVertex > 0 )
  927.                 DrawVertexPers( poly, code );
  928.             if ( VisibleVector )
  929.                 DrawVector( poly, code );
  930.             if ( VisiblePolyVector )
  931.                 DrawPolyVector( poly, code );
  932.         }
  933.         poly = BufferNext( poly );
  934.     }
  935.  
  936.     if ( sflag )
  937.     {
  938.         poly = BufferTop();
  939.         while( poly != NULL )
  940.         {
  941.             if ( poly->select == ON
  942.              && (!DrawFrontOnlyFlag || ScreenFront(poly->vec) ))
  943.             {
  944.                 int f1, f2;
  945.                 f2 = ToScreenPers( scr[0], &poly->ver[0] );
  946.                 for( i = 1 ; i < poly->vers ; i++ )
  947.                 {
  948.                     f1 = f2;
  949.                     f2 = ToScreenPers( scr[i&1], &poly->ver[i] );
  950.                     if (f1 && f2) {
  951.                         ClipLine( &WinPers, scr[0][0], scr[0][1],
  952.                                             scr[1][0], scr[1][1], SELECT_COLOR );
  953.                     }
  954.                 }
  955.                 if (f2 && ToScreenPers( scr[i&1], &poly->ver[0] )) {
  956.                     ClipLine( &WinPers, scr[0][0], scr[0][1], scr[1][0], scr[1][1], SELECT_COLOR );
  957.                 }
  958.                 if ( VisibleVertex > 0 )
  959.                     DrawVertexPers( poly, SELECT_COLOR );
  960.                 if ( VisibleVector )
  961.                     DrawVector( poly, SELECT_COLOR );
  962.                 if ( VisiblePolyVector )
  963.                     DrawPolyVector( poly, SELECT_COLOR );
  964.  
  965.             }
  966.             poly = BufferNext( poly );
  967.         }
  968.     }
  969.  
  970.     ViewTempForPers();
  971.  
  972.     if (viewbox_drawflag) {
  973.         int oldview;
  974.         oldview = ViewMode;
  975.         ViewMode &= VIEW_PERS;
  976.         ViewBox(&viewbox_p1, &viewbox_p2, viewbox_mat);
  977.         ViewMode = oldview;
  978.         viewbox_drawflag = TRUE;
  979.     }
  980.     if (viewbox2d_drawflag) {
  981.         ViewBox2D(viewbox2d_x1, viewbox2d_y1, viewbox2d_x2, viewbox2d_y2);
  982.         viewbox2d_drawflag = TRUE;
  983.     }
  984.  
  985.     graph_buffer_end();
  986.  
  987.     ViewCursorPers( savemstat );
  988. }
  989.  
  990. static    void    DrawVertexWin( poly, code )
  991. Polygon    *poly ;
  992. int        code ;
  993. {
  994.     int        i ;
  995.     int        pos[3] ;
  996.  
  997.     for( i = 0 ; i < poly->vers ; i++ )
  998.     {
  999.         ToScreen( pos, &poly->ver[i] );
  1000.         if ( ViewMode & VIEW_XY )
  1001.         {
  1002.             ClipBox( &WinXY,
  1003.                 pos[0]+WinXY.offx - VisibleVertex, - pos[1]+WinXY.offy - VisibleVertex,
  1004.                 pos[0]+WinXY.offx + VisibleVertex, - pos[1]+WinXY.offy + VisibleVertex,code);
  1005.         }
  1006.         if ( ViewMode & VIEW_YZ )
  1007.         {
  1008.             ClipBox( &WinYZ,
  1009.                 pos[1]+WinYZ.offx - VisibleVertex, - pos[2]+WinYZ.offy - VisibleVertex,
  1010.                 pos[1]+WinYZ.offx + VisibleVertex, - pos[2]+WinYZ.offy + VisibleVertex, code );
  1011.         }
  1012.         if ( ViewMode & VIEW_ZX )
  1013.         {
  1014.             ClipBox( &WinZX,
  1015.                 pos[0]+WinZX.offx - VisibleVertex, - pos[2]+WinZX.offy - VisibleVertex,
  1016.                 pos[0]+WinZX.offx + VisibleVertex, - pos[2]+WinZX.offy + VisibleVertex, code );
  1017.         }
  1018.     }
  1019. }
  1020.  
  1021. static    void    DrawVertexPers( poly, code )
  1022. Polygon    *poly ;
  1023. int        code ;
  1024. {
  1025.     int        i ;
  1026.     int        scr[2] ;
  1027.  
  1028.     if ((!DrawFrontOnlyFlag || ScreenFront(poly->vec)) == FALSE) {
  1029.         return;
  1030.     }
  1031.     for( i = 0 ; i < poly->vers ; i++ )
  1032.     {
  1033.         if (ToScreenPers( scr, &poly->ver[i] )) {
  1034.             ClipBox( &WinPers,
  1035.                     scr[0] - VisibleVertex, scr[1] - VisibleVertex,
  1036.                     scr[0] + VisibleVertex, scr[1] + VisibleVertex, code);
  1037.         }
  1038.     }
  1039. }
  1040.  
  1041. static    void    DrawVector( poly, code )
  1042. Polygon    *poly ;
  1043. int        code ;
  1044. {
  1045.     int        i ;
  1046.     int        scr[2][2] ;
  1047.     Vertex    nvec ;
  1048.  
  1049.     if ( (poly->type & POLY_SHADE)
  1050.      && (!DrawFrontOnlyFlag || ScreenFront(poly->vec)) )
  1051.     {
  1052.         for( i = 0 ; i < poly->vers ; i++ )
  1053.         {
  1054.             if (ToScreenPers( scr[0], &poly->ver[i] )) {
  1055.                 nvec.x = poly->ver[i].x + poly->ver[i].vx * VisibleVector / 256 ;
  1056.                 nvec.y = poly->ver[i].y + poly->ver[i].vy * VisibleVector / 256 ;
  1057.                 nvec.z = poly->ver[i].z + poly->ver[i].vz * VisibleVector / 256 ;
  1058.                 if (ToScreenPers( scr[1], &nvec )) {
  1059.                     ClipLine( &WinPers, scr[0][0], scr[0][1], scr[1][0], scr[1][1], code );
  1060.                 }
  1061.             }
  1062.         }
  1063.     }
  1064. }
  1065.  
  1066. static    void    DrawPolyVector( poly, code )
  1067. Polygon    *poly ;
  1068. int        code ;
  1069. {
  1070.     int        i ;
  1071.     int        scr[2][2] ;
  1072.     int        add[3];
  1073.     Vertex    nvec ;
  1074.  
  1075.     add[0] = poly->vec[0] * VisiblePolyVector / 256;
  1076.     add[1] = poly->vec[1] * VisiblePolyVector / 256;
  1077.     add[2] = poly->vec[2] * VisiblePolyVector / 256;
  1078.  
  1079.     if (!DrawFrontOnlyFlag || ScreenFront(poly->vec) )
  1080.     {
  1081.         for( i = 0 ; i < poly->vers ; i++ )
  1082.         {
  1083.             if (ToScreenPers( scr[0], &poly->ver[i] )) {
  1084.                 nvec.x = poly->ver[i].x + add[0] ;
  1085.                 nvec.y = poly->ver[i].y + add[1] ;
  1086.                 nvec.z = poly->ver[i].z + add[2] ;
  1087.                 if (ToScreenPers( scr[1], &nvec )) {
  1088.                     ClipLine( &WinPers, scr[0][0], scr[0][1], scr[1][0], scr[1][1], code );
  1089.                 }
  1090.             }
  1091.         }
  1092.     }
  1093. }
  1094.  
  1095. /*    透視図のみ表示    */
  1096. void    ViewLinePers( p1, p2, color )
  1097. Vertex    *p1, *p2 ;
  1098. int        color ;
  1099. {
  1100.     DrawLineForPers( p1, p2, color );
  1101. }
  1102.  
  1103. void    DrawLineForWin( pos1, pos2, code )
  1104. int        pos1[3], pos2[3] ;
  1105. int        code ;
  1106. {
  1107.     if ( ViewMode & VIEW_XY )
  1108.     {
  1109.         ClipLine( &WinXY, pos1[0]+WinXY.offx, - pos1[1]+WinXY.offy,
  1110.                             pos2[0]+WinXY.offx, - pos2[1]+WinXY.offy, code );
  1111.     }
  1112.     if ( ViewMode & VIEW_YZ )
  1113.     {
  1114.         ClipLine( &WinYZ, pos1[1]+WinYZ.offx, - pos1[2]+WinYZ.offy,
  1115.                             pos2[1]+WinYZ.offx, - pos2[2]+WinYZ.offy, code );
  1116.     }
  1117.     if ( ViewMode & VIEW_ZX )
  1118.     {
  1119.         ClipLine( &WinZX, pos1[0]+WinZX.offx, - pos1[2]+WinZX.offy,
  1120.                             pos2[0]+WinZX.offx, - pos2[2]+WinZX.offy, code );
  1121.     }
  1122. }
  1123.  
  1124. void    DrawLineForPers( p1, p2, color )
  1125. Vertex    *p1, *p2 ;
  1126. int        color ;
  1127. {
  1128.     int        sp1[2], sp2[2] ;
  1129.  
  1130.     if ( ( ViewMode & VIEW_PERS ) && ToScreenPers( sp1, p1 ) && ToScreenPers( sp2, p2 ) )
  1131.         ClipLine( &WinPers, sp1[0], sp1[1], sp2[0], sp2[1], color );
  1132.  
  1133. }
  1134.  
  1135. /*    クリッピング    */
  1136. void    ClipLine( win, x1, y1, x2, y2, color )
  1137. ViewWindow    *win ;
  1138. int        x1, y1, x2, y2 ;
  1139. int        color ;
  1140. {
  1141.     int        vx1, vy1, vx2, vy2 ;
  1142.  
  1143.     vx1 = win->x + FRAME_WIDTH ;
  1144.     vy1 = win->y + FRAME_WIDTH ;
  1145.     vx2 = win->x + win->h - (FRAME_WIDTH+1) ;
  1146.     vy2 = win->y + win->v - (FRAME_WIDTH+1) ;
  1147.  
  1148.     if ( vx1 < ViewX1 )
  1149.         vx1 = ViewX1 ;
  1150.     if ( vy1 < ViewY1 )
  1151.         vy1 = ViewY1 ;
  1152.     if ( vx2 > ViewX2 )
  1153.         vx2 = ViewX2 ;
  1154.     if ( vy2 > ViewY2 )
  1155.         vy2 = ViewY2 ;
  1156.     if ( vx1 > vx2 || vy1 > vy2 )
  1157.         return ;
  1158.  
  1159.     if ( y1 > y2 )
  1160.     {
  1161.         swap( x1, x2 );
  1162.         swap( y1, y2 );
  1163.     }
  1164.     if ( y2 < vy1 || vy2 < y1 )
  1165.         return ;
  1166.     if ( y1 < vy1 )
  1167.     {
  1168.         x1 = ( x1 - x2 ) * ( vy1 - y2 ) / ( y1 - y2 ) + x2 ;
  1169.         y1 = vy1 ;
  1170.     }
  1171.     if ( vy2 < y2 )
  1172.     {
  1173.         x2 = ( x2 - x1 ) * ( vy2 - y1 ) / ( y2 - y1 ) + x1 ;
  1174.         y2 = vy2 ;
  1175.     }
  1176.  
  1177.     if ( x1 > x2 )
  1178.     {
  1179.         swap( x1, x2 );
  1180.         swap( y1, y2 );
  1181.     }
  1182.     if ( x2 < vx1 || vx2 < x1 )
  1183.         return ;
  1184.     if ( x1 < vx1 )
  1185.     {
  1186.         y1 = ( y1 - y2 ) * ( vx1 - x2 ) / ( x1 - x2 ) + y2 ;
  1187.         x1 = vx1 ;
  1188.     }
  1189.     if ( vx2 < x2 )
  1190.     {
  1191.         y2 = ( y2 - y1 ) * ( vx2 - x1 ) / ( x2 - x1 ) + y1 ;
  1192.         x2 = vx2 ;
  1193.     }
  1194.  
  1195.     graph_line( x1, y1, x2, y2, color );
  1196. }
  1197.  
  1198. /*    透視図に表示    */
  1199. void    ViewLine2D( x1, y1, x2, y2, color )
  1200. int        x1, y1, x2, y2 ;
  1201. int        color ;
  1202. {
  1203.     x1 =   ((x1 * WinPers.h) >> CURSOR_2D_SHIFT) + WinPers.x + WinPers.h / 2 ;
  1204.     y1 = - ((y1 * WinPers.h) >> CURSOR_2D_SHIFT) + WinPers.y + WinPers.v / 2 ;
  1205.     x2 =   ((x2 * WinPers.h) >> CURSOR_2D_SHIFT) + WinPers.x + WinPers.h / 2 ;
  1206.     y2 = - ((y2 * WinPers.h) >> CURSOR_2D_SHIFT) + WinPers.y + WinPers.v / 2 ;
  1207.     ClipLine( &WinPers, x1, y1, x2, y2, color );
  1208. }
  1209.  
  1210.  
  1211. void    DrawBoxForWin( pos, code )
  1212. int        pos[3];
  1213. int        code ;
  1214. {
  1215.     if (VisibleVertex <= 0) {
  1216.         return;
  1217.     }
  1218.     if ( ViewMode & VIEW_XY )
  1219.     {
  1220.         ClipBox( &WinXY,
  1221.                 pos[0]+WinXY.offx - VisibleVertex, - pos[1]+WinXY.offy - VisibleVertex,
  1222.                 pos[0]+WinXY.offx + VisibleVertex, - pos[1]+WinXY.offy + VisibleVertex,code);
  1223.     }
  1224.     if ( ViewMode & VIEW_YZ )
  1225.     {
  1226.         ClipBox( &WinYZ,
  1227.                 pos[1]+WinYZ.offx - VisibleVertex, - pos[2]+WinYZ.offy - VisibleVertex,
  1228.                 pos[1]+WinYZ.offx + VisibleVertex, - pos[2]+WinYZ.offy + VisibleVertex, code );
  1229.     }
  1230.     if ( ViewMode & VIEW_ZX )
  1231.     {
  1232.         ClipBox( &WinZX,
  1233.                 pos[0]+WinZX.offx - VisibleVertex, - pos[2]+WinZX.offy - VisibleVertex,
  1234.                 pos[0]+WinZX.offx + VisibleVertex, - pos[2]+WinZX.offy + VisibleVertex, code );
  1235.     }
  1236. }
  1237.  
  1238. void    DrawBoxForPers( p, color )
  1239. Vertex    *p ;
  1240. int        color ;
  1241. {
  1242.     if (VisibleVertex <= 0) {
  1243.         return;
  1244.     }
  1245.     if ( ViewMode & VIEW_PERS ) {
  1246.         int        sp[2];
  1247.         if (ToScreenPers( sp, p ))
  1248.             ClipBox( &WinPers,
  1249.                     sp[0] - VisibleVertex, sp[1] - VisibleVertex,
  1250.                     sp[0] + VisibleVertex, sp[1] + VisibleVertex, color );
  1251.     }
  1252. }
  1253.  
  1254. /*    クリッピング    */
  1255. void    ClipBox( win, x1, y1, x2, y2, color )
  1256. ViewWindow    *win ;
  1257. int        x1, y1, x2, y2 ;
  1258. int        color ;
  1259. {
  1260.     int        vx1, vy1, vx2, vy2 ;
  1261.  
  1262.     vx1 = win->x + FRAME_WIDTH ;
  1263.     vy1 = win->y + FRAME_WIDTH ;
  1264.     vx2 = win->x + win->h - (FRAME_WIDTH+1) ;
  1265.     vy2 = win->y + win->v - (FRAME_WIDTH+1) ;
  1266.  
  1267.     if ( vx1 < ViewX1 )
  1268.         vx1 = ViewX1 ;
  1269.     if ( vy1 < ViewY1 )
  1270.         vy1 = ViewY1 ;
  1271.     if ( vx2 > ViewX2 )
  1272.         vx2 = ViewX2 ;
  1273.     if ( vy2 > ViewY2 )
  1274.         vy2 = ViewY2 ;
  1275.     if ( vx1 > vx2 || vy1 > vy2 )
  1276.         return ;
  1277.  
  1278.     if (x1 < vx1 || x2 > vx2 || y1 < vy1 || y2 > vy2) {
  1279.         return;
  1280.     }
  1281.     graph_fill( x1, y1, x2, y2, color );
  1282. /*
  1283.     graph_line(x1, y1, x2, y1, color);
  1284.     graph_line(x2, y1, x2, y2, color);
  1285.     graph_line(x2, y2, x1, y2, color);
  1286.     graph_line(x1, y2, x1, y1, color);
  1287. */
  1288. }
  1289.  
  1290.  
  1291.