home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
VIEWLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-05
|
17KB
|
691 lines
/*
* 画面制御
*
* Copyright T.Kobayashi 1994.6.26
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "poly.h"
#include "view.h"
#include "graph.h"
#include "input.h"
#include "menu.h"
#include "ml.h"
#include "matclass.h"
#include "strclass.h"
#include "verconv.h"
static char *SysConstName[] = {
"WIN_XY",
"WIN_YZ",
"WIN_ZX",
"WIN_PERS",
"WIN_ALL",
"LINE_OR",
"LINE_XOR",
"OVERWRITE",
"CLEAR",
NULL
};
static IntData SysConst[] = {
{ TYPE_INT, 0, VIEW_XY, },
{ TYPE_INT, 0, VIEW_YZ, },
{ TYPE_INT, 0, VIEW_ZX, },
{ TYPE_INT, 0, VIEW_PERS, },
{ TYPE_INT, 0, VIEW_ALL, },
{ TYPE_INT, 0, OR_COLOR, },
{ TYPE_INT, 0, CURSOR_COLOR, },
{ TYPE_BOOLEAN, 0, FALSE, },
{ TYPE_BOOLEAN, 0, TRUE, },
};
static int MatrixClassID ;
static int VectorClassID ;
static int StringClassID ;
static int FuncMouseWindow( int, int, DataStruct* );
static int FuncGet3DCursor( int, int, DataStruct* );
static int Set3DCursor( int, int, DataStruct* );
static int Get2DCursor( int, int, DataStruct* );
static int Update( int, int, DataStruct* );
static int UpdatePers( int, int, DataStruct* );
static int DrawCurrent( int, int, DataStruct* );
static int DrawLine( int, int, DataStruct* );
static int DrawLine2D( int, int, DataStruct* );
static int DrawBox( int, int, DataStruct* );
static int DrawBox2D( int, int, DataStruct* );
static int Clear( int, int, DataStruct* );
static int SetWindow( int, int, DataStruct* );
static int SetVisibleVector( int, int, DataStruct* );
static int SetVisiblePolyVector( int, int, DataStruct* );
static int SetVisibleVertex( int, int, DataStruct* );
static int SetCenter( int, int, DataStruct* );
static int SetZoom( int, int, DataStruct* );
static int SetPers( int, int, DataStruct* );
static int SetGrid( int, int, DataStruct* );
static int SetConv( int, int, DataStruct* );
static int DrawText( int, int, DataStruct* );
static int FuncPersAngle( int, int, DataStruct* );
static int FuncViewWidth( int, int, DataStruct* );
static int FuncViewHeight( int, int, DataStruct* );
static int FuncDrawInvisible( int, int, DataStruct* );
static int FuncViewCursor( int, int, DataStruct* );
static int FuncDrawFrontOnly( int, int, DataStruct* );
void ViewLibInit()
{
int i ;
MatrixClassID = ClassName( "Matrix" );
VectorClassID = ClassName( "Vector" );
StringClassID = ClassName( "String" );
for( i = 0 ; SysConstName[i] != NULL ; i++ )
{
NewConst( SysConstName[i], (DataStruct*)&SysConst[i] );
}
NewFunction( 0, "MouseWindow", FuncMouseWindow );
NewFunction( 0, "Cursor", FuncGet3DCursor );
NewFunction( VertexClassID, "Cursor", Set3DCursor );
NewFunction( VectorClassID, "Cursor", Set3DCursor );
NewFunction( 0, "Cursor2D", Get2DCursor );
NewFunction( 0, "Update", Update );
NewFunction( 0, "UpdatePers", UpdatePers );
NewFunction( 0, "DrawCurrent", DrawCurrent );
NewFunction( VertexClassID, "DrawLine", DrawLine );
NewFunction( 0, "DrawLine2D", DrawLine2D );
NewFunction( VertexClassID, "DrawBox", DrawBox );
NewFunction( 0, "DrawBox2D", DrawBox2D );
NewFunction( 0, "Clear", Clear );
NewFunction( 0, "SetWindow", SetWindow );
NewFunction( 0, "Window", SetWindow );
NewFunction( 0, "VisibleVector", SetVisibleVector );
NewFunction( 0, "VisiblePolyVector", SetVisiblePolyVector );
NewFunction( 0, "VisibleVertex", SetVisibleVertex );
NewFunction( 0, "SetCenter", SetCenter );
NewFunction( 0, "Center", SetCenter );
NewFunction( 0, "SetZoom", SetZoom );
NewFunction( MatrixClassID, "SetPers", SetPers );
NewFunction( 0, "SetGrid", SetGrid );
NewFunction( MatrixClassID, "SetConv", SetConv );
NewFunction( StringClassID, "DrawText", DrawText );
NewFunction( 0, "PersAngle", FuncPersAngle );
NewFunction( 0, "ViewWidth", FuncViewWidth );
NewFunction( 0, "ViewHeight", FuncViewHeight );
NewFunction( 0, "DrawInvisible", FuncDrawInvisible);
NewFunction( 0, "DrawFrontOnly", FuncDrawFrontOnly);
NewFunction( 0, "ViewCursor", FuncViewCursor);
}
/* マウスのあるウインドウの読み出し*/
static int FuncMouseWindow( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "MouseWindow", args, buf, TYPE_NOASN );
StackPushInt( MouseWindow( MouseX, MouseY ) );
return RETURN_RETURN ;
}
/* 3Dカーソル位置の読み出し */
static int FuncGet3DCursor( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int x, y, z ;
VertexClass *ver ;
ArgCheck( "Cursor", args, buf, TYPE_NOASN );
ver = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
memset(&ver->ver, 0, sizeof(Vertex));
Get3DCursor( &x, &y, &z );
ver->ver.x = x ;
ver->ver.y = y ;
ver->ver.z = z ;
ver->dtype = POLY_SIMPLE ;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)ver ;
return RETURN_RETURN ;
}
/* 3Dカーソルの設定 */
static int Set3DCursor( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *ver ;
ArgCheck( "Vertex:Cursor", args, buf, TYPE_OBJECT, TYPE_NOASN );
if (ObjectCheck(buf, VertexClassID)) {
ver = (VertexClass*)buf[0].od.ptr ;
ViewSet3DCursorPos( ver->ver.x, ver->ver.y, ver->ver.z );
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = ObjectCopy( (Object*)ver );
} else if (ObjectCheck(buf, VectorClassID)) {
VectorClass *vec;
vec = (VectorClass*)buf[0].od.ptr ;
ViewSet3DCursorPos( vec->vec.x, vec->vec.y, vec->vec.z );
ver = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
memset(&ver->ver, 0, sizeof(Vertex));
ver->ver.x = vec->vec.x ;
ver->ver.y = vec->vec.y ;
ver->ver.z = vec->vec.z ;
ver->dtype = POLY_SIMPLE ;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)ver ;
}
DrawCursorPos();
return RETURN_RETURN ;
}
/* 2Dカーソル位置の読み出し */
static int Get2DCursor( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int scr[2];
Vertex v;
ArgCheck( "Cursor2D", args, buf, TYPE_ARRAY, TYPE_NOASN );
if ( buf[0].ad.size < 2 )
ExecError( "引数配列のサイズが不正です。( Get2DCursor )" );
buf = buf[0].ad.ary ;
buf[0].type = buf[1].type = TYPE_INT ;
#if 0
buf[0].id.i = PersMx ;
buf[1].id.i = PersMy ;
#else
v.x = Mx;
v.y = My;
v.z = Mz;
ToScreenPers(scr, &v);
buf[0].id.i = (( scr[0] - WinPers.x - WinPers.h / 2 ) << CURSOR_2D_SHIFT) / WinPers.h ;
buf[1].id.i = - (( scr[1] - WinPers.y - WinPers.v / 2 ) << CURSOR_2D_SHIFT) / WinPers.h ;
#endif
return RETURN_VOID ;
}
/* 3面図の再描画 */
static int Update( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (args == 1) {
ArgCheck( "Update", args, buf, TYPE_BOOLEAN, TYPE_NOASN );
ViewLineAll( 0, 0, 4096, 4096, buf[0].ld.l );
} else {
int orgdraw;
ArgCheck( "Update", args, buf, TYPE_BOOLEAN, TYPE_INT, TYPE_NOASN );
orgdraw = ViewMode;
ViewMode &= buf[1].id.i;
ViewLineAll( 0, 0, 4096, 4096, buf[0].ld.l );
ViewMode = orgdraw;
}
return RETURN_VOID ;
}
/* 透視図の再描画 */
static int UpdatePers( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "UpdatePers", args, buf, TYPE_BOOLEAN, TYPE_NOASN );
ViewLinePersAll( buf[0].ld.l );
return RETURN_VOID ;
}
/* カレントポリゴンを表示 */
static int DrawCurrent( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int osel;
osel = CurrentPoly->select;
if (args > 0) {
ArgCheck( "UpdatePers", args, buf, TYPE_BOOLEAN|TYPE_INT, TYPE_NOASN );
CurrentPoly->select = buf[0].id.i;
}
ViewCurrent();
CurrentPoly->select = osel;
return RETURN_VOID ;
}
/* 3Dラインの表示 */
static int DrawLine( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int color ;
VertexClass *v1, *v2 ;
if ( args == 2 )
{
ArgCheck( "DrawLine", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
color = CURSOR_COLOR ;
}
else
{
ArgCheck( "DrawLine", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
color = buf[2].id.i ;
}
v1 = (VertexClass*)buf[0].od.ptr ;
v2 = (VertexClass*)buf[1].od.ptr ;
ViewLine3D( &v1->ver, &v2->ver, color );
return RETURN_VOID ;
}
/* 2Dラインの表示 */
static int DrawLine2D( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "DrawLine2D", args, buf, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_NOASN );
ViewLine2D( buf[0].id.i, buf[1].id.i, buf[2].id.i, buf[3].id.i, CURSOR_COLOR );
return RETURN_VOID ;
}
/* 3Dボックスの表示 */
static int DrawBox( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
VertexClass *v1, *v2 ;
if ( args < 2 )
ExecError( "引数の数が不正です。( Vertex:DrawBox )" );
if ( buf[1].type != TYPE_OBJECT || ObjectCheck( &buf[1], VertexClassID ) == FALSE )
ExecError( "引数の型が不正です。( Vertex:DrawBox )" );
v1 = (VertexClass*)buf[0].od.ptr ;
v2 = (VertexClass*)buf[1].od.ptr ;
if ( args == 2 )
{
Matrix mat ;
MatUnit( mat );
ViewBox( &v1->ver, &v2->ver, mat );
}
else
{
int matid ;
matid = ClassName( "Matrix" );
if ( buf[2].type != TYPE_OBJECT || ObjectCheck( &buf[2], MatrixClassID ) == FALSE )
ExecError( "引数の型が不正です。( Vertex:DrawBox )" );
ViewBox( &v1->ver, &v2->ver, ((MatrixClass*)buf[2].od.ptr)->mat );
}
return RETURN_VOID ;
}
/* 2Dボックスの表示 */
static int DrawBox2D( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "DrawBox2D", args, buf, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_NOASN );
ViewBox2D( buf[0].id.i, buf[1].id.i, buf[2].id.i, buf[3].id.i );
return RETURN_VOID ;
}
/* 表示画面クリア */
static int Clear( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (args > 0) {
ArgCheck( "Clear", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
if (buf[0].id.i) {
ViewClear( TMP_COLOR );
} else {
ViewClear(-1);
}
} else {
ArgCheck( "Clear", args, buf, TYPE_NOASN );
ViewClear( TMP_COLOR );
}
return RETURN_VOID ;
}
/* 表示ウインドウの設定 */
static int SetWindow( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (args == 0) {
StackPushInt(ViewMode);
return RETURN_RETURN;
} else {
ArgCheck( "SetWindow", args, buf, TYPE_INT, TYPE_NOASN );
ViewCursor( OFF );
ViewSetWindow( buf[0].id.i );
ViewFrame();
ViewLineAll( 0, 0, 4096, 4096, TRUE );
ViewCursor( ON );
return RETURN_VOID ;
}
}
/* 法線ベクトル表示モードの設定 */
static int SetVisibleVector( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int v;
v = VisibleVector;
if (args > 0) {
ArgCheck( "SetVisibleVector", args, buf, TYPE_INT, TYPE_NOASN );
VisibleVector = buf[0].id.i ;
}
StackPushInt( v );
return RETURN_RETURN ;
}
/* 面法線ベクトル表示モードの設定 */
static int SetVisiblePolyVector( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int v;
v = VisiblePolyVector;
if (args > 0) {
ArgCheck( "SetVisiblePolyVector", args, buf, TYPE_INT, TYPE_NOASN );
VisiblePolyVector = buf[0].id.i ;
}
StackPushInt( v );
return RETURN_RETURN ;
}
/* 頂点表示モードの設定 */
static int SetVisibleVertex( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int v;
v = VisibleVertex;
if (args > 0) {
ArgCheck( "SetVisibleVertex", args, buf, TYPE_INT, TYPE_NOASN );
VisibleVertex = buf[0].id.i ;
}
StackPushInt( v );
return RETURN_RETURN ;
}
/* 表示位置の設定 */
static int SetCenter( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int x, y, z, vx, vy, vz, u, v ;
VertexClass *ver ;
if ( args == 0 )
{
ver = (VertexClass*)ObjectAlloc( sizeof( VertexClass ), VertexClassID );
memset(&ver->ver, 0, sizeof(Vertex));
ver->dtype = POLY_SIMPLE ;
ver->ver.x = Cx ;
ver->ver.y = Cy ;
ver->ver.z = Cz ;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)ver ;
return RETURN_RETURN ;
}
else
{
if ( ConvVertex( &x, &y, &z, &vx, &vy, &vz, &u, &v, buf ) ) {
ViewCursorPers( PERS_CURSOR_OFF );
ViewSetCenter( x, y, z );
ViewCursorPers( PERS_CURSOR_3D );
} else
ExecError( "型が不正です。(SetCenter)" );
return RETURN_VOID ;
}
}
/* ズーム値の設定 */
static int SetZoom( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int move ;
if ( args == 1 )
{
ArgCheck( "SetZoom", args, buf, TYPE_INT, TYPE_NOASN );
move = 0 ;
}
else
{
ArgCheck( "SetZoom", args, buf, TYPE_INT, TYPE_INT, TYPE_NOASN );
move = buf[1].id.i ;
printf( "move : %d\n", move );
}
ViewCursorPers( PERS_CURSOR_OFF );
ViewSetZoom( buf[0].id.i, move );
ViewCursorPers( PERS_CURSOR_3D );
return RETURN_VOID ;
}
/* 透視図の設定 */
static int SetPers( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "SetPers", args, buf, TYPE_OBJECT, TYPE_NOASN );
ViewCursorPers( PERS_CURSOR_OFF );
ViewSetPers( ((MatrixClass*)buf[0].od.ptr)->mat );
ViewLinePersAll( TRUE );
ViewCursorPers( PERS_CURSOR_3D );
return RETURN_VOID ;
}
/* グリッドの設定 */
static int SetGrid( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "SetGrid", args, buf, TYPE_INT, TYPE_INT, TYPE_NOASN );
ViewSetGrid( buf[0].id.i, buf[1].id.i );
return RETURN_VOID ;
}
/* 3面図の変換設定 */
static int SetConv( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "SetConv", args, buf, TYPE_OBJECT, TYPE_NOASN );
ViewCursorPers( PERS_CURSOR_OFF );
ViewSetConv( ((MatrixClass*)buf[0].od.ptr)->mat );
ViewCursorPers( PERS_CURSOR_3D );
return RETURN_VOID ;
}
/* 3面図の変換設定 */
static int DrawText( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int x, y, atr ;
atr = ( args < 4 ) ? 0x0f : buf[4].id.i ;
y = ( args < 3 ) ? 20 : buf[4].id.i ;
x = ( args < 2 ) ? 0 : buf[4].id.i ;
graph_puts( ((StringClass*)buf[2].od.ptr)->str, x, y, atr );
return RETURN_VOID ;
}
/* 透視図の画角設定 */
static int FuncPersAngle( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int angle;
if (args > 0) {
ArgCheck( "PersAngle", args, buf, TYPE_INT, TYPE_NOASN );
angle = PersAngle(buf->id.i);
#if 0
ViewCursorPers( PERS_CURSOR_OFF );
ViewLinePersAll( TRUE );
ViewCursorPers( PERS_CURSOR_3D );
#endif
} else {
angle = PersAngle(0);
}
StackPushInt( angle );
return RETURN_RETURN ;
}
static int FuncViewWidth( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "ViewWidth", args, buf, TYPE_INT, TYPE_NOASN );
switch (buf[0].id.i) {
case VIEW_XY:
StackPushInt( WinXY.h * ZoomMinus / ZoomPlus );
break;
case VIEW_YZ:
StackPushInt( WinYZ.h * ZoomMinus / ZoomPlus);
break;
case VIEW_ZX:
StackPushInt( WinZX.h * ZoomMinus / ZoomPlus);
break;
case VIEW_PERS:
StackPushInt( WinPers.h * ZoomMinus / ZoomPlus);
break;
}
return RETURN_RETURN ;
}
static int FuncViewHeight( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "ViewHeight", args, buf, TYPE_INT, TYPE_NOASN );
switch (buf[0].id.i) {
case VIEW_XY:
StackPushInt( WinXY.v * ZoomMinus / ZoomPlus );
break;
case VIEW_YZ:
StackPushInt( WinYZ.v * ZoomMinus / ZoomPlus );
break;
case VIEW_ZX:
StackPushInt( WinZX.v * ZoomMinus / ZoomPlus );
break;
case VIEW_PERS:
StackPushInt( WinPers.v * ZoomMinus / ZoomPlus );
break;
}
return RETURN_RETURN ;
}
static int FuncDrawInvisible( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (args > 0) {
ArgCheck( "DrawInvisible", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
InvisibleDraw = buf[0].id.i;
}
StackPushInt( InvisibleDraw );
return RETURN_RETURN ;
}
static int FuncDrawFrontOnly( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (args > 0) {
ArgCheck( "DrawFrontOnly", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
DrawFrontOnlyFlag= buf[0].id.i;
}
StackPushInt( DrawFrontOnlyFlag );
return RETURN_RETURN ;
}
static int FuncViewCursor( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (args > 0) {
ArgCheck( "ViewCursor", args, buf, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
ViewCursor(buf[0].id.i);
}
StackPushInt( Mstat );
return RETURN_RETURN ;
}