home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / PROG / BWSB120B.ZIP / TTP / VECTOR.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1994-12-20  |  5.1 KB  |  238 lines

  1. Unit Vector;
  2.  
  3. Interface
  4.  
  5. Uses MCGA;
  6.  
  7. Const
  8.   NumStars = 200;
  9.  
  10. Type
  11.   LCoord = Record
  12.     x, y, z : Longint;
  13.   End;
  14.   LList = Array[0..7] of LCoord;
  15.   LNormal = Array[0..5] of LCoord;
  16.   PolyDesc = Array[0..5,0..3] of Byte;
  17.   SCoord = Record
  18.     x, y : Integer;
  19.   End;
  20.   SList = Array[0..7] of SCoord;
  21.   SField = Array[0..NumStars] of SCoord;
  22.  
  23. Const
  24.   NumColors = 12;
  25.   ColorStart = 65;
  26.   EndPosition : LCoord = (x:0; y:0; z:-10000);
  27.   Viewer : LCoord = (x:0;y:0;z:4096);
  28.   Local : LList = ((x:50; y:50;  z:50),
  29.                    (x:50; y:-50; z:50),
  30.                    (x:-50; y:-50; z:50),
  31.                    (x:-50; y:50; z:50),
  32.                    (x:50; y:50; z:-50),
  33.                    (x:50; y:-50; z:-50),
  34.                    (x:-50; y:-50; z:-50),
  35.                    (x:-50; y:50; z:-50));
  36.   Polygons:PolyDesc=((0,3,2,1),(5,6,7,4),(1,2,6,5),(2,3,7,6),(3,0,4,7),(0,1,5,4));
  37.   Normals:LNormal=((x:0;y:0;z:4096),(x:0;y:0;z:-4096),(x:0;y:-4096;z:0),
  38.                    (x:-4096;y:0;z:0),(x:0;y:4096;z:0),(x:4096;y:0;z:0));
  39.  
  40. Var
  41.   LStars, WStars : SField;
  42.   Circle : Array[0..511] of SCoord;
  43.  
  44. Procedure InitStars;
  45. Procedure LocalRotate(X, Y, Z : Word);
  46. Procedure GlobalTranslate;
  47. Procedure GlobalRotate(X, Y, Z : Word);
  48. Procedure DisplayVec;
  49. Procedure Scale;
  50. Procedure UpDatePos;
  51. Procedure SpawnTarget(CirPos, Z, Sca : Longint);
  52. Procedure PutStars;
  53. Procedure DrawLaser(Side : Integer);
  54. Procedure InitCircle;
  55.  
  56. Implementation
  57.  
  58. Var
  59.   ScaleSize : Longint;
  60.   World : LList;
  61.   WNormals : LNormal;
  62.   Screen : SList;
  63.   XPos, YPos, ZPos : Integer;
  64.   CirclePos : Word;
  65.  
  66. {$F+}
  67. {$L Rotate.Obj}
  68. Procedure RotatePoints(Var Local, World; Num, X, Y, Z : Word); External;
  69. Procedure ScalePoints(Var Word; Num : Word; Sf : Longint); External;
  70. Procedure Project(Var World, Screen; Num : Word); External;
  71.  
  72. {$L Poly.Obj}
  73. Procedure DrawPoly(Var Sc; Num : Word; Color : Byte; PG : Word); External;
  74. {$F-}
  75.  
  76. Procedure InitStars;
  77.  
  78. Var
  79.   x : Integer;
  80.  
  81. Begin
  82.   RandSeed := 1001;
  83.   For x := 0 to NumStars do
  84.     Begin
  85.       LStars[x].x := Random(900) - 450;
  86.       LStars[x].y := Random(900) - 450;
  87.     End;
  88. End;
  89.  
  90. Procedure LocalRotate(X, Y, Z : Word);
  91.  
  92. Begin
  93.   RotatePoints(Local, World, 8, X, Y, Z);
  94.   RotatePoints(Normals, WNormals, 6, X, Y, Z);
  95. End;
  96.  
  97. Procedure Scale;
  98.  
  99. Begin
  100.   ScalePoints(World, 8, ScaleSize);
  101. End;
  102.  
  103. Procedure GlobalTranslate;
  104.  
  105. Var
  106.   Count : Integer;
  107.  
  108. Begin
  109.   For Count := 0 to 7 do
  110.     Begin
  111.       World[Count].x := World[Count].x + Circle[CirclePos].x;
  112.       World[Count].y := World[Count].y + Circle[CirclePos].y;
  113.       World[Count].z := World[Count].z + ZPos;
  114.     End;
  115. End;
  116.  
  117. Procedure GlobalRotate(X, Y, Z : Word);
  118.  
  119. Var
  120.   xc : Integer;
  121.  
  122. Begin
  123.   RotatePoints(World, World, 8, X, Y, Z);
  124.   RotatePoints(WNormals, WNormals, 6, X, Y, Z);
  125.   For xc := 0 to NumStars do
  126.     Begin
  127.       WStars[xc].x := LStars[xc].x + (y - 256) Shl 2;
  128.       WStars[xc].y := LStars[xc].y - (x - 256) Shl 2;
  129.     End;
  130. End;
  131.  
  132. Function Visible(W : LNormal; Num : Word) : Word;
  133.  
  134. Var
  135.   Dot : Longint;
  136.  
  137. Begin
  138.   Dot := (Viewer.x * W[Num].x) + (Viewer.y * W[Num].y) + (Viewer.z * W[Num].z);
  139.   If Dot >= 0
  140.     Then Visible := ((Dot Shr 12) * NumColors) Shr 12
  141.     Else Visible := $ff00;
  142. End;
  143.  
  144. Procedure PutStars;
  145.  
  146. Var
  147.   Count : Integer;
  148.  
  149. Begin
  150.   For Count := 0 to NumStars do
  151.     With WStars[Count] do
  152.       Begin
  153.         If ((X >= 0) and (X <= 319)) And
  154.            ((Y >= 0) and (Y <= 199))
  155.             Then Mem[Page1:y*320+x] := 15;
  156.       End;
  157. End;
  158.  
  159. Procedure DisplayVec;
  160.  
  161. Var
  162.   SmallList : Array[0..3] of SCoord;
  163.   Count : Integer;
  164.   Intensity : Word;
  165.   Convert : Integer;
  166.  
  167. Begin
  168.   Project(World, Screen, 8);
  169.   For Count := 0 to 6 do
  170.     Begin
  171.       Intensity := Visible(WNormals, Count);
  172.       If (Intensity And $ff00) = 0
  173.         Then Begin
  174.           For Convert := 0 to 3 do
  175.             Begin
  176.               SmallList[Convert].x := Screen[Polygons[Count,Convert]].x;
  177.               SmallList[Convert].y := Screen[Polygons[Count,Convert]].y;
  178.             End;
  179.           DrawPoly(SmallList, 4, ColorStart + (NumColors - Lo(Intensity) + 1), Page1);
  180.         End;
  181.     End;
  182. End;
  183.  
  184. Procedure SpawnTarget(CirPos, Z, Sca : Longint);
  185.  
  186. Begin
  187.   CirclePos := CirPos;
  188.   ZPos := Z;
  189.   ScaleSize := Sca;
  190. End;
  191.  
  192. Procedure UpdatePos;
  193.  
  194. Begin
  195.   CirclePos := (CirclePos + 1) And 511;
  196. End;
  197.  
  198.  
  199. Procedure DrawLaser(Side : Integer);
  200.  
  201. Var
  202.   LaserList : Array[0..2] of SCoord;
  203.  
  204. Begin
  205.   If Side = 1
  206.     Then Begin
  207.       LaserList[0].x := 0;
  208.       LaserList[0].y := 110;
  209.       LaserList[1].x := 160;
  210.       LaserList[1].y := 100;
  211.       LaserList[2].x := 0;
  212.       LaserList[2].y := 130;
  213.     End
  214.     Else Begin
  215.       LaserList[0].x := 160;
  216.       LaserList[0].y := 100;
  217.       LaserList[1].x := 319;
  218.       LaserList[1].y := 110;
  219.       LaserList[2].x := 319;
  220.       LaserList[2].y := 130;
  221.     End;
  222.   DrawPoly(LaserList, 3, 249, Page1);
  223. End;
  224.  
  225. Procedure InitCircle;
  226.  
  227. Var
  228.   x : Longint;
  229.  
  230. Begin
  231.   For x := 0 to 511 do
  232.     Begin
  233.       Circle[x].x := Round(Cos(x*(Pi*2)/512)*300);
  234.       Circle[x].y := Round(Sin(x*(Pi*2)/512)*300);
  235.     End;
  236. End;
  237.  
  238. End.