home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Homebrewer's Handbook
/
vr.iso
/
3dgraph
/
pascal
/
chap2_3.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-03-19
|
2KB
|
94 lines
program chap2_3;
uses graph, crt;
const xoffset=640/2;
yoffset=480/2;
xscale=1;
yscale=-1;
type point=record
xw, yw, zw : real;
xs, ys, zs : integer;
end;
var vertex : array[1..18] of point;
edges : array[1..27,1..27] of integer;
f : text;
c : integer;
ch : char;
procedure Initialise_Graphics;
var Graphdriver, Graphmode, Errorcode : integer;
begin
Graphdriver:=Detect;
InitGraph(Graphdriver, Graphmode,'');
Errorcode:=graphresult;
if Errorcode<>grOk then
begin
writeln('Graphics Error: ',GraphErrorMsg(ErrorCode));
writeln('Program Aborted');
Halt(1);
end;
SetLineStyle(0,0,3);
end;
procedure draw_picture;
var c : integer;
begin
ClearDevice;
for c:=1 to 27 do
line(vertex[edges[c,1]].xs,vertex[edges[c,1]].ys,vertex[edges[c,2]].xs,vertex[edges[c,2]].ys);
end;
procedure transform;
var c : integer;
begin
for c:=1 to 18 do
begin
vertex[c].xs:=round((vertex[c].xw*xscale)+xoffset);
vertex[c].ys:=round((vertex[c].yw*yscale)+yoffset);
vertex[c].zs:=round(vertex[c].zw);
end;
end;
begin
clrscr;
writeln; writeln; writeln; writeln; writeln; writeln; writeln;
writeln('This is from Chapter 2 Step 3 of the Virtual Reality Homebrewer''s Handbook and');
writeln('shows how to draw a virtual shape in wireframe.');
writeln;
writeln;
writeln;
writeln(' Press any key to continue');
ch:=ReadKey;
{Read in vertices}
assign(f,'points.dat');
reset(f);
for c:=1 to 18 do
begin
readln(f,vertex[c].xw,vertex[c].yw,vertex[c].zw);
end;
close(f);
{Move to z=500}
for c:=1 to 18 do
begin
vertex[c].zw:=vertex[c].zw+500;
end;
{Read in edges}
assign(f,'edges.dat');
reset(f);
for c:=1 to 27 do
readln(f,edges[c,1], edges[c,2]);
close(f);
Initialise_Graphics;
transform;
draw_picture;
repeat until keypressed;
CloseGraph;
end.