home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MACRO / CREATED.M < prev    next >
Text File  |  1996-07-10  |  13KB  |  644 lines

  1. var private const    Tosha_pos = 1;
  2. //
  3. //    ポリゴンの作成
  4. //
  5. function CreatePolygon()
  6. {
  7.     var    key, vers, i;
  8.     var    prev, cur0, cur1, cur2, temp, temp2;
  9.     var    pick, draw_flag = ON;
  10.     var    pos[3];
  11.     var    tosha_mode = OFF;
  12.     var    prev_change, prev_sel;
  13.  
  14.     PushMenu();
  15.     Status_org = Status_title;
  16.     ClearStatus();
  17.     MenuPosition( Menu( " 動作設定(&S)",
  18.             "自動平面投射    C",    ToshaChange, Check_Toshaflag,
  19.             "------------",        SEPARATE_MENU,
  20.             "作成中止        ESC",    MenuQuit
  21.         ), Menu_Title );
  22.  
  23.     Status_title[0] = "【多角形作成中】";
  24.     if( tosha_flag == ON )
  25.         Status_title[Tosha_pos] = "平面投射:自動";
  26.     else
  27.         Status_title[Tosha_pos] = "平面投射:手動";
  28.     DrawStatus();
  29.  
  30.     quit_flag = FALSE;
  31.  
  32.     prev_sel = Select();
  33.     prev = Cursor();
  34.     cur0 = prev;
  35.     cur = prev ;
  36.     pick = cur;
  37.     fix_vertex = cur;
  38.     PolySetVertex( cur, 0 );
  39.     vers = 0 ;
  40.     input_flag = OFF;
  41.     prev_change = -1;
  42.     while( TRUE )
  43.     {
  44.         if( draw_flag == ON )
  45.         {
  46.             DrawLine( cur, prev );
  47.             if( vers > 0 )
  48.                 DrawLine( cur, cur0 );
  49.         }
  50.         key = WaitEvent();
  51.         if( key )
  52.             input_flag = ON;
  53.         if( ( ShiftStat() & 1 ) == 1 )
  54.         {
  55.             cur = Cursor();
  56.             TrimCursor( fix_vertex, MouseWindow());
  57.             Cursor( cur );
  58.         }
  59.         else
  60.             cur = Cursor();
  61.         if((tosha_mode == ON ) & ( tosha_flag == ON ) & ( pick != cur ))
  62.         {
  63.             cur = PolyPlane( cur, MouseWindow(),
  64.                     pos[0], pos[1], pos[2] );
  65.             Cursor( cur );
  66.         }
  67.         key = KeyCode();
  68.         if ( input_flag | key == INPUT_KEY )
  69.         {
  70.             if (( cur == prev ) | ( cur == PolyGetVertex( 0 )))
  71.             {
  72.                 vers++;
  73.                 break ;
  74.             }
  75.             else
  76.             {
  77.                 if(( tosha_mode == ON ) & ( tosha_flag == ON ))
  78.                 {
  79.                     temp = unit((Position(cur)-Position(pos[0]))*(Position(pos[0])-Position(pos[1])));
  80.                     temp2 = unit((Position(PolyPlane(cur, MouseWindow(), pos[0], pos[1], pos[2]))-Position(pos[0]))*(Position(pos[0])-Position(pos[1])));
  81.                 }
  82.                 else
  83.                 {
  84.                     temp = vector(0,0,1);
  85.                     temp2 = temp;
  86.                 }
  87.                 if( abs(temp.temp2) < 0.999 )
  88.                 {
  89.                     Warning();
  90.                     Message( "点が平面上にありません\n" );
  91.                 }
  92.                 else
  93.                 {
  94.                     Cursor( cur );
  95.                     if( cur != pick )
  96.                     {
  97.                         if( vers > 0 )
  98.                         {
  99.                             DrawLine( pick, prev );
  100.                             DrawLine( cur, prev );
  101.                             DrawLine( pick, cur );
  102.                         }
  103.                         else
  104.                             DrawLine( pick, cur );
  105.                     }
  106.                     vers ++ ;
  107.                     PolySetVertex( cur, vers );
  108.                     prev = cur;
  109.                     fix_vertex = cur;
  110.                     if( vers == (MAXVERTEX-1) )
  111.                     {
  112.                         Warning();
  113.                         if( MESSAGE == ON )
  114.                             Message( "一つの面にこれ以上の点を作ることができません\n"
  115.                                 +"すでに確定された点で面を作成します" );
  116.                         vers++;
  117.                         break;
  118.                     }
  119.                     if(( vers >= 2 ) & ( tosha_mode == OFF ))
  120.                     {
  121.                         pos[0] = PolyGetVertex( 0 );
  122.                         pos[1] = PolyGetVertex( 1 );
  123.                         temp = Position( pos[1] )- Position( pos[0] );
  124.                         if( abs(temp*(Position(cur)- Position(pos[0]))) > 0.00001 )
  125.                         {
  126.                             pos[2] = cur;
  127.                             tosha_mode = ON;
  128.                         }
  129.                     }
  130.                 }
  131.             }
  132.         }
  133.         else if( key == ESC | quit_flag == TRUE )
  134.         {
  135.             PopandClear( OVERWRITE );
  136.             return;
  137.         }
  138.         else if ( key == BS )
  139.         {
  140.             if ( vers == 0 )
  141.             {
  142.                 PopandClear( OVERWRITE );
  143.                 return ;
  144.             }
  145.             else
  146.             {
  147.                 if( cur == prev )
  148.                 {
  149.                     prev_change = vers -1;
  150.                     vers --;
  151.                 }
  152.                 else
  153.                 {
  154.                     cur = PolyGetVertex( vers );
  155.                     prev_change = vers-1;
  156.                     vers --;
  157.                 }
  158.                 if( vers < 2 )
  159.                     tosha_mode = OFF;
  160.             }
  161.         }
  162.         else if( ( key == 'p' ) & ( tosha_mode == ON ))
  163.         {
  164.             cur = PolyPlane( cur, MouseWindow(),
  165.                     pos[0], pos[1], pos[2] );
  166.             Cursor( cur );
  167.         }
  168.         else if( key == 'c' )
  169.             ToshaChange();
  170.         else
  171.             KeyProcess( key );
  172.         if( ((key!=0 ) & (key != INPUT_KEY)) | ( pick != Cursor()) )
  173.         {
  174.             draw_flag = ON;
  175.             DrawLine( pick, prev );
  176.             if(( prev_change > 0 ) | ( Cursor() != cur ))
  177.             {
  178.                 Cursor( cur );
  179.                 DrawLine( cur, PolyGetVertex( prev_change ));
  180.             }
  181.             if( vers == 0 )
  182.             {
  183.                 if( prev_change >= 0 )
  184.                     DrawLine( pick, cur0 );
  185.             }
  186.             else if( vers == 1 )
  187.             {
  188.                 if( pick != prev )
  189.                     DrawLine( pick, cur0 );
  190.             }
  191.             else
  192.                 DrawLine( pick, cur0 );
  193.         }
  194.         else
  195.             draw_flag = OFF;
  196.         if( prev_change >= 0 )
  197.         {
  198.             prev = PolyGetVertex( prev_change );
  199.             fix_vertex = prev;
  200.         }
  201.         prev_change = -1;
  202.         pick = Cursor();
  203.         input_flag = OFF;
  204.     }
  205.     Clear( OVERWRITE );
  206.     if ( vers >= 3 )
  207.     {
  208.         PolyVertexs( vers );
  209.         PolyType( POLY_SIMPLE );
  210.         PolyAttr( AttrCurrent() );
  211.         PolyObj( ObjCurrent() );
  212.         PolyAppend( TRUE );
  213.         if( SelectPolygons(prev_sel) != 0 )
  214.         {
  215.             SelectAllFalse();
  216.             Select(prev_sel^Select());
  217.         }
  218.         ViewCursor( OFF );
  219.         DrawCurrent( TRUE );
  220.         ViewCursor( ON );
  221.         UpdateObject();
  222.     }
  223.     else
  224.     {
  225.         Warning();
  226.         if( MESSAGE == ON )
  227.             Message( "3点以上点が指定されていないので、\n"
  228.                 +"面が生成できませんでした" );
  229.     }
  230.     PopMenu();
  231.     pers_rotation_flag = FALSE;
  232.     Status_title = Status_org;
  233.     DrawStatus();
  234. }
  235.  
  236. //
  237. //    長方形の登録
  238. //
  239. function private AppendRectangle( v1, v2, v3, v4 )
  240. {
  241.     PolySetVertex( v1, 0 );
  242.     PolySetVertex( v2, 1 );
  243.     PolySetVertex( v3, 2 );
  244.     PolySetVertex( v4, 3 );
  245.     PolyAppend( TRUE );
  246.     ViewCursor( OFF );
  247.     DrawCurrent( TRUE );
  248.     ViewCursor( ON );
  249. }
  250.  
  251. //
  252. //    直方体・長方形の作成
  253. //
  254. function CreateRectangle()
  255. {
  256.     var    key ;
  257.     var    prev, temp;
  258.     var    i, a, b, c ;
  259.     var    ver[8], pos[2][3] ;
  260.     var    pick, draw_flag = ON;
  261.     var    prev_sel;
  262.  
  263.     PushMenu();
  264.     Status_org = Status_title;
  265.     ClearStatus();
  266.     MenuPosition( Menu( " 動作設定(&S)",
  267.             "作成中止    ESC",    MenuQuit
  268.         ), Menu_Title );
  269.  
  270.     Status_title[0] = "【直方体作成中】";
  271.     DrawStatus();
  272.  
  273.     quit_flag = FALSE;
  274.     prev_sel = Select();
  275.  
  276.     prev = Cursor();
  277.     cur = prev ;
  278.     pick = cur;
  279.     fix_vertex = cur;
  280.     input_flag = OFF;
  281.     while( TRUE )
  282.     {
  283.         if( draw_flag == ON )
  284.             DrawBox( cur, prev );
  285.         key = WaitEvent();
  286.         if( key )
  287.             input_flag = ON;
  288.         if( (( ShiftStat() & 1 ) == 1))
  289.         {
  290.             cur = Cursor();
  291.             TrimCursor(fix_vertex, MouseWindow());
  292.             Cursor( cur );
  293.         }
  294.         else
  295.             cur = Cursor();
  296.         key = KeyCode();
  297.         if ( input_flag | key == INPUT_KEY )
  298.         {
  299.             if( cur == prev )
  300.             {
  301.                 Warning();
  302.                 if( MESSAGE == ON )
  303.                     Message( error_msg4 );
  304.             }
  305.             else
  306.                 break;
  307.         }
  308.         else if( key == ESC | key == BS | quit_flag == TRUE )
  309.         {
  310.             PopandClear( OVERWRITE );
  311.             return;
  312.         }
  313.         else
  314.             temp = KeyProcess( key );
  315.         if( ((key!=0 ) & (key != INPUT_KEY)) | ( pick != Cursor()) )
  316.         {
  317.             draw_flag = ON;
  318.             DrawBox( pick, prev );
  319.         }
  320.         else
  321.             draw_flag = OFF;
  322.         pick = Cursor();
  323.         input_flag = OFF;
  324.     }
  325.     Clear( OVERWRITE );
  326.     if( SelectPolygons( prev_sel ) != 0 )
  327.     {
  328.         SelectAllFalse();
  329.         SelectAll( FALSE );
  330.     }
  331.  
  332.     Position( prev, pos[0] );
  333.     Position( cur, pos[1] );
  334.     for( i = 0 ; i < 8 ; i += 1 )
  335.     {
  336.         a = ( ( i & 1 ) == 0 );
  337.         b = ( ( i & 2 ) == 0 );
  338.         c = ( ( i & 4 ) == 0 );
  339.         ver[i] = Vertex( pos[a][0], pos[b][1], pos[c][2] );
  340.     }
  341.     PolyVertexs( 4 );
  342.     PolyType( POLY_SIMPLE );
  343.     PolyAttr( AttrCurrent() );
  344.     PolyObj( ObjCurrent() );
  345.     if ( pos[0][0] != pos[1][0] & pos[0][1] != pos[1][1] )
  346.     {
  347.         AppendRectangle( ver[0], ver[1], ver[3], ver[2] );
  348.         if ( pos[0][2] != pos[1][2] )
  349.             AppendRectangle( ver[4], ver[5], ver[7], ver[6] );
  350.     }
  351.     if ( pos[0][0] != pos[1][0] & pos[0][2] != pos[1][2] )
  352.     {
  353.         AppendRectangle( ver[0], ver[1], ver[5], ver[4] );
  354.         if ( pos[0][1] != pos[1][1] )
  355.             AppendRectangle( ver[2], ver[3], ver[7], ver[6] );
  356.     }
  357.     if ( pos[0][1] != pos[1][1] & pos[0][2] != pos[1][2] )
  358.     {
  359.         AppendRectangle( ver[0], ver[2], ver[6], ver[4] );
  360.         if ( pos[0][0] != pos[1][0] )
  361.             AppendRectangle( ver[1], ver[3], ver[7], ver[5] );
  362.     }
  363.     UpdateObject();
  364.     PopMenu();
  365.     pers_rotation_flag = FALSE;
  366.     Status_title = Status_org;
  367.     DrawStatus();
  368. }
  369.  
  370. //
  371. //    角錐の作成
  372. //
  373. function CreatePyramid()
  374. {
  375.     var vers, i, j;
  376.     var ver[2];
  377.     var all_edge, rinkaku_edge;
  378.  
  379.     if( SelectPolygons() == 0 )
  380.     {
  381.         Warning();
  382.         if( MESSAGE == ON )
  383.             Message( error_msg3 );
  384.         return;
  385.     }
  386.  
  387.     all_edge = EdgeSelect();
  388.     rinkaku_edge = EdgeSelectCount( all_edge, 1, 1 );
  389.  
  390.     SelectAllFalse();
  391.     SelectAll( FALSE );
  392.  
  393.     cur = Cursor();
  394.     j = Edges( rinkaku_edge );
  395.     ViewCursor( OFF );
  396.     for( i = 0; i< j; i++ )
  397.     {
  398.         EdgeGetVertex( rinkaku_edge, i, ver );
  399.         PolyVertexs( 3 );
  400.         PolySetVertex( cur, 0 );
  401.         PolySetVertex( ver[0], 1 );
  402.         PolySetVertex( ver[1], 2 );
  403.         PolyType( POLY_SIMPLE );
  404.         PolyAttr( AttrCurrent() );
  405.         PolyObj( ObjCurrent() );
  406.         PolyAppend( TRUE );
  407.         DrawCurrent( TRUE );
  408.     }
  409.     ViewCursor( ON );
  410.     UpdateObject();
  411.     pers_rotation_flag = FALSE;
  412. }
  413.  
  414. //
  415. //    面立ち上げ機能
  416. //
  417. function CreateStandUpPolygons()
  418. {
  419.     var i, j, key, vers, temp;
  420.     var org, ver[2];
  421.     var vect;
  422.     var all_edge, rinkaku_edge;
  423.     var pick, draw_flag = ON;
  424.  
  425.     if ( SelectPolygons() == 0 )
  426.     {
  427.         Warning();
  428.         if( MESSAGE == ON )
  429.             Message( error_msg3 );
  430.         return ;
  431.     }
  432.  
  433.     PushMenu();
  434.     Status_org = Status_title;
  435.     ClearStatus();
  436.     MenuPosition( Menu( " 動作設定(&S)",
  437.             "作成中止    ESC",    MenuQuit
  438.         ), Menu_Title );
  439.     Status_title[0] = "【面立ち上げ中】";
  440.     DrawStatus();
  441.  
  442.     quit_flag = FALSE;
  443.  
  444.     org = Cursor();
  445.     cur = org;
  446.     pick = cur;
  447.     fix_vertex = cur;
  448.     input_flag = OFF;
  449.     while( TRUE )
  450.     {
  451.         if( draw_flag == ON )
  452.             DrawLine( org, cur );
  453.         key = WaitEvent();
  454.         if( key )
  455.             input_flag = ON;
  456.         if( (( ShiftStat() & 1 ) == 1))
  457.         {
  458.             cur = Cursor();
  459.             TrimCursor(fix_vertex, MouseWindow());
  460.             Cursor( cur );
  461.         }
  462.         else
  463.             cur = Cursor();
  464.         key = KeyCode();
  465.         if( input_flag | key == INPUT_KEY )
  466.         {
  467.             if( cur == org )
  468.             {
  469.                 Warning();
  470.                 if( MESSAGE == ON )
  471.                     Message( "2点目は立ち上げる幅を指定してください" );
  472.             }
  473.             else
  474.                 break;
  475.         }
  476.         else if( key == ESC | key == BS | quit_flag == TRUE )
  477.         {
  478.             PopandClear( OVERWRITE );
  479.             return;
  480.         }
  481.         else
  482.             temp = KeyProcess( key );
  483.         if( ((key!=0 ) & (key != INPUT_KEY)) | ( pick != Cursor()) )
  484.         {
  485.             draw_flag = ON;
  486.             DrawLine( org, pick );
  487.         }
  488.         else
  489.             draw_flag = OFF;
  490.         pick = Cursor();
  491.         input_flag = OFF;
  492.     }
  493.     Clear( OVERWRITE );
  494.  
  495.     all_edge = EdgeSelect();
  496.     rinkaku_edge = EdgeSelectCount( all_edge, 1, 1 );
  497.  
  498.     vect = Position( cur ) - Position( org );
  499.     Select( _CopyPolygons( vect ) );
  500.  
  501.     j = Edges( rinkaku_edge );
  502.     ViewCursor( OFF );
  503.     for( i = 0; i< j; i++ )
  504.     {
  505.         EdgeGetVertex( rinkaku_edge, i, ver );
  506.         PolyVertexs( 4 );
  507.         PolySetVertex( ver[0], 0 );
  508.         PolySetVertex( ver[1], 1 );
  509.         PolySetVertex( ver[1]+vect, 2 );
  510.         PolySetVertex( ver[0]+vect, 3 );
  511.         PolyType( POLY_SIMPLE );
  512.         PolyAttr( AttrCurrent() );
  513.         PolyObj( ObjCurrent() );
  514.         PolyAppend( TRUE );
  515.         DrawCurrent( TRUE );
  516.     }
  517.     ViewCursor( ON );
  518.     UpdateObject();
  519.     pers_rotation_flag = FALSE;
  520.     PopMenu();
  521.     Status_title = Status_org;
  522.     DrawStatus();
  523. }
  524.  
  525. //
  526. //    面作成
  527. //
  528. function Polygon()
  529. {
  530.     ClearStatus();
  531.     Status_title[0] = "【モード:多角形作成】";
  532.     DrawStatus();
  533.     InputEvent( CreatePolygon );
  534.     KeyEvent( CreatePolygon, INPUT_KEY );
  535. }
  536.  
  537. //
  538. //    正多角形作成
  539. //
  540. function EquilateralPolygon()
  541. {
  542.     ClearStatus();
  543.     Status_title[0] = "【モード:正多角形作成】";
  544.     DrawStatus();
  545.     InputEvent( CreateEquilateralPolygon );
  546.     KeyEvent( CreateEquilateralPolygon, INPUT_KEY );
  547. }
  548.  
  549. //
  550. //    直方体作成
  551. //
  552. function Rectangle()
  553. {
  554.     ClearStatus();
  555.     Status_title[0] = "【モード:直方体作成】";
  556.     DrawStatus();
  557.     InputEvent( CreateRectangle );
  558.     KeyEvent( CreateRectangle, INPUT_KEY );
  559. }
  560.  
  561. //
  562. //    球作成
  563. //
  564. function Ball()
  565. {
  566.     ClearStatus();
  567.     Status_title[0] = "【モード:球作成】";
  568.     DrawStatus();
  569.     InputEvent( CreateBall );
  570.     KeyEvent( CreateBall, INPUT_KEY );
  571. }
  572.  
  573. //
  574. //    回転体作成
  575. //
  576. function RotationBody()
  577. {
  578.     ClearStatus();
  579.     Status_title[0] = "【モード:回転体作成】";
  580.     DrawStatus();
  581.     InputEvent( CreateRotationBody );
  582.     KeyEvent( CreateRotationBody, INPUT_KEY );
  583. }
  584.  
  585. //
  586. //    角錐作成
  587. //
  588. function Pyramid()
  589. {
  590.     ClearStatus();
  591.     Status_title[0] = "【モード:角錐作成】";
  592.     DrawStatus();
  593.     InputEvent( CreatePyramid );
  594.     KeyEvent( CreatePyramid, INPUT_KEY );
  595. }
  596.  
  597. //
  598. //    面立ち上げ
  599. //
  600. function StandUp()
  601. {
  602.     ClearStatus();
  603.     Status_title[0] = "【モード:面立ち上げ】";
  604.     DrawStatus();
  605.     InputEvent( CreateStandUpPolygons );
  606.     KeyEvent( CreateStandUpPolygons, INPUT_KEY );
  607. }
  608.  
  609. //
  610. //    チューブを作成
  611. //
  612. function MakeTube()
  613. {
  614.     if( SelectPolygons() < 2 )
  615.     {
  616.         Warning();
  617.         if( MESSAGE == ON )
  618.             Message( "接続する面は2面以上選択してください" );
  619.     }
  620.     else
  621.     {
  622.         Tube( Select());
  623.         pers_rotation_flag = FALSE;
  624.         UpdateObject();
  625.     }
  626. }
  627.  
  628. MenuPosition(
  629.     Menu( " 作成(&C)",
  630.         "多角形(&P)    P",        Polygon,
  631.         "------------------",        SEPARATE_MENU,
  632.         "正多角形(&E)    E",        EquilateralPolygon,
  633.         "------------------",        SEPARATE_MENU,
  634.         "直方体(&H)    H",        Rectangle,
  635.         "球(&G)    G",        Ball,
  636.         "回転体(&R)    R",        RotationBody,
  637.         "------------------",        SEPARATE_MENU,
  638.         "角錐(&K)    K",        Pyramid,SelectCheck,
  639.         "面立ち上げ(&U)    U",        StandUp,SelectCheck,
  640.         "------------------",        SEPARATE_MENU,
  641.         "チューブを作成(&T)    シフト+T",    MakeTube,SelectCheck
  642.     ), Menu_create
  643. );
  644.