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

  1. /*
  2.  *    ポリゴンデータ制御
  3.  *
  4.  *        Copyright T.Kobayashi    1994.8.9
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <assert.h>
  11. #include <math.h>
  12.  
  13. #include "matrix.h"
  14. #include "vector.h"
  15. #include "matclass.h"
  16. #include "strclass.h"
  17. #include "ml.h"
  18. #include "verconv.h"
  19.  
  20. #include "poly.h"
  21. #include "view.h"
  22. #include "menu.h"
  23. #include "graph.h"
  24. #include "input.h"
  25.  
  26. static    char    *SysConstName[] = {
  27.     "POLY_SIMPLE",
  28.     "POLY_SHADE",
  29.     "POLY_UV",
  30.     "POLY_UVSHADE",
  31.     "SELECT_UPDATE",
  32.     "SELECT_AND",
  33.     "SELECT_OR",
  34.     "SELECT_XOR",
  35.     "SELECT_ALL",
  36.     "SELECT_SUB",
  37.     "FILE_OVERWRITE",
  38.     "FILE_APPEND",
  39.     "OBJ_CREATE",
  40.     "OBJ_APPEND",
  41.     "ATTR_CREATE",
  42.     "ATTR_APPEND",
  43.     "VERTEX_MIN",
  44.     "VERTEX_MAX",
  45.     "NORMAL_OFF",
  46.     "NORMAL_ON",
  47.     "NORMAL_CREATE",
  48.     NULL
  49. };
  50.  
  51. static    IntData        SysConst[] = {
  52.     { TYPE_INT,    0,        POLY_SIMPLE,        },
  53.     { TYPE_INT,    0,        POLY_SHADE,            },
  54.     { TYPE_INT,    0,        POLY_UV,            },
  55.     { TYPE_INT,    0,        POLY_UVSHADE,        },
  56.     { TYPE_INT,    0,        SELECT_UPDATE,        },
  57.     { TYPE_INT,    0,        SELECT_AND,            },
  58.     { TYPE_INT,    0,        SELECT_OR,            },
  59.     { TYPE_INT,    0,        SELECT_XOR,            },
  60.     { TYPE_INT,    0,        SELECT_ALL,            },
  61.     { TYPE_INT,    0,        SELECT_SUB,            },
  62.     { TYPE_INT,    0,        FILE_OVERWRITE,        },
  63.     { TYPE_INT,    0,        FILE_APPEND,        },
  64.     { TYPE_INT,    0,        FILE_OVERWRITE,        },
  65.     { TYPE_INT,    0,        FILE_APPEND,        },
  66.     { TYPE_INT,    0,        FILE_OVERWRITE,        },
  67.     { TYPE_INT,    0,        FILE_APPEND,        },
  68.     { TYPE_INT,    0,        -32767,                },
  69.     { TYPE_INT,    0,        32767,                },
  70.     { TYPE_INT,    0,        SHADE_OFF,            },
  71.     { TYPE_INT,    0,        SHADE_ON,            },
  72.     { TYPE_INT,    0,        SHADE_CREATE,        },
  73. };
  74.  
  75. static    int        MatrixClassID ;
  76. static    int        StringClassID ;
  77.  
  78. int        VectorClassID ;
  79. int        VertexClassID ;
  80.  
  81. static    VertexClass    *StackAllocVertex( DataStruct* );
  82. static    int        VertexEqual( int, int, DataStruct* );
  83. static    int        ToString( int, int, DataStruct* );
  84. static    int        CreateVertex( int, int, DataStruct* );
  85. static    int        VertexPlus( int, int, DataStruct* );
  86. static    int        VertexMinus( int, int, DataStruct* );
  87. static    int        VertexMult( int, int, DataStruct* );
  88. static    int        GetPosition( int, int, DataStruct* );
  89. static    int        GetVector( int, int, DataStruct* );
  90. static    int        GetMapping( int, int, DataStruct* );
  91. static    int        SetVertex( int, int, DataStruct* );
  92. static    int        GetVertex( int, int, DataStruct* );
  93. static    int        InsVertex( int, int, DataStruct* );
  94. static    int        DelVertex( int, int, DataStruct* );
  95. static    int        FuncPolyVers( int, int, DataStruct* );
  96. static    int        FuncPolyType( int, int, DataStruct* );
  97. static    int        FuncPolyAttr( int, int, DataStruct* );
  98. static    int        FuncPolyObj( int, int, DataStruct* );
  99. static    int        FuncPolyAppend( int, int, DataStruct* );
  100. static    int        FuncPolyLoad( int, int, DataStruct* );
  101. static    int        FuncPolyLoadInit( int, int, DataStruct* );
  102. static    int        FuncPolySave( int, int, DataStruct* );
  103. static    int        FuncPolyDelete( int, int, DataStruct* );
  104. static    int        FuncPolyMove( int, int, DataStruct* );
  105. static    int        FuncPolyInvisible( int, int, DataStruct* );
  106. static    int        FuncPolyVertex( int, int, DataStruct* );
  107. static    int        FuncPolyPlane( int, int, DataStruct* );
  108. static    int        FuncReadFile( int, int, DataStruct* );
  109. static    int        FuncFrmReadFile( int, int, DataStruct* );
  110. static    int        FuncWriteFile( int, int, DataStruct* );
  111. static    int        FuncPolyShade( int, int, DataStruct* );
  112. static    int        FuncPolyShadeInv( int, int, DataStruct* );
  113. static    int        FuncPolyMap( int, int, DataStruct* );
  114. static    int        FuncPolyShiftVertex( int, int, DataStruct* );
  115. static    int        FuncPolyInvVertex( int, int, DataStruct* );
  116. static    int        FuncVertexLength( int, int, DataStruct* );
  117. static    int        FuncVertexLength2( int, int, DataStruct* );
  118. static    int        FuncPolyVector(int, int, DataStruct* );
  119.  
  120. void    PolyLibInit()
  121. {
  122.     int        i ;
  123.  
  124.     StringClassID = ClassName( "String" );
  125.     MatrixClassID = ClassName( "Matrix" );
  126.     VectorClassID = ClassName( "Vector" );
  127.     VertexClassID = NewClass( "Vertex", 0 );
  128.  
  129.     for( i = 0 ; SysConstName[i] != NULL ; i++ )
  130.         NewConst( SysConstName[i], (DataStruct*)&SysConst[i] );
  131.  
  132.     NewOperator( VertexClassID,    OPE_PLUS, VertexPlus );
  133.     NewOperator( VertexClassID,    OPE_MINUS, VertexMinus );
  134.     NewOperator( VertexClassID,    OPE_MULT, VertexMult);
  135.     NewOperator( VertexClassID,    OPE_EQ, VertexEqual );
  136.     NewOperator( VertexClassID,    OPE_NOTEQ, VertexEqual );
  137.  
  138.     NewFunction( VertexClassID, "tostring", ToString );
  139.     NewFunction( 0,                "Vertex", CreateVertex );
  140.     NewFunction( VectorClassID,    "Vertex", CreateVertex );
  141.     NewFunction( VertexClassID, "Position", GetPosition );
  142.     NewFunction( VertexClassID, "Vector", GetVector );
  143.     NewFunction( VertexClassID, "Mapping", GetMapping );
  144.     NewFunction( VertexClassID, "VertexLength", FuncVertexLength );
  145.     NewFunction( VertexClassID, "VertexLength2", FuncVertexLength2 );
  146.  
  147.     NewFunction( VertexClassID, "PolySetVertex", SetVertex );
  148.     NewFunction( 0,                "PolyGetVertex", GetVertex );
  149.     NewFunction( VertexClassID, "PolyInsVertex", InsVertex);
  150.     NewFunction( 0,                "PolyDelVertex", DelVertex);
  151.     NewFunction( 0,                "PolyVertexs", FuncPolyVers );
  152.     NewFunction( 0,                "PolyType", FuncPolyType );
  153.     NewFunction( 0,                "PolyAttr", FuncPolyAttr );
  154.     NewFunction( 0,                "PolyObj", FuncPolyObj );
  155.     NewFunction( 0,                "PolyAppend", FuncPolyAppend );
  156.     NewFunction( 0,                "PolyLoad", FuncPolyLoad );
  157.     NewFunction( 0,                "PolyLoadInit", FuncPolyLoadInit );
  158.     NewFunction( 0,                "PolySave", FuncPolySave );
  159.     NewFunction( 0,                "PolyDelete", FuncPolyDelete );
  160.     NewFunction( MatrixClassID,    "PolyMove", FuncPolyMove );
  161.     NewFunction( 0,                "PolyInvisible", FuncPolyInvisible );
  162.     NewFunction( VertexClassID,    "PolyVertex", FuncPolyVertex );
  163.     NewFunction( VertexClassID,    "PolyPlane", FuncPolyPlane );
  164.     NewFunction( StringClassID,    "ReadFile", FuncReadFile );
  165.     NewFunction( StringClassID,    "ObjReadFile", FuncReadFile );
  166.     NewFunction( StringClassID,    "FrmReadFile", FuncFrmReadFile );
  167.     NewFunction( 0,                "WriteFile", FuncWriteFile );
  168.     NewFunction( 0,                "ObjWriteFile", FuncWriteFile );
  169.     NewFunction( 0,                "PolyShade", FuncPolyShade );
  170.     NewFunction( 0,                "PolyShadeInv", FuncPolyShadeInv );
  171.     NewFunction( 0,                "PolyMap", FuncPolyMap );
  172.     NewFunction( 0,                "PolyShiftVertex", FuncPolyShiftVertex);
  173.     NewFunction( 0,                "PolyInvVertex", FuncPolyInvVertex);
  174.     NewFunction( 0,                "PolyVector", FuncPolyVector);
  175.  
  176.     SelectLibInit();
  177.     AttrLibInit();
  178.     ObjLibInit();
  179. }
  180.  
  181. static    VertexClass    *StackAllocVertex( buf )
  182. DataStruct    *buf ;
  183. {
  184.     DataStruct    *top ;
  185.  
  186.     top = StackAlloc( 1 );
  187.     top->type = TYPE_OBJECT ;
  188.     top->od.ptr = ObjectDup( buf->od.ptr );
  189.     return (VertexClass*)top->od.ptr ;
  190. }
  191.  
  192. static    int        VertexEqual( ident, args, buf )
  193. int        ident ;
  194. int        args ;
  195. DataStruct    *buf ;
  196. {
  197.     int        eq ;
  198.     Vertex    *v1, *v2 ;
  199.  
  200.     if ( ObjectCheck( &buf[1], VertexClassID ) == FALSE )
  201.         ExecError( "演算の型が不正です" );
  202.  
  203.     v1 = &((VertexClass*)buf[0].od.ptr)->ver ;
  204.     v2 = &((VertexClass*)buf[1].od.ptr)->ver ;
  205.  
  206.     eq = ( ( v1->x == v2->x ) && ( v1->y == v2->y ) && ( v1->z == v2->z ) );
  207.  
  208.     if ( ident == OPE_EQ )
  209.         StackPushBoolean( eq );
  210.     else
  211.         StackPushBoolean( !eq );
  212.     return RETURN_RETURN ;
  213. }
  214.  
  215. static    int        ToString( ident, args, buf )
  216. int        ident ;
  217. int        args ;
  218. DataStruct    *buf ;
  219. {
  220.     VertexClass    *ver ;
  221.     char    str[256], substr[128] ;
  222.  
  223.     assert( buf->type == TYPE_OBJECT );
  224.     ver = (VertexClass*)buf->od.ptr ;
  225.  
  226.     sprintf( str, "( %-4d, %-4d, %-4d )", ver->ver.x, ver->ver.y, ver->ver.z );
  227.     if ( ver->dtype & POLY_SHADE )
  228.     {
  229.         Vector    v ;
  230.         toVector( &v, (double)ver->ver.vx, (double)ver->ver.vy, (double)ver->ver.vz );
  231.         sprintf( substr, " ( %-8.5g, %-8.5g, %-8.5g )", v.x, v.y, v.z );
  232.         strcat( str, substr );
  233.     }
  234.     if ( ver->dtype & POLY_UV )
  235.     {
  236.         sprintf( substr, " ( %-4d, %-4d )", ver->ver.u, ver->ver.v );
  237.         strcat( str, substr );
  238.     }
  239.  
  240.     buf = StackAlloc( 1 );
  241.     StringToObject( buf, str );
  242.     return RETURN_RETURN ;
  243. }
  244.  
  245. /*    頂点データの設定    */
  246. static    int        CreateVertex( ident, args, buf )
  247. int        ident ;
  248. int        args ;
  249. DataStruct    *buf ;
  250. {
  251.     extern int    ToVector(int args, DataStruct *buf, Vector* vec);
  252.     VertexClass    *ver ;
  253.     VectorClass    *v ;
  254.     Vector vec;
  255.  
  256.     int c, count = 0;
  257.  
  258.     if ( args < 1 )
  259.         ExecError( "引数の数が違います。(Vertex)" );
  260.  
  261.     ver = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
  262.  
  263.     ver->dtype = POLY_SIMPLE ;
  264.     memset(&ver->ver, 0, sizeof(Vertex));
  265.     if ((count = ToVector(args, buf, &vec))    != 0) {
  266.         ver->ver.x = (int)vec.x;
  267.         ver->ver.y = (int)vec.y;
  268.         ver->ver.z = (int)vec.z;
  269.     } else {
  270.         ExecError( "引数の型が不正です。(Vertex)" );
  271.     }
  272.     if (args - count > 0) {
  273.         ver->dtype = POLY_SHADE ;
  274.         if ((c = ToVector(args-count, buf+count, &vec)) != 0) {
  275.             ver->ver.vx = (int)vec.x;
  276.             ver->ver.vy = (int)vec.y;
  277.             ver->ver.vz = (int)vec.z;
  278.             count += c;
  279.         } else {
  280.             ExecError( "引数の型が不正です。(Vertex)" );
  281.         }
  282.     }
  283.     if (args - count > 0) {
  284.         ver->dtype = POLY_UVSHADE ;
  285.         if ( buf[count].type == TYPE_OBJECT ) {
  286.             /*    Vectorクラスからの変換    */
  287.             if ( ! ObjectCheck( &buf[0], VectorClassID ) )
  288.                 ExecError( "引数の型が不正です。(Vertex)" );
  289.  
  290.             v = (VectorClass*)buf[0].od.ptr ;
  291.             ver->ver.u = (int)v->vec.x ;
  292.             ver->ver.v = (int)v->vec.y ;
  293.         } else if (buf[count].type == TYPE_ARRAY) {
  294.             DataStruct *abuf;
  295.             abuf = buf[count].ad.ary;
  296.             if (buf[count].ad.size >= 2
  297.              && (abuf[0].type & (TYPE_INT|TYPE_REAL))
  298.              && (abuf[1].type & (TYPE_INT|TYPE_REAL))) {
  299.                 ver->ver.u = ToInt(&abuf[0]);
  300.                 ver->ver.v = ToInt(&abuf[1]);
  301.             } else {
  302.                 ExecError( "引数の型が不正です。(Vertex)" );
  303.             }
  304.         } else if (args-count >= 2
  305.                && (buf[count  ].type & (TYPE_INT|TYPE_REAL))
  306.                && (buf[count+1].type & (TYPE_INT|TYPE_REAL))) {
  307.             ver->ver.u = ToInt( &buf[count] );
  308.             ver->ver.v = ToInt( &buf[count+1] );
  309.         } else {
  310.             ExecError( "引数の型が不正です。(Vertex)" );
  311.         }
  312.     }
  313.  
  314.     buf = StackAlloc( 1 );
  315.     buf->type = TYPE_OBJECT ;
  316.     buf->od.ptr = (Object*)ver ;
  317.     return RETURN_RETURN ;
  318. }
  319.  
  320. static    int        VertexPlus( ident, args, buf )
  321. int        ident ;
  322. int        args ;
  323. DataStruct    *buf ;
  324. {
  325.     VertexClass    *ver, *ver1 ;
  326.     int        x, y, z, vx, vy, vz, u, v ;
  327.  
  328.     if ( ConvVertex( &x, &y, &z, &vx, &vy, &vz, &u, &v, buf+1 ) )
  329.     {
  330.         ver = StackAllocVertex( &buf[0] );
  331.         ver1 = (VertexClass*)buf[0].od.ptr ;
  332.         ver->ver.x = ver1->ver.x + x ;
  333.         ver->ver.y = ver1->ver.y + y ;
  334.         ver->ver.z = ver1->ver.z + z ;
  335.         ver->ver.vx = ver1->ver.vx + vx ;
  336.         ver->ver.vy = ver1->ver.vy + vy ;
  337.         ver->ver.vz = ver1->ver.vz + vz ;
  338.         ver->ver.u = ver1->ver.u + u ;
  339.         ver->ver.v = ver1->ver.v + v ;
  340.     }
  341.     else
  342.         ExecError( "型が不正です。(演算子+)" );
  343.  
  344.     return RETURN_RETURN ;
  345. }
  346.  
  347. static    int        VertexMinus( ident, args, buf )
  348. int        ident ;
  349. int        args ;
  350. DataStruct    *buf ;
  351. {
  352.     VertexClass    *ver, *ver1 ;
  353.     int        x, y, z, vx, vy, vz, u, v ;
  354.  
  355.     if ( ConvVertex( &x, &y, &z, &vx, &vy, &vz, &u, &v, buf+1 ) )
  356.     {
  357.         ver = StackAllocVertex( &buf[0] );
  358.         ver1 = (VertexClass*)buf[0].od.ptr ;
  359.         ver->ver.x = ver1->ver.x - x ;
  360.         ver->ver.y = ver1->ver.y - y ;
  361.         ver->ver.z = ver1->ver.z - z ;
  362.         ver->ver.vx = ver1->ver.vx - vx ;
  363.         ver->ver.vy = ver1->ver.vy - vy ;
  364.         ver->ver.vz = ver1->ver.vz - vz ;
  365.         ver->ver.u = ver1->ver.u - u ;
  366.         ver->ver.v = ver1->ver.v - v ;
  367.     }
  368.     else
  369.         ExecError( "型が不正です。(演算子-)" );
  370.  
  371.     return RETURN_RETURN ;
  372. }
  373.  
  374. static    int        VertexMult( ident, args, buf )
  375. int        ident ;
  376. int        args ;
  377. DataStruct    *buf ;
  378. {
  379.     VertexClass    *ver, *ver1 ;
  380. #if 0
  381.     int            i ;
  382.     float        r[3] ;
  383. #endif
  384.     MatrixClass    *mat2 ;
  385.     Matrix    matit;
  386.     int        imat[5][3], imatit[5][3] ;
  387.     int x, y, z;
  388.  
  389.     if ( ObjectCheck( &buf[1], MatrixClassID ) )
  390.     {
  391.         ver = StackAllocVertex( &buf[0] );
  392.         ver1 = (VertexClass*)buf[0].od.ptr ;
  393.         mat2 = (MatrixClass*)buf[1].od.ptr ;
  394. #if 0
  395.         for( i = 0 ; i < 3 ; i++ )
  396.         {
  397.             r[i] =    (float)ver1->ver.x * mat2->mat[0][i] +
  398.                     (float)ver1->ver.y * mat2->mat[1][i] +
  399.                     (float)ver1->ver.z * mat2->mat[2][i] +
  400.                     mat2->mat[3][i] ;
  401.         }
  402.         ver->ver.x = r[0] ;
  403.         ver->ver.y = r[1] ;
  404.         ver->ver.z = r[2] ;
  405.         for( i = 0 ; i < 3 ; i++ )
  406.         {
  407.             r[i] =    (float)ver1->ver.vx * mat2->mat[0][i] +
  408.                     (float)ver1->ver.vy * mat2->mat[1][i] +
  409.                     (float)ver1->ver.vz * mat2->mat[2][i] +
  410.                     mat2->mat[3][i] ;
  411.         }
  412.         ver->ver.vx = r[0] ;
  413.         ver->ver.vy = r[1] ;
  414.         ver->ver.vz = r[2] ;
  415. #else
  416.         MatCopy(matit, mat2->mat);
  417.         MatInv(matit);
  418.         MatTra(matit);
  419.  
  420.         MatToInt( imat, mat2->mat );
  421.         MatToInt( imatit, matit );
  422.  
  423.         x = (int)ver1->ver.x * imat[0][0]
  424.           + (int)ver1->ver.y * imat[1][0]
  425.           + (int)ver1->ver.z * imat[2][0]
  426.           + imat[4][0];
  427.         y = (int)ver1->ver.x * imat[0][1]
  428.           + (int)ver1->ver.y * imat[1][1]
  429.           + (int)ver1->ver.z * imat[2][1]
  430.           + imat[4][1];
  431.         z = (int)ver1->ver.x * imat[0][2]
  432.           + (int)ver1->ver.y * imat[1][2]
  433.           + (int)ver1->ver.z * imat[2][2]
  434.           + imat[4][2];
  435. #if 0
  436.         if (x > 0) {
  437.             ver->ver.x = imat[3][0] + (short)( ( x + 32767) >> 16 );
  438.         } else {
  439.             ver->ver.x = imat[3][0] - (short)( (-x + 32767) >> 16 );
  440.         }
  441.         if (y > 0) {
  442.             ver->ver.y = imat[3][1] + (short)( ( y + 32767) >> 16 );
  443.         } else {
  444.             ver->ver.y = imat[3][1] - (short)( (-y + 32767) >> 16 );
  445.         }
  446.         if (z > 0) {
  447.             ver->ver.z = imat[3][2] + (short)( ( z + 32767) >> 16 );
  448.         } else {
  449.             ver->ver.z = imat[3][2] - (short)( (-z + 32767) >> 16 );
  450.         }
  451. #else
  452.         ver->ver.x = (short)imat[3][0] + (short)( x >> 16 );
  453.         ver->ver.y = (short)imat[3][1] + (short)( y >> 16 );
  454.         ver->ver.z = (short)imat[3][2] + (short)( z >> 16 );
  455. #endif
  456.         x = (int)ver1->ver.vx * imatit[0][0]
  457.           + (int)ver1->ver.vy * imatit[1][0]
  458.           + (int)ver1->ver.vz * imatit[2][0];
  459.         y = (int)ver1->ver.vx * imatit[0][1]
  460.           + (int)ver1->ver.vy * imatit[1][1]
  461.           + (int)ver1->ver.vz * imatit[2][1];
  462.         z = (int)ver1->ver.vx * imatit[0][2]
  463.           + (int)ver1->ver.vy * imatit[1][2]
  464.           + (int)ver1->ver.vz * imatit[2][2];
  465.         ver->ver.vx = (short)( x >> 16 );
  466.         ver->ver.vy = (short)( y >> 16 );
  467.         ver->ver.vz = (short)( z >> 16 );
  468. #endif
  469.     }
  470.     else
  471.     {
  472.         ExecError( "型が不正です。(演算子*)" );
  473.     }
  474.  
  475.     return RETURN_RETURN ;
  476. }
  477.  
  478. /*    頂点データを得る    */
  479. static    int        GetPosition( ident, args, buf )
  480. int        ident ;
  481. int        args ;
  482. DataStruct    *buf ;
  483. {
  484.     VertexClass    *ver ;
  485.     VectorClass    *v ;
  486.  
  487.     if ( args == 1 )
  488.     {
  489.         v = (VectorClass*)ObjectAlloc( sizeof( VectorClass ), VectorClassID );
  490.         ver = (VertexClass*)buf[0].od.ptr ;
  491.         v->vec.x = ver->ver.x ;
  492.         v->vec.y = ver->ver.y ;
  493.         v->vec.z = ver->ver.z ;
  494.         buf = StackAlloc( 1 );
  495.         buf->type = TYPE_OBJECT ;
  496.         buf->od.ptr = (Object*)v ;
  497.         return RETURN_RETURN ;
  498.     }
  499.     else
  500.     {
  501.         ArgCheck( "Position", args, buf, TYPE_OBJECT, TYPE_ARRAY, TYPE_NOASN );
  502.  
  503.         if ( buf[1].ad.size < 3 )
  504.             ExecError( "引数配列のサイズが不正です。( Vertex:Position )" );
  505.  
  506.         ver = (VertexClass*)buf[0].od.ptr ;
  507.         buf = buf[1].ad.ary ;
  508.         buf[0].type = buf[1].type = buf[2].type = TYPE_INT ;
  509.         buf[0].id.i = ver->ver.x ;
  510.         buf[1].id.i = ver->ver.y ;
  511.         buf[2].id.i = ver->ver.z ;
  512.         return RETURN_VOID ;
  513.     }
  514. }
  515.  
  516. /*    法線ベクトルを得る    */
  517. static    int        GetVector( ident, args, buf )
  518. int        ident ;
  519. int        args ;
  520. DataStruct    *buf ;
  521. {
  522.     VertexClass    *ver ;
  523.     VectorClass    *v ;
  524.  
  525.     if ( args == 1 )
  526.     {
  527.         v = (VectorClass*)ObjectAlloc( sizeof( VectorClass ), VectorClassID );
  528.         ver = (VertexClass*)buf[0].od.ptr ;
  529.         v->vec.x = ver->ver.vx ;
  530.         v->vec.y = ver->ver.vy ;
  531.         v->vec.z = ver->ver.vz ;
  532.         buf = StackAlloc( 1 );
  533.         buf->type = TYPE_OBJECT ;
  534.         buf->od.ptr = (Object*)v ;
  535.         return RETURN_RETURN ;
  536.     }
  537.     else
  538.     {
  539.         ArgCheck( "Vector", args, buf, TYPE_OBJECT, TYPE_ARRAY, TYPE_NOASN );
  540.  
  541.         if ( buf[1].ad.size < 3 )
  542.             ExecError( "引数配列のサイズが不正です。( Vertex:Vector )" );
  543.  
  544.         ver = (VertexClass*)buf[0].od.ptr ;
  545.         buf = buf[1].ad.ary ;
  546.         buf[0].type = buf[1].type = buf[2].type = TYPE_INT ;
  547.         buf[0].id.i = ver->ver.vx ;
  548.         buf[1].id.i = ver->ver.vy ;
  549.         buf[2].id.i = ver->ver.vz ;
  550.         return RETURN_VOID ;
  551.     }
  552. }
  553.  
  554. /*    マッピング座標を得る    */
  555. static    int        GetMapping( ident, args, buf )
  556. int        ident ;
  557. int        args ;
  558. DataStruct    *buf ;
  559. {
  560.     VertexClass    *ver ;
  561.  
  562.     ArgCheck( "Mapping", args, buf, TYPE_OBJECT, TYPE_ARRAY, TYPE_NOASN );
  563.  
  564.     if ( buf[1].ad.size < 2 )
  565.         ExecError( "引数配列のサイズが不正です。( Vertex:Mapping )" );
  566.  
  567.     ver = (VertexClass*)buf[0].od.ptr ;
  568.     buf = buf[1].ad.ary ;
  569.     buf[0].type = buf[1].type = TYPE_INT ;
  570.     buf[0].id.i = ver->ver.u ;
  571.     buf[1].id.i = ver->ver.v ;
  572.     return RETURN_VOID ;
  573. }
  574.  
  575. /*    頂点間の距離を返す    */
  576. static    int        FuncVertexLength( ident, args, buf )
  577. int        ident ;
  578. int        args ;
  579. DataStruct    *buf ;
  580. {
  581.     VertexClass *v1, *v2;
  582.     int lx, ly, lz;
  583.     ArgCheck( "PolyVertexLength", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
  584.     if (ObjectCheck(&buf[0], VertexClassID) == FALSE
  585.      || ObjectCheck(&buf[1], VertexClassID) == FALSE) {
  586.         ExecError( "2番目の引数の型が不正です。(VertexLength)" );
  587.     }
  588.     v1 = (VertexClass*)buf[0].od.ptr;
  589.     v2 = (VertexClass*)buf[1].od.ptr;
  590.     lx = v1->ver.x - v2->ver.x;
  591.     ly = v1->ver.y - v2->ver.y;
  592.     lz = v1->ver.z - v2->ver.z;
  593.     StackPushInt((int)sqrt((double)(lx*lx+ly*ly+lz*lz)));
  594.     return RETURN_RETURN;
  595. }
  596.  
  597. /*    頂点間の距離を返す    */
  598. static    int        FuncVertexLength2( ident, args, buf )
  599. int        ident ;
  600. int        args ;
  601. DataStruct    *buf ;
  602. {
  603.     VertexClass *v1, *v2;
  604.     int lx, ly, lz;
  605.     ArgCheck( "PolyVertex2Length", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
  606.     if (ObjectCheck(&buf[0], VertexClassID) == FALSE
  607.      || ObjectCheck(&buf[1], VertexClassID) == FALSE) {
  608.         ExecError( "2番目の引数の型が不正です。(VertexLength2)" );
  609.     }
  610.     v1 = (VertexClass*)buf[0].od.ptr;
  611.     v2 = (VertexClass*)buf[1].od.ptr;
  612.     lx = v1->ver.x - v2->ver.x;
  613.     ly = v1->ver.y - v2->ver.y;
  614.     lz = v1->ver.z - v2->ver.z;
  615.     StackPushInt(lx*lx+ly*ly+lz*lz);
  616.     return RETURN_RETURN;
  617. }
  618.  
  619.  
  620. /*    頂点データをカレントポリゴンに    */
  621. static    int        SetVertex( ident, args, buf )
  622. int        ident ;
  623. int        args ;
  624. DataStruct    *buf ;
  625. {
  626.     int        n ;
  627.     VertexClass    *ver ;
  628.  
  629.     ArgCheck( "PolySetVertex", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
  630.  
  631.     ver = (VertexClass*)buf[0].od.ptr ;
  632.     n = buf[1].id.i ;
  633.     if ( n < 0 || MaxVertex <= n )
  634.         ExecError( "2番目の引数の値が不正です。(SetVertex)" );
  635.  
  636.     CurrentPoly->ver[n] = ver->ver ;
  637.  
  638.     return RETURN_VOID ;
  639. }
  640.  
  641. /*    カレントポリゴンの頂点データを取り出す    */
  642. static    int        GetVertex( ident, args, buf )
  643. int        ident ;
  644. int        args ;
  645. DataStruct    *buf ;
  646. {
  647.     int        n ;
  648.     VertexClass    *ver ;
  649.  
  650.     ArgCheck( "PolyGetVertex", args, buf, TYPE_INT, TYPE_NOASN );
  651.  
  652.     ver = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
  653.     n = buf[0].id.i ;
  654.     if ( n < 0 || MaxVertex <= n )
  655.         ExecError( "1番目の引数の値が不正です。(PolyGetVertex)" );
  656.  
  657.     ver->dtype = CurrentPoly->type ;
  658.     ver->ver = CurrentPoly->ver[n] ;
  659.  
  660.     buf = StackAlloc( 1 );
  661.     buf->type = TYPE_OBJECT ;
  662.     buf->od.ptr = (Object*)ver ;
  663.     return RETURN_RETURN ;
  664. }
  665.  
  666. /*    頂点データをカレントポリゴンに挿入    */
  667. static    int        InsVertex( ident, args, buf )
  668. int        ident ;
  669. int        args ;
  670. DataStruct    *buf ;
  671. {
  672.     int        n ;
  673.     VertexClass    *ver ;
  674.  
  675.     ArgCheck( "PolyInsVertex", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
  676.  
  677.     ver = (VertexClass*)buf[0].od.ptr ;
  678.     n = buf[1].id.i ;
  679.     if ( n < 0 || MaxVertex-1 <= n || n > CurrentPoly->vers)
  680.         ExecError( "2番目の引数の値が不正です。(InsVertex)" );
  681.  
  682.     if (n < CurrentPoly->vers) {
  683.         memmove(&CurrentPoly->ver[n+1],
  684.                 &CurrentPoly->ver[n],
  685.                 sizeof(Vertex) * (CurrentPoly->vers - n));
  686.     }
  687.     CurrentPoly->ver[n] = ver->ver ;
  688.     CurrentPoly->vers++;
  689.  
  690.     return RETURN_VOID ;
  691. }
  692.  
  693. /*    カレントポリゴンの頂点データを削除    */
  694. static    int        DelVertex( ident, args, buf )
  695. int        ident ;
  696. int        args ;
  697. DataStruct    *buf ;
  698. {
  699.     int        n ;
  700.     ArgCheck( "PolyDelVertex", args, buf, TYPE_INT, TYPE_NOASN );
  701.  
  702.     n = buf[0].id.i ;
  703.     if ( n < 0 || MaxVertex <= n || n >= CurrentPoly->vers)
  704.         ExecError( "1番目の引数の値が不正です。(PolyGetVertex)" );
  705.  
  706.     if (n < CurrentPoly->vers-1) {
  707.         memmove(&CurrentPoly->ver[n],
  708.                 &CurrentPoly->ver[n+1],
  709.                 sizeof(Vertex) * (CurrentPoly->vers - n - 1));
  710.     }
  711.     CurrentPoly->vers--;
  712.  
  713.     return RETURN_VOID ;
  714. }
  715.  
  716.  
  717. /*    カレントポリゴンの頂点数を設定する    */
  718. static    int        FuncPolyVers( ident, args, buf )
  719. int        ident ;
  720. int        args ;
  721. DataStruct    *buf ;
  722. {
  723.     if ( args >= 1 )
  724.     {
  725.         ArgCheck( "PolyVertexs", args, buf, TYPE_INT, TYPE_NOASN );
  726.         CurrentPoly->vers = buf[0].id.i ;
  727.     }
  728.     StackPushInt( CurrentPoly->vers );
  729.     return RETURN_RETURN ;
  730. }
  731.  
  732. /*    カレントポリゴンのデータタイプを設定する    */
  733. static    int        FuncPolyType( ident, args, buf )
  734. int        ident ;
  735. int        args ;
  736. DataStruct    *buf ;
  737. {
  738.     if ( args >= 1 )
  739.     {
  740.         ArgCheck( "PolyType", args, buf, TYPE_INT, TYPE_NOASN );
  741.         CurrentPoly->type = buf[0].id.i ;
  742.     }
  743.  
  744.     StackPushInt( CurrentPoly->type );
  745.     return RETURN_RETURN ;
  746. }
  747.  
  748. /*    カレントポリゴンのアトリビュートを設定する    */
  749. static    int        FuncPolyAttr( ident, args, buf )
  750. int        ident ;
  751. int        args ;
  752. DataStruct    *buf ;
  753. {
  754.     if ( args >= 1 )
  755.     {
  756.         ArgCheck( "PolyAttr", args, buf, TYPE_INT, TYPE_NOASN );
  757.         CurrentPoly->atr = buf[0].id.i ;
  758.     }
  759.     StackPushInt( CurrentPoly->atr );
  760.     return RETURN_RETURN ;
  761. }
  762.  
  763. /*    カレントポリゴンのオブジェクト番号を設定する    */
  764. static    int        FuncPolyObj( ident, args, buf )
  765. int        ident ;
  766. int        args ;
  767. DataStruct    *buf ;
  768. {
  769.     if ( args >= 1 )
  770.     {
  771.         ArgCheck( "PolyObj", args, buf, TYPE_INT, TYPE_NOASN );
  772.         CurrentPoly->obj = buf[0].id.i ;
  773.     }
  774.     StackPushInt( CurrentPoly->obj );
  775.     return RETURN_RETURN ;
  776. }
  777.  
  778. /*    カレントポリゴンを登録    */
  779. static    int        FuncPolyAppend( ident, args, buf )
  780. int        ident ;
  781. int        args ;
  782. DataStruct    *buf ;
  783. {
  784.     CurrentPoly->select = OFF ;
  785.     if (args >= 1) {
  786.         ArgCheck( "PolyAppend", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
  787.         CurrentPoly->select = (buf[0].id.i ? ON : OFF) ;
  788.     }
  789.     PolyAppend();
  790.     return RETURN_VOID ;
  791. }
  792.  
  793. /*    選択されているポリゴンを一時バッファに取り込む    */
  794. static    int        FuncPolyLoad( ident, args, buf )
  795. int        ident ;
  796. int        args ;
  797. DataStruct    *buf ;
  798. {
  799. #if 0
  800.     StackPushBoolean( PolyLoad() );
  801. #else
  802.     if (args == 0) {
  803.         StackPushInt( (int)PolyLoad() );
  804.     } else {
  805.         ArgCheck( "PolyLoad", args, buf, TYPE_INT, TYPE_NOASN );
  806.         StackPushInt((int)PolyLoadPtr((void*)buf[0].id.i));
  807.     }
  808. #endif
  809.     return RETURN_RETURN ;
  810. }
  811.  
  812. /*    一時バッファの初期化    */
  813. static    int        FuncPolyLoadInit( ident, args, buf )
  814. int        ident ;
  815. int        args ;
  816. DataStruct    *buf ;
  817. {
  818.     PolyPtr = NULL;
  819.     return RETURN_VOID ;
  820. }
  821.  
  822. /*    一時バッファからポリゴンを書き戻す    */
  823. static    int        FuncPolySave( ident, args, buf )
  824. int        ident ;
  825. int        args ;
  826. DataStruct    *buf ;
  827. {
  828.     if (PolyPtr == NULL) {
  829.         ExecError( "PolyLoadされていません。(Vertex:PolySave)" );
  830.     }
  831.     PolySave();
  832.     return RETURN_VOID ;
  833. }
  834.  
  835. /*    セレクトされているポリゴン削除する    */
  836. static    int        FuncPolyDelete( ident, args, buf )
  837. int        ident ;
  838. int        args ;
  839. DataStruct    *buf ;
  840. {
  841.     PolyDelete();
  842.     return RETURN_VOID ;
  843. }
  844.  
  845. /*    セレクトされているポリゴンを移動する    */
  846. static    int        FuncPolyMove( ident, args, buf )
  847. int        ident ;
  848. int        args ;
  849. DataStruct    *buf ;
  850. {
  851.     ArgCheck( "PolyMove", args, buf, TYPE_OBJECT, TYPE_NOASN );
  852.     PolyMove( ((MatrixClass*)buf[0].od.ptr)->mat );
  853.     return RETURN_VOID ;
  854. }
  855.  
  856. /*    セレクトされていないポリゴンを不可視属性にする    */
  857. static    int        FuncPolyInvisible( ident, args, buf )
  858. int        ident ;
  859. int        args ;
  860. DataStruct    *buf ;
  861. {
  862.     ArgCheck( "PolyInvisible", args, buf, TYPE_BOOLEAN|TYPE_INT, TYPE_NOASN );
  863.     PolyInvisible( buf[0].id.i );
  864.     return RETURN_VOID ;
  865. }
  866.  
  867. /*    最近頂点を検索    */
  868. static    int        FuncPolyVertex( ident, args, buf )
  869. int        ident ;
  870. int        args ;
  871. DataStruct    *buf ;
  872. {
  873.     int view;
  874.     Vertex    *ver ;
  875.     VertexClass    *ret ;
  876.  
  877.     if (args == 2) {
  878.         ArgCheck( "PolyVertex", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
  879.         view = buf[1].id.i;
  880.     } else {
  881.         ArgCheck( "PolyVertex", args, buf, TYPE_OBJECT, TYPE_NOASN );
  882.         view = 0;
  883.     }
  884.     ver = PolyVertex( &((VertexClass*)buf[0].od.ptr)->ver, view );
  885.     ret = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
  886.     ret->dtype = POLY_SIMPLE ;
  887.     memset(&ret->ver, 0, sizeof(Vertex));
  888.     if ( ver != NULL )
  889.         ret->ver = *ver ;
  890.  
  891.     buf = StackAlloc( 1 );
  892.     buf->type = TYPE_OBJECT ;
  893.     buf->od.ptr = (Object*)ret ;
  894.     return RETURN_RETURN ;
  895. }
  896.  
  897. /*    平面投射    */
  898. static    int        FuncPolyPlane( ident, args, buf )
  899. int        ident ;
  900. int        args ;
  901. DataStruct    *buf ;
  902. {
  903.     int        i, win ;
  904.     Vertex    *ver, vary[3] ;
  905.     VertexClass    *ret ;
  906.  
  907. #if 0
  908.     ArgCheck( "PolyPlane", args, buf, TYPE_OBJECT, TYPE_INT,
  909.                 TYPE_OBJECT, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
  910. #endif
  911.     if (buf[0].type != TYPE_OBJECT || buf[1].type != TYPE_INT) {
  912.         ExecError( "引数の型が不正です。(Vertex:PolyPlane)" );
  913.     }
  914.     ver = &((VertexClass*)buf[0].od.ptr)->ver ;
  915.     win = buf[1].id.i ;
  916.     buf = &buf[2];
  917.     args -= 2;
  918.     if (buf->type == TYPE_ARRAY) {
  919.         args = buf->ad.size;
  920.         buf  = buf->ad.ary;
  921.     }
  922.     if (args != 3) {
  923.         ExecError( "引数の型が不正です。(Vertex:PolyPlane)" );
  924.     }
  925.  
  926.     for( i = 0 ; i < 3 ; i++ )
  927.     {
  928.         if ( ObjectCheck( &buf[i], VertexClassID ) == FALSE )
  929.             ExecError( "引数の型が不正です。(Vertex:PolyPlane)" );
  930.         vary[i] = ((VertexClass*)buf[i].od.ptr)->ver ;
  931.     }
  932.  
  933. /*    PolyPlane( ver, win, vary );*/
  934.     ret = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
  935.     ret->dtype = POLY_SIMPLE ;
  936.     ret->ver = *ver ;
  937.     PolyPlane( &ret->ver, win, vary );
  938.  
  939.     buf = StackAlloc( 1 );
  940.     buf->type = TYPE_OBJECT ;
  941.     buf->od.ptr = (Object*)ret ;
  942.     return RETURN_RETURN ;
  943. }
  944.  
  945. /*    ファイルから読み込む    */
  946. static    int        FuncReadFile( ident, args, buf )
  947. int        ident ;
  948. int        args ;
  949. DataStruct    *buf ;
  950. {
  951.     int        objno ;
  952.     int        mode = FILE_APPEND;
  953.  
  954.     if (args > 1) {
  955.         ArgCheck( "ReadFile", args, buf, TYPE_OBJECT, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
  956.         mode = buf[1].id.i;
  957.     } else {
  958.         ArgCheck( "ReadFile", args, buf, TYPE_OBJECT, TYPE_NOASN );
  959.     }
  960.     objno = PolyReadFile( ((StringClass*)buf[0].od.ptr)->str, mode);
  961.     StackPushInt( objno );
  962.  
  963.     return RETURN_RETURN ;
  964. }
  965.  
  966. /*    ファイルへ出力    */
  967. static    int        FuncWriteFile( ident, args, buf )
  968. int        ident ;
  969. int        args ;
  970. DataStruct    *buf ;
  971. {
  972.     int        mode ;
  973.  
  974.     if ( args == 1 )
  975.     {
  976.         ArgCheck( "WriteFile", args, buf, TYPE_INT, TYPE_NOASN );
  977.         mode = FILE_OVERWRITE ;
  978.     }
  979.     else
  980.     {
  981.         ArgCheck( "WriteFile", args, buf, TYPE_INT, TYPE_INT, TYPE_NOASN );
  982.         mode = buf[1].id.i ;
  983.     }
  984.     StackPushInt(PolyWriteFile( buf[0].id.i, mode ));
  985.     return RETURN_RETURN ;
  986. }
  987.  
  988. /*    ファイルから読み込む    */
  989. static    int        FuncFrmReadFile( ident, args, buf )
  990. int        ident ;
  991. int        args ;
  992. DataStruct    *buf ;
  993. {
  994.     int        objno ;
  995.     char *dir = NULL;
  996.     int        mode = FILE_APPEND;
  997.     int i;
  998.  
  999.     for (i = 1; i < 3 && i < args; i++) {
  1000.         if (buf[i].type & (TYPE_INT|TYPE_BOOLEAN)) {
  1001.             mode = buf[i].id.i;
  1002.         } else if (ObjectCheck(&buf[i], StringClassID) != FALSE) {
  1003.             dir = ((StringClass*)buf[1].od.ptr)->str;
  1004.         } else {
  1005.             ExecError( "引数の型が不正です。(FrmReadFile)" );
  1006.         }
  1007.     }
  1008. /*        ArgCheck( "FrmReadFile", args, buf, TYPE_OBJECT, TYPE_NOASN );*/
  1009.     objno = FrmReadFile( ((StringClass*)buf[0].od.ptr)->str, dir, mode );
  1010.     StackPushInt( objno );
  1011.  
  1012.     return RETURN_RETURN ;
  1013. }
  1014.  
  1015. /*    法線ベクトルをつける    */
  1016. static    int        FuncPolyShade( ident, args, buf )
  1017. int        ident ;
  1018. int        args ;
  1019. DataStruct    *buf ;
  1020. {
  1021.     ArgCheck( "PolyShade", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
  1022.     PolyShade( buf[0].id.i );
  1023.     return RETURN_VOID ;
  1024. }
  1025.  
  1026. /*    法線ベクトルを反転する    */
  1027. static    int        FuncPolyShadeInv( ident, args, buf )
  1028. int        ident ;
  1029. int        args ;
  1030. DataStruct    *buf ;
  1031. {
  1032.     ArgCheck( "PolyShadeInv", args, buf, TYPE_NOASN );
  1033.     PolyShadeInv();
  1034.     return RETURN_VOID ;
  1035. }
  1036.  
  1037. /*    マッピング座標をつける    */
  1038. static    int        FuncPolyMap( ident, args, buf )
  1039. int        ident ;
  1040. int        args ;
  1041. DataStruct    *buf ;
  1042. {
  1043.     Matrix    mat ;
  1044.     int u1, v1, u2, v2;
  1045.     u1 = v1 = -32767;
  1046.     u2 = v2 = 32767;
  1047.  
  1048.  
  1049.     if ( args == 1 )
  1050.     {
  1051.         ArgCheck( "PolyMap", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
  1052.         MatUnit( mat );
  1053.     }
  1054.     else if (args == 6) {
  1055.         ArgCheck( "PolyMap", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_OBJECT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_NOASN );
  1056.         MatCopy( mat, ((MatrixClass*)buf[1].od.ptr)->mat );
  1057.         u1 = buf[2].id.i;
  1058.         v1 = buf[3].id.i;
  1059.         u2 = buf[4].id.i;
  1060.         v2 = buf[5].id.i;
  1061.     } else {
  1062.         ArgCheck( "PolyMap", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_OBJECT, TYPE_NOASN );
  1063.         MatCopy( mat, ((MatrixClass*)buf[1].od.ptr)->mat );
  1064.     }
  1065.     PolyMap( buf[0].id.i, mat, u1, v1, u2, v2 );
  1066.  
  1067.     return RETURN_VOID ;
  1068. }
  1069.  
  1070.  
  1071. /*    頂点番号をずらす    */
  1072. static    int        FuncPolyShiftVertex( ident, args, buf )
  1073. int        ident ;
  1074. int        args ;
  1075. DataStruct    *buf ;
  1076. {
  1077.     ArgCheck( "PolyShiftVertex", args, buf, TYPE_INT, TYPE_NOASN );
  1078.     if (0 <= buf[0].id.i && buf[0].id.i < CurrentPoly->vers) {
  1079.         PolyShiftVertex(buf[0].id.i);
  1080.     }
  1081.     return RETURN_VOID;
  1082. }
  1083.  
  1084.  
  1085. /*    頂点番号を反転する    */
  1086. static    int        FuncPolyInvVertex( ident, args, buf )
  1087. int        ident ;
  1088. int        args ;
  1089. DataStruct    *buf ;
  1090. {
  1091.     ArgCheck( "PolyInvVertex", args, buf, TYPE_NOASN );
  1092.     PolyInvVertex();
  1093.     return RETURN_VOID;
  1094. }
  1095.  
  1096. /*    面の法線ベクトルを得る    */
  1097. static    int        FuncPolyVector( ident, args, buf )
  1098. int        ident ;
  1099. int        args ;
  1100. DataStruct    *buf ;
  1101. {
  1102.     int createflag = FALSE;
  1103.     VertexClass    *ver ;
  1104.     VectorClass    *v ;
  1105.  
  1106.     if (args > 0) {
  1107.         ArgCheck( "PolyVector", args, buf, TYPE_INT, TYPE_NOASN );
  1108.         if (buf[0].ld.l) {
  1109.             int coe[3];
  1110.             Coefficent(coe, CurrentPoly->ver, CurrentPoly->vers);
  1111.             CurrentPoly->vec[0] = coe[0];
  1112.             CurrentPoly->vec[1] = coe[1];
  1113.             CurrentPoly->vec[2] = coe[2];
  1114.         }
  1115.     } else {
  1116.         ArgCheck( "PolyVector", args, buf, TYPE_NOASN );
  1117.     }
  1118.     v = (VectorClass*)ObjectAlloc( sizeof( VectorClass ), VectorClassID );
  1119.     v->vec.x = CurrentPoly->vec[0];
  1120.     v->vec.y = CurrentPoly->vec[1];
  1121.     v->vec.z = CurrentPoly->vec[2];
  1122.     buf = StackAlloc( 1 );
  1123.     buf->type = TYPE_OBJECT ;
  1124.     buf->od.ptr = (Object*)v ;
  1125.     return RETURN_RETURN ;
  1126. }
  1127.  
  1128.