home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol069 / util.pas < prev    next >
Pascal/Delphi Source File  |  1984-04-29  |  2KB  |  61 lines

  1. External Graphics::Util(4);
  2. (*$E+ *)
  3.  
  4. { The field of vision for a 3 dimensional display is bounded
  5.   by 'clipping planes', the coefficients of which are calculated
  6.   in this procedure. } 
  7. procedure GetPlanes( var Poly : OnePoly; NumPts : counter);
  8. var
  9.   I,LstI : counter;
  10.   TmpPoly : OnePoly;
  11. begin { compute plane equation coefficients for polygon edges }
  12.   LstI := NumPts;  { leading vertex of the edge }
  13.   for I := 1 to NumPts do
  14.     begin
  15.       with Poly[I] do
  16.     begin { vector cross product using edge endpoints }
  17.     TmpPoly[I].X := Y * Poly[LstI].Z - Z * Poly[LstI].Y;
  18.     TmpPoly[I].Y := Z * Poly[LstI].X - X * Poly[LstI].Z;
  19.     TmpPoly[I].Z := X * Poly[LstI].Y - Y * Poly[LstI].X;
  20.     end; { with Poly[I] }
  21.       LstI := I;
  22.     end;    { for loop }
  23.     for I := 1 to NumPts do    {copy back to input polygon }
  24.       with TmpPoly[I] do
  25.         begin
  26.           Poly[I].X := X;
  27.           Poly[I].Y := Y;
  28.           Poly[I].Z := Z;
  29.         end { with TmpPoly[I] }
  30. end;    { Getplanes }
  31. (*$L+ *)
  32.  
  33. procedure GetScreenScale;
  34. { get window to screen scale factor }
  35. var
  36.   I : counter;
  37.   MaxX,MinX,MaxY,MinY : real;
  38.  
  39. begin
  40.   MaxX:=0.0;
  41.   MinX:=0.0;
  42.   MaxY:=0.0;
  43.   MinY:=0.0; {window must include Z-axis}
  44.   for I := 1 to WindowSize do
  45.     with Window[I] do
  46.       begin
  47.     if X/Z > MaxX then MaxX := X/Z;
  48.     if X/Z < MinX then MinX := X/Z;
  49.     if Y/Z > MaxY then MaxY := Y/Z;
  50.     if Y/Z < MinY then MinY := Y/Z;
  51.       end; { with Window[I] }
  52.   MaxX := MaxX - MinX;
  53.   MaxY := MaxY - MinY;
  54.   if MaxY > (0.75 * MaxX)  {standard display is 3 unit high by 4 units wide}
  55.   then ScreenScale.Z := (MaxY * 4 / 3)
  56.   else ScreenScale.Z := MaxX;
  57.   ScreenScale.X := DotsAcross / ScreenScale.Z;
  58.   ScreenScale.Y := (DotsDown * 4 / 3) / ScreenScale.Z;
  59. end;    { GetScreenScale }
  60. .
  61.