home *** CD-ROM | disk | FTP | other *** search
- program chap2_5;
-
- uses graph, crt;
-
- const xoffset=640/2;
- yoffset=480/2;
- xscale=1;
- yscale=-1;
- persp=500;
-
- 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;
- xe,ye,ze : real;
-
- 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;
- 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(x,y,z : real);
- begin
- for c:=1 to 18 do
- begin
- vertex[c].zs:=round(vertex[c].zw-z);
- vertex[c].xs:=round(((vertex[c].xw-x)*(persp/vertex[c].zs)*xscale)+xoffset);
- vertex[c].ys:=round(((vertex[c].yw-y)*(persp/vertex[c].zs)*yscale)+yoffset);
- end;
- end;
-
-
- begin
- clrscr;
- writeln; writeln; writeln; writeln; writeln; writeln;
- writeln('This is from Chapter 2 Step 5 of the Virtual Reality Homebrewer''s Handbook and');
- writeln('shows how to simply move (no turning) around a virtual shape drawn in wireframe.');
- writeln;
- writeln;
- writeln('Controls: 8/2 - move forwards/back');
- writeln(' 4/6 - move left/back');
- writeln(' 7/1 - move up/down');
- writeln;
- writeln(' q - quit');
- 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;
-
- xe:=0; ye:=0; ze:=0;
- transform(xe,ye,ze);
- draw_picture;
-
- repeat
- ch:=Readkey;
- case ch of
- '8': ze:=ze+10;
- '2': ze:=ze-10;
- '4': xe:=xe-10;
- '6': xe:=xe+10;
- '1': ye:=ye-10;
- '7': ye:=ye+10;
- end;
- transform(xe,ye,ze);
- draw_picture;
- until ch='q';
- CloseGraph;
- end.