home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Modula
/
Source
/
Draw3D.MOD
< prev
next >
Wrap
Text File
|
1985-01-01
|
2KB
|
102 lines
MODULE Draw3D;
(*
Draw and rotate a three dimensional wire-frame object
*)
FROM ThreeDee IMPORT Point3D, SetRot, SetScale,
SetTranslation, SetPerspective,
TransformSRT, Project;
FROM QuickDrawTypes IMPORT Point;
FROM MiniQD IMPORT MoveTo, LineTo, ObscureCursor;
FROM Terminal IMPORT ClearScreen, BusyRead;
FROM InOut IMPORT OpenInput, CloseInput,
ReadInt, WriteString, Done;
FROM RealInOut IMPORT ReadReal;
CONST
maxVertices = 150;
maxEdges = 300;
VAR
vertices: ARRAY[1..maxVertices] OF Point3D;
projectedVertices: ARRAY[1..maxVertices] OF Point;
edges: ARRAY[1..maxEdges] OF INTEGER;
numVertices, numEdges: INTEGER;
PROCEDURE DrawEdge( from, to: INTEGER );
BEGIN
WITH projectedVertices[from] DO MoveTo( 256+h, 171+v ); END;
WITH projectedVertices[to] DO LineTo( 256+h, 171+v ); END;
END DrawEdge;
PROCEDURE DisplayList;
VAR
edgeIndex: INTEGER;
BEGIN
FOR edgeIndex:=1 TO numEdges DO
IF edges[edgeIndex] > 0
THEN DrawEdge( ABS(edges[edgeIndex-1]), edges[edgeIndex] );
END; (*IF*)
END; (*FOR*)
END DisplayList;
PROCEDURE ProjectList; (* rotate and project all vertices *)
VAR
vertIndex: INTEGER;
rotVertex: Point3D;
BEGIN
FOR vertIndex:=1 TO numVertices DO
TransformSRT( vertices[vertIndex], rotVertex );
Project( rotVertex, projectedVertices[vertIndex] );
END; (*FOR*)
END ProjectList;
PROCEDURE ReadList;
VAR
index, edge: INTEGER;
BEGIN
ClearScreen;
WriteString( "Please enter the name of a 3-D data file:" );
OpenInput( "3D" );
ReadInt( numVertices );
FOR index:=1 TO numVertices DO
WITH vertices[index] DO
ReadReal( X ); ReadReal( Y ); ReadReal( Z );
END; (*WITH*)
END; (*FOR*)
numEdges:=0;
LOOP
ReadInt( edge );
IF NOT Done THEN EXIT; END;
INC( numEdges );
edges[numEdges]:=edge;
END; (*LOOP*)
CloseInput;
END ReadList;
PROCEDURE KeyWasPressed(): BOOLEAN;
VAR
ch: CHAR;
BEGIN
BusyRead( ch );
RETURN ch <> 0C;
END KeyWasPressed;
VAR
xR, yR, zR: REAL;
BEGIN
ReadList;
SetTranslation( 0.0, 0.0, 0.0 );
SetPerspective( 220.0, -180.0 );
xR:=0.0; yR:=0.0; zR:=0.0;
ObscureCursor;
REPEAT
SetRot( xR, yR, zR );
ProjectList;
ClearScreen;
DisplayList;
xR:=xR + 8.0; yR:=yR + 10.0; zR:=zR + 12.0;
UNTIL KeyWasPressed();
END Draw3D.