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 >
Wrap
C/C++ Source or Header
|
1996-06-05
|
30KB
|
1,128 lines
/*
* ポリゴンデータ制御
*
* Copyright T.Kobayashi 1994.8.9
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include "matrix.h"
#include "vector.h"
#include "matclass.h"
#include "strclass.h"
#include "ml.h"
#include "verconv.h"
#include "poly.h"
#include "view.h"
#include "menu.h"
#include "graph.h"
#include "input.h"
static char *SysConstName[] = {
"POLY_SIMPLE",
"POLY_SHADE",
"POLY_UV",
"POLY_UVSHADE",
"SELECT_UPDATE",
"SELECT_AND",
"SELECT_OR",
"SELECT_XOR",
"SELECT_ALL",
"SELECT_SUB",
"FILE_OVERWRITE",
"FILE_APPEND",
"OBJ_CREATE",
"OBJ_APPEND",
"ATTR_CREATE",
"ATTR_APPEND",
"VERTEX_MIN",
"VERTEX_MAX",
"NORMAL_OFF",
"NORMAL_ON",
"NORMAL_CREATE",
NULL
};
static IntData SysConst[] = {
{ TYPE_INT, 0, POLY_SIMPLE, },
{ TYPE_INT, 0, POLY_SHADE, },
{ TYPE_INT, 0, POLY_UV, },
{ TYPE_INT, 0, POLY_UVSHADE, },
{ TYPE_INT, 0, SELECT_UPDATE, },
{ TYPE_INT, 0, SELECT_AND, },
{ TYPE_INT, 0, SELECT_OR, },
{ TYPE_INT, 0, SELECT_XOR, },
{ TYPE_INT, 0, SELECT_ALL, },
{ TYPE_INT, 0, SELECT_SUB, },
{ TYPE_INT, 0, FILE_OVERWRITE, },
{ TYPE_INT, 0, FILE_APPEND, },
{ TYPE_INT, 0, FILE_OVERWRITE, },
{ TYPE_INT, 0, FILE_APPEND, },
{ TYPE_INT, 0, FILE_OVERWRITE, },
{ TYPE_INT, 0, FILE_APPEND, },
{ TYPE_INT, 0, -32767, },
{ TYPE_INT, 0, 32767, },
{ TYPE_INT, 0, SHADE_OFF, },
{ TYPE_INT, 0, SHADE_ON, },
{ TYPE_INT, 0, SHADE_CREATE, },
};
static int MatrixClassID ;
static int StringClassID ;
int VectorClassID ;
int VertexClassID ;
static VertexClass *StackAllocVertex( DataStruct* );
static int VertexEqual( int, int, DataStruct* );
static int ToString( int, int, DataStruct* );
static int CreateVertex( int, int, DataStruct* );
static int VertexPlus( int, int, DataStruct* );
static int VertexMinus( int, int, DataStruct* );
static int VertexMult( int, int, DataStruct* );
static int GetPosition( int, int, DataStruct* );
static int GetVector( int, int, DataStruct* );
static int GetMapping( int, int, DataStruct* );
static int SetVertex( int, int, DataStruct* );
static int GetVertex( int, int, DataStruct* );
static int InsVertex( int, int, DataStruct* );
static int DelVertex( int, int, DataStruct* );
static int FuncPolyVers( int, int, DataStruct* );
static int FuncPolyType( int, int, DataStruct* );
static int FuncPolyAttr( int, int, DataStruct* );
static int FuncPolyObj( int, int, DataStruct* );
static int FuncPolyAppend( int, int, DataStruct* );
static int FuncPolyLoad( int, int, DataStruct* );
static int FuncPolyLoadInit( int, int, DataStruct* );
static int FuncPolySave( int, int, DataStruct* );
static int FuncPolyDelete( int, int, DataStruct* );
static int FuncPolyMove( int, int, DataStruct* );
static int FuncPolyInvisible( int, int, DataStruct* );
static int FuncPolyVertex( int, int, DataStruct* );
static int FuncPolyPlane( int, int, DataStruct* );
static int FuncReadFile( int, int, DataStruct* );
static int FuncFrmReadFile( int, int, DataStruct* );
static int FuncWriteFile( int, int, DataStruct* );
static int FuncPolyShade( int, int, DataStruct* );
static int FuncPolyShadeInv( int, int, DataStruct* );
static int FuncPolyMap( int, int, DataStruct* );
static int FuncPolyShiftVertex( int, int, DataStruct* );
static int FuncPolyInvVertex( int, int, DataStruct* );
static int FuncVertexLength( int, int, DataStruct* );
static int FuncVertexLength2( int, int, DataStruct* );
static int FuncPolyVector(int, int, DataStruct* );
void PolyLibInit()
{
int i ;
StringClassID = ClassName( "String" );
MatrixClassID = ClassName( "Matrix" );
VectorClassID = ClassName( "Vector" );
VertexClassID = NewClass( "Vertex", 0 );
for( i = 0 ; SysConstName[i] != NULL ; i++ )
NewConst( SysConstName[i], (DataStruct*)&SysConst[i] );
NewOperator( VertexClassID, OPE_PLUS, VertexPlus );
NewOperator( VertexClassID, OPE_MINUS, VertexMinus );
NewOperator( VertexClassID, OPE_MULT, VertexMult);
NewOperator( VertexClassID, OPE_EQ, VertexEqual );
NewOperator( VertexClassID, OPE_NOTEQ, VertexEqual );
NewFunction( VertexClassID, "tostring", ToString );
NewFunction( 0, "Vertex", CreateVertex );
NewFunction( VectorClassID, "Vertex", CreateVertex );
NewFunction( VertexClassID, "Position", GetPosition );
NewFunction( VertexClassID, "Vector", GetVector );
NewFunction( VertexClassID, "Mapping", GetMapping );
NewFunction( VertexClassID, "VertexLength", FuncVertexLength );
NewFunction( VertexClassID, "VertexLength2", FuncVertexLength2 );
NewFunction( VertexClassID, "PolySetVertex", SetVertex );
NewFunction( 0, "PolyGetVertex", GetVertex );
NewFunction( VertexClassID, "PolyInsVertex", InsVertex);
NewFunction( 0, "PolyDelVertex", DelVertex);
NewFunction( 0, "PolyVertexs", FuncPolyVers );
NewFunction( 0, "PolyType", FuncPolyType );
NewFunction( 0, "PolyAttr", FuncPolyAttr );
NewFunction( 0, "PolyObj", FuncPolyObj );
NewFunction( 0, "PolyAppend", FuncPolyAppend );
NewFunction( 0, "PolyLoad", FuncPolyLoad );
NewFunction( 0, "PolyLoadInit", FuncPolyLoadInit );
NewFunction( 0, "PolySave", FuncPolySave );
NewFunction( 0, "PolyDelete", FuncPolyDelete );
NewFunction( MatrixClassID, "PolyMove", FuncPolyMove );
NewFunction( 0, "PolyInvisible", FuncPolyInvisible );
NewFunction( VertexClassID, "PolyVertex", FuncPolyVertex );
NewFunction( VertexClassID, "PolyPlane", FuncPolyPlane );
NewFunction( StringClassID, "ReadFile", FuncReadFile );
NewFunction( StringClassID, "ObjReadFile", FuncReadFile );
NewFunction( StringClassID, "FrmReadFile", FuncFrmReadFile );
NewFunction( 0, "WriteFile", FuncWriteFile );
NewFunction( 0, "ObjWriteFile", FuncWriteFile );
NewFunction( 0, "PolyShade", FuncPolyShade );
NewFunction( 0, "PolyShadeInv", FuncPolyShadeInv );
NewFunction( 0, "PolyMap", FuncPolyMap );
NewFunction( 0, "PolyShiftVertex", FuncPolyShiftVertex);
NewFunction( 0, "PolyInvVertex", FuncPolyInvVertex);
NewFunction( 0, "PolyVector", FuncPolyVector);
SelectLibInit();
AttrLibInit();
ObjLibInit();
}
static VertexClass *StackAllocVertex( buf )
DataStruct *buf ;
{
DataStruct *top ;
top = StackAlloc( 1 );
top->type = TYPE_OBJECT ;
top->od.ptr = ObjectDup( buf->od.ptr );
return (VertexClass*)top->od.ptr ;
}
static int VertexEqual( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int eq ;
Vertex *v1, *v2 ;
if ( ObjectCheck( &buf[1], VertexClassID ) == FALSE )
ExecError( "演算の型が不正です" );
v1 = &((VertexClass*)buf[0].od.ptr)->ver ;
v2 = &((VertexClass*)buf[1].od.ptr)->ver ;
eq = ( ( v1->x == v2->x ) && ( v1->y == v2->y ) && ( v1->z == v2->z ) );
if ( ident == OPE_EQ )
StackPushBoolean( eq );
else
StackPushBoolean( !eq );
return RETURN_RETURN ;
}
static int ToString( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *ver ;
char str[256], substr[128] ;
assert( buf->type == TYPE_OBJECT );
ver = (VertexClass*)buf->od.ptr ;
sprintf( str, "( %-4d, %-4d, %-4d )", ver->ver.x, ver->ver.y, ver->ver.z );
if ( ver->dtype & POLY_SHADE )
{
Vector v ;
toVector( &v, (double)ver->ver.vx, (double)ver->ver.vy, (double)ver->ver.vz );
sprintf( substr, " ( %-8.5g, %-8.5g, %-8.5g )", v.x, v.y, v.z );
strcat( str, substr );
}
if ( ver->dtype & POLY_UV )
{
sprintf( substr, " ( %-4d, %-4d )", ver->ver.u, ver->ver.v );
strcat( str, substr );
}
buf = StackAlloc( 1 );
StringToObject( buf, str );
return RETURN_RETURN ;
}
/* 頂点データの設定 */
static int CreateVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
extern int ToVector(int args, DataStruct *buf, Vector* vec);
VertexClass *ver ;
VectorClass *v ;
Vector vec;
int c, count = 0;
if ( args < 1 )
ExecError( "引数の数が違います。(Vertex)" );
ver = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
ver->dtype = POLY_SIMPLE ;
memset(&ver->ver, 0, sizeof(Vertex));
if ((count = ToVector(args, buf, &vec)) != 0) {
ver->ver.x = (int)vec.x;
ver->ver.y = (int)vec.y;
ver->ver.z = (int)vec.z;
} else {
ExecError( "引数の型が不正です。(Vertex)" );
}
if (args - count > 0) {
ver->dtype = POLY_SHADE ;
if ((c = ToVector(args-count, buf+count, &vec)) != 0) {
ver->ver.vx = (int)vec.x;
ver->ver.vy = (int)vec.y;
ver->ver.vz = (int)vec.z;
count += c;
} else {
ExecError( "引数の型が不正です。(Vertex)" );
}
}
if (args - count > 0) {
ver->dtype = POLY_UVSHADE ;
if ( buf[count].type == TYPE_OBJECT ) {
/* Vectorクラスからの変換 */
if ( ! ObjectCheck( &buf[0], VectorClassID ) )
ExecError( "引数の型が不正です。(Vertex)" );
v = (VectorClass*)buf[0].od.ptr ;
ver->ver.u = (int)v->vec.x ;
ver->ver.v = (int)v->vec.y ;
} else if (buf[count].type == TYPE_ARRAY) {
DataStruct *abuf;
abuf = buf[count].ad.ary;
if (buf[count].ad.size >= 2
&& (abuf[0].type & (TYPE_INT|TYPE_REAL))
&& (abuf[1].type & (TYPE_INT|TYPE_REAL))) {
ver->ver.u = ToInt(&abuf[0]);
ver->ver.v = ToInt(&abuf[1]);
} else {
ExecError( "引数の型が不正です。(Vertex)" );
}
} else if (args-count >= 2
&& (buf[count ].type & (TYPE_INT|TYPE_REAL))
&& (buf[count+1].type & (TYPE_INT|TYPE_REAL))) {
ver->ver.u = ToInt( &buf[count] );
ver->ver.v = ToInt( &buf[count+1] );
} else {
ExecError( "引数の型が不正です。(Vertex)" );
}
}
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)ver ;
return RETURN_RETURN ;
}
static int VertexPlus( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *ver, *ver1 ;
int x, y, z, vx, vy, vz, u, v ;
if ( ConvVertex( &x, &y, &z, &vx, &vy, &vz, &u, &v, buf+1 ) )
{
ver = StackAllocVertex( &buf[0] );
ver1 = (VertexClass*)buf[0].od.ptr ;
ver->ver.x = ver1->ver.x + x ;
ver->ver.y = ver1->ver.y + y ;
ver->ver.z = ver1->ver.z + z ;
ver->ver.vx = ver1->ver.vx + vx ;
ver->ver.vy = ver1->ver.vy + vy ;
ver->ver.vz = ver1->ver.vz + vz ;
ver->ver.u = ver1->ver.u + u ;
ver->ver.v = ver1->ver.v + v ;
}
else
ExecError( "型が不正です。(演算子+)" );
return RETURN_RETURN ;
}
static int VertexMinus( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *ver, *ver1 ;
int x, y, z, vx, vy, vz, u, v ;
if ( ConvVertex( &x, &y, &z, &vx, &vy, &vz, &u, &v, buf+1 ) )
{
ver = StackAllocVertex( &buf[0] );
ver1 = (VertexClass*)buf[0].od.ptr ;
ver->ver.x = ver1->ver.x - x ;
ver->ver.y = ver1->ver.y - y ;
ver->ver.z = ver1->ver.z - z ;
ver->ver.vx = ver1->ver.vx - vx ;
ver->ver.vy = ver1->ver.vy - vy ;
ver->ver.vz = ver1->ver.vz - vz ;
ver->ver.u = ver1->ver.u - u ;
ver->ver.v = ver1->ver.v - v ;
}
else
ExecError( "型が不正です。(演算子-)" );
return RETURN_RETURN ;
}
static int VertexMult( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *ver, *ver1 ;
#if 0
int i ;
float r[3] ;
#endif
MatrixClass *mat2 ;
Matrix matit;
int imat[5][3], imatit[5][3] ;
int x, y, z;
if ( ObjectCheck( &buf[1], MatrixClassID ) )
{
ver = StackAllocVertex( &buf[0] );
ver1 = (VertexClass*)buf[0].od.ptr ;
mat2 = (MatrixClass*)buf[1].od.ptr ;
#if 0
for( i = 0 ; i < 3 ; i++ )
{
r[i] = (float)ver1->ver.x * mat2->mat[0][i] +
(float)ver1->ver.y * mat2->mat[1][i] +
(float)ver1->ver.z * mat2->mat[2][i] +
mat2->mat[3][i] ;
}
ver->ver.x = r[0] ;
ver->ver.y = r[1] ;
ver->ver.z = r[2] ;
for( i = 0 ; i < 3 ; i++ )
{
r[i] = (float)ver1->ver.vx * mat2->mat[0][i] +
(float)ver1->ver.vy * mat2->mat[1][i] +
(float)ver1->ver.vz * mat2->mat[2][i] +
mat2->mat[3][i] ;
}
ver->ver.vx = r[0] ;
ver->ver.vy = r[1] ;
ver->ver.vz = r[2] ;
#else
MatCopy(matit, mat2->mat);
MatInv(matit);
MatTra(matit);
MatToInt( imat, mat2->mat );
MatToInt( imatit, matit );
x = (int)ver1->ver.x * imat[0][0]
+ (int)ver1->ver.y * imat[1][0]
+ (int)ver1->ver.z * imat[2][0]
+ imat[4][0];
y = (int)ver1->ver.x * imat[0][1]
+ (int)ver1->ver.y * imat[1][1]
+ (int)ver1->ver.z * imat[2][1]
+ imat[4][1];
z = (int)ver1->ver.x * imat[0][2]
+ (int)ver1->ver.y * imat[1][2]
+ (int)ver1->ver.z * imat[2][2]
+ imat[4][2];
#if 0
if (x > 0) {
ver->ver.x = imat[3][0] + (short)( ( x + 32767) >> 16 );
} else {
ver->ver.x = imat[3][0] - (short)( (-x + 32767) >> 16 );
}
if (y > 0) {
ver->ver.y = imat[3][1] + (short)( ( y + 32767) >> 16 );
} else {
ver->ver.y = imat[3][1] - (short)( (-y + 32767) >> 16 );
}
if (z > 0) {
ver->ver.z = imat[3][2] + (short)( ( z + 32767) >> 16 );
} else {
ver->ver.z = imat[3][2] - (short)( (-z + 32767) >> 16 );
}
#else
ver->ver.x = (short)imat[3][0] + (short)( x >> 16 );
ver->ver.y = (short)imat[3][1] + (short)( y >> 16 );
ver->ver.z = (short)imat[3][2] + (short)( z >> 16 );
#endif
x = (int)ver1->ver.vx * imatit[0][0]
+ (int)ver1->ver.vy * imatit[1][0]
+ (int)ver1->ver.vz * imatit[2][0];
y = (int)ver1->ver.vx * imatit[0][1]
+ (int)ver1->ver.vy * imatit[1][1]
+ (int)ver1->ver.vz * imatit[2][1];
z = (int)ver1->ver.vx * imatit[0][2]
+ (int)ver1->ver.vy * imatit[1][2]
+ (int)ver1->ver.vz * imatit[2][2];
ver->ver.vx = (short)( x >> 16 );
ver->ver.vy = (short)( y >> 16 );
ver->ver.vz = (short)( z >> 16 );
#endif
}
else
{
ExecError( "型が不正です。(演算子*)" );
}
return RETURN_RETURN ;
}
/* 頂点データを得る */
static int GetPosition( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *ver ;
VectorClass *v ;
if ( args == 1 )
{
v = (VectorClass*)ObjectAlloc( sizeof( VectorClass ), VectorClassID );
ver = (VertexClass*)buf[0].od.ptr ;
v->vec.x = ver->ver.x ;
v->vec.y = ver->ver.y ;
v->vec.z = ver->ver.z ;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)v ;
return RETURN_RETURN ;
}
else
{
ArgCheck( "Position", args, buf, TYPE_OBJECT, TYPE_ARRAY, TYPE_NOASN );
if ( buf[1].ad.size < 3 )
ExecError( "引数配列のサイズが不正です。( Vertex:Position )" );
ver = (VertexClass*)buf[0].od.ptr ;
buf = buf[1].ad.ary ;
buf[0].type = buf[1].type = buf[2].type = TYPE_INT ;
buf[0].id.i = ver->ver.x ;
buf[1].id.i = ver->ver.y ;
buf[2].id.i = ver->ver.z ;
return RETURN_VOID ;
}
}
/* 法線ベクトルを得る */
static int GetVector( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *ver ;
VectorClass *v ;
if ( args == 1 )
{
v = (VectorClass*)ObjectAlloc( sizeof( VectorClass ), VectorClassID );
ver = (VertexClass*)buf[0].od.ptr ;
v->vec.x = ver->ver.vx ;
v->vec.y = ver->ver.vy ;
v->vec.z = ver->ver.vz ;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)v ;
return RETURN_RETURN ;
}
else
{
ArgCheck( "Vector", args, buf, TYPE_OBJECT, TYPE_ARRAY, TYPE_NOASN );
if ( buf[1].ad.size < 3 )
ExecError( "引数配列のサイズが不正です。( Vertex:Vector )" );
ver = (VertexClass*)buf[0].od.ptr ;
buf = buf[1].ad.ary ;
buf[0].type = buf[1].type = buf[2].type = TYPE_INT ;
buf[0].id.i = ver->ver.vx ;
buf[1].id.i = ver->ver.vy ;
buf[2].id.i = ver->ver.vz ;
return RETURN_VOID ;
}
}
/* マッピング座標を得る */
static int GetMapping( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *ver ;
ArgCheck( "Mapping", args, buf, TYPE_OBJECT, TYPE_ARRAY, TYPE_NOASN );
if ( buf[1].ad.size < 2 )
ExecError( "引数配列のサイズが不正です。( Vertex:Mapping )" );
ver = (VertexClass*)buf[0].od.ptr ;
buf = buf[1].ad.ary ;
buf[0].type = buf[1].type = TYPE_INT ;
buf[0].id.i = ver->ver.u ;
buf[1].id.i = ver->ver.v ;
return RETURN_VOID ;
}
/* 頂点間の距離を返す */
static int FuncVertexLength( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *v1, *v2;
int lx, ly, lz;
ArgCheck( "PolyVertexLength", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
if (ObjectCheck(&buf[0], VertexClassID) == FALSE
|| ObjectCheck(&buf[1], VertexClassID) == FALSE) {
ExecError( "2番目の引数の型が不正です。(VertexLength)" );
}
v1 = (VertexClass*)buf[0].od.ptr;
v2 = (VertexClass*)buf[1].od.ptr;
lx = v1->ver.x - v2->ver.x;
ly = v1->ver.y - v2->ver.y;
lz = v1->ver.z - v2->ver.z;
StackPushInt((int)sqrt((double)(lx*lx+ly*ly+lz*lz)));
return RETURN_RETURN;
}
/* 頂点間の距離を返す */
static int FuncVertexLength2( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *v1, *v2;
int lx, ly, lz;
ArgCheck( "PolyVertex2Length", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
if (ObjectCheck(&buf[0], VertexClassID) == FALSE
|| ObjectCheck(&buf[1], VertexClassID) == FALSE) {
ExecError( "2番目の引数の型が不正です。(VertexLength2)" );
}
v1 = (VertexClass*)buf[0].od.ptr;
v2 = (VertexClass*)buf[1].od.ptr;
lx = v1->ver.x - v2->ver.x;
ly = v1->ver.y - v2->ver.y;
lz = v1->ver.z - v2->ver.z;
StackPushInt(lx*lx+ly*ly+lz*lz);
return RETURN_RETURN;
}
/* 頂点データをカレントポリゴンに */
static int SetVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
VertexClass *ver ;
ArgCheck( "PolySetVertex", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
ver = (VertexClass*)buf[0].od.ptr ;
n = buf[1].id.i ;
if ( n < 0 || MaxVertex <= n )
ExecError( "2番目の引数の値が不正です。(SetVertex)" );
CurrentPoly->ver[n] = ver->ver ;
return RETURN_VOID ;
}
/* カレントポリゴンの頂点データを取り出す */
static int GetVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
VertexClass *ver ;
ArgCheck( "PolyGetVertex", args, buf, TYPE_INT, TYPE_NOASN );
ver = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
n = buf[0].id.i ;
if ( n < 0 || MaxVertex <= n )
ExecError( "1番目の引数の値が不正です。(PolyGetVertex)" );
ver->dtype = CurrentPoly->type ;
ver->ver = CurrentPoly->ver[n] ;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)ver ;
return RETURN_RETURN ;
}
/* 頂点データをカレントポリゴンに挿入 */
static int InsVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
VertexClass *ver ;
ArgCheck( "PolyInsVertex", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
ver = (VertexClass*)buf[0].od.ptr ;
n = buf[1].id.i ;
if ( n < 0 || MaxVertex-1 <= n || n > CurrentPoly->vers)
ExecError( "2番目の引数の値が不正です。(InsVertex)" );
if (n < CurrentPoly->vers) {
memmove(&CurrentPoly->ver[n+1],
&CurrentPoly->ver[n],
sizeof(Vertex) * (CurrentPoly->vers - n));
}
CurrentPoly->ver[n] = ver->ver ;
CurrentPoly->vers++;
return RETURN_VOID ;
}
/* カレントポリゴンの頂点データを削除 */
static int DelVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
ArgCheck( "PolyDelVertex", args, buf, TYPE_INT, TYPE_NOASN );
n = buf[0].id.i ;
if ( n < 0 || MaxVertex <= n || n >= CurrentPoly->vers)
ExecError( "1番目の引数の値が不正です。(PolyGetVertex)" );
if (n < CurrentPoly->vers-1) {
memmove(&CurrentPoly->ver[n],
&CurrentPoly->ver[n+1],
sizeof(Vertex) * (CurrentPoly->vers - n - 1));
}
CurrentPoly->vers--;
return RETURN_VOID ;
}
/* カレントポリゴンの頂点数を設定する */
static int FuncPolyVers( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if ( args >= 1 )
{
ArgCheck( "PolyVertexs", args, buf, TYPE_INT, TYPE_NOASN );
CurrentPoly->vers = buf[0].id.i ;
}
StackPushInt( CurrentPoly->vers );
return RETURN_RETURN ;
}
/* カレントポリゴンのデータタイプを設定する */
static int FuncPolyType( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if ( args >= 1 )
{
ArgCheck( "PolyType", args, buf, TYPE_INT, TYPE_NOASN );
CurrentPoly->type = buf[0].id.i ;
}
StackPushInt( CurrentPoly->type );
return RETURN_RETURN ;
}
/* カレントポリゴンのアトリビュートを設定する */
static int FuncPolyAttr( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if ( args >= 1 )
{
ArgCheck( "PolyAttr", args, buf, TYPE_INT, TYPE_NOASN );
CurrentPoly->atr = buf[0].id.i ;
}
StackPushInt( CurrentPoly->atr );
return RETURN_RETURN ;
}
/* カレントポリゴンのオブジェクト番号を設定する */
static int FuncPolyObj( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if ( args >= 1 )
{
ArgCheck( "PolyObj", args, buf, TYPE_INT, TYPE_NOASN );
CurrentPoly->obj = buf[0].id.i ;
}
StackPushInt( CurrentPoly->obj );
return RETURN_RETURN ;
}
/* カレントポリゴンを登録 */
static int FuncPolyAppend( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
CurrentPoly->select = OFF ;
if (args >= 1) {
ArgCheck( "PolyAppend", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
CurrentPoly->select = (buf[0].id.i ? ON : OFF) ;
}
PolyAppend();
return RETURN_VOID ;
}
/* 選択されているポリゴンを一時バッファに取り込む */
static int FuncPolyLoad( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
#if 0
StackPushBoolean( PolyLoad() );
#else
if (args == 0) {
StackPushInt( (int)PolyLoad() );
} else {
ArgCheck( "PolyLoad", args, buf, TYPE_INT, TYPE_NOASN );
StackPushInt((int)PolyLoadPtr((void*)buf[0].id.i));
}
#endif
return RETURN_RETURN ;
}
/* 一時バッファの初期化 */
static int FuncPolyLoadInit( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
PolyPtr = NULL;
return RETURN_VOID ;
}
/* 一時バッファからポリゴンを書き戻す */
static int FuncPolySave( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (PolyPtr == NULL) {
ExecError( "PolyLoadされていません。(Vertex:PolySave)" );
}
PolySave();
return RETURN_VOID ;
}
/* セレクトされているポリゴン削除する */
static int FuncPolyDelete( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
PolyDelete();
return RETURN_VOID ;
}
/* セレクトされているポリゴンを移動する */
static int FuncPolyMove( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "PolyMove", args, buf, TYPE_OBJECT, TYPE_NOASN );
PolyMove( ((MatrixClass*)buf[0].od.ptr)->mat );
return RETURN_VOID ;
}
/* セレクトされていないポリゴンを不可視属性にする */
static int FuncPolyInvisible( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "PolyInvisible", args, buf, TYPE_BOOLEAN|TYPE_INT, TYPE_NOASN );
PolyInvisible( buf[0].id.i );
return RETURN_VOID ;
}
/* 最近頂点を検索 */
static int FuncPolyVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int view;
Vertex *ver ;
VertexClass *ret ;
if (args == 2) {
ArgCheck( "PolyVertex", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
view = buf[1].id.i;
} else {
ArgCheck( "PolyVertex", args, buf, TYPE_OBJECT, TYPE_NOASN );
view = 0;
}
ver = PolyVertex( &((VertexClass*)buf[0].od.ptr)->ver, view );
ret = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
ret->dtype = POLY_SIMPLE ;
memset(&ret->ver, 0, sizeof(Vertex));
if ( ver != NULL )
ret->ver = *ver ;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)ret ;
return RETURN_RETURN ;
}
/* 平面投射 */
static int FuncPolyPlane( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int i, win ;
Vertex *ver, vary[3] ;
VertexClass *ret ;
#if 0
ArgCheck( "PolyPlane", args, buf, TYPE_OBJECT, TYPE_INT,
TYPE_OBJECT, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
#endif
if (buf[0].type != TYPE_OBJECT || buf[1].type != TYPE_INT) {
ExecError( "引数の型が不正です。(Vertex:PolyPlane)" );
}
ver = &((VertexClass*)buf[0].od.ptr)->ver ;
win = buf[1].id.i ;
buf = &buf[2];
args -= 2;
if (buf->type == TYPE_ARRAY) {
args = buf->ad.size;
buf = buf->ad.ary;
}
if (args != 3) {
ExecError( "引数の型が不正です。(Vertex:PolyPlane)" );
}
for( i = 0 ; i < 3 ; i++ )
{
if ( ObjectCheck( &buf[i], VertexClassID ) == FALSE )
ExecError( "引数の型が不正です。(Vertex:PolyPlane)" );
vary[i] = ((VertexClass*)buf[i].od.ptr)->ver ;
}
/* PolyPlane( ver, win, vary );*/
ret = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
ret->dtype = POLY_SIMPLE ;
ret->ver = *ver ;
PolyPlane( &ret->ver, win, vary );
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)ret ;
return RETURN_RETURN ;
}
/* ファイルから読み込む */
static int FuncReadFile( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int objno ;
int mode = FILE_APPEND;
if (args > 1) {
ArgCheck( "ReadFile", args, buf, TYPE_OBJECT, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
mode = buf[1].id.i;
} else {
ArgCheck( "ReadFile", args, buf, TYPE_OBJECT, TYPE_NOASN );
}
objno = PolyReadFile( ((StringClass*)buf[0].od.ptr)->str, mode);
StackPushInt( objno );
return RETURN_RETURN ;
}
/* ファイルへ出力 */
static int FuncWriteFile( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int mode ;
if ( args == 1 )
{
ArgCheck( "WriteFile", args, buf, TYPE_INT, TYPE_NOASN );
mode = FILE_OVERWRITE ;
}
else
{
ArgCheck( "WriteFile", args, buf, TYPE_INT, TYPE_INT, TYPE_NOASN );
mode = buf[1].id.i ;
}
StackPushInt(PolyWriteFile( buf[0].id.i, mode ));
return RETURN_RETURN ;
}
/* ファイルから読み込む */
static int FuncFrmReadFile( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int objno ;
char *dir = NULL;
int mode = FILE_APPEND;
int i;
for (i = 1; i < 3 && i < args; i++) {
if (buf[i].type & (TYPE_INT|TYPE_BOOLEAN)) {
mode = buf[i].id.i;
} else if (ObjectCheck(&buf[i], StringClassID) != FALSE) {
dir = ((StringClass*)buf[1].od.ptr)->str;
} else {
ExecError( "引数の型が不正です。(FrmReadFile)" );
}
}
/* ArgCheck( "FrmReadFile", args, buf, TYPE_OBJECT, TYPE_NOASN );*/
objno = FrmReadFile( ((StringClass*)buf[0].od.ptr)->str, dir, mode );
StackPushInt( objno );
return RETURN_RETURN ;
}
/* 法線ベクトルをつける */
static int FuncPolyShade( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "PolyShade", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
PolyShade( buf[0].id.i );
return RETURN_VOID ;
}
/* 法線ベクトルを反転する */
static int FuncPolyShadeInv( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "PolyShadeInv", args, buf, TYPE_NOASN );
PolyShadeInv();
return RETURN_VOID ;
}
/* マッピング座標をつける */
static int FuncPolyMap( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
Matrix mat ;
int u1, v1, u2, v2;
u1 = v1 = -32767;
u2 = v2 = 32767;
if ( args == 1 )
{
ArgCheck( "PolyMap", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
MatUnit( mat );
}
else if (args == 6) {
ArgCheck( "PolyMap", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_OBJECT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_NOASN );
MatCopy( mat, ((MatrixClass*)buf[1].od.ptr)->mat );
u1 = buf[2].id.i;
v1 = buf[3].id.i;
u2 = buf[4].id.i;
v2 = buf[5].id.i;
} else {
ArgCheck( "PolyMap", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_OBJECT, TYPE_NOASN );
MatCopy( mat, ((MatrixClass*)buf[1].od.ptr)->mat );
}
PolyMap( buf[0].id.i, mat, u1, v1, u2, v2 );
return RETURN_VOID ;
}
/* 頂点番号をずらす */
static int FuncPolyShiftVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "PolyShiftVertex", args, buf, TYPE_INT, TYPE_NOASN );
if (0 <= buf[0].id.i && buf[0].id.i < CurrentPoly->vers) {
PolyShiftVertex(buf[0].id.i);
}
return RETURN_VOID;
}
/* 頂点番号を反転する */
static int FuncPolyInvVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "PolyInvVertex", args, buf, TYPE_NOASN );
PolyInvVertex();
return RETURN_VOID;
}
/* 面の法線ベクトルを得る */
static int FuncPolyVector( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int createflag = FALSE;
VertexClass *ver ;
VectorClass *v ;
if (args > 0) {
ArgCheck( "PolyVector", args, buf, TYPE_INT, TYPE_NOASN );
if (buf[0].ld.l) {
int coe[3];
Coefficent(coe, CurrentPoly->ver, CurrentPoly->vers);
CurrentPoly->vec[0] = coe[0];
CurrentPoly->vec[1] = coe[1];
CurrentPoly->vec[2] = coe[2];
}
} else {
ArgCheck( "PolyVector", args, buf, TYPE_NOASN );
}
v = (VectorClass*)ObjectAlloc( sizeof( VectorClass ), VectorClassID );
v->vec.x = CurrentPoly->vec[0];
v->vec.y = CurrentPoly->vec[1];
v->vec.z = CurrentPoly->vec[2];
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)v ;
return RETURN_RETURN ;
}