home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / grafik / gr3d / gr3d_obj.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-08-23  |  3.0 KB  |  137 lines

  1. unit Gr3d_obj;
  2.  
  3. interface
  4.  
  5. uses
  6.   Graph, MM_Mem, Gr3d_pt;
  7.  
  8. type
  9.  
  10.   PPoint = ^TPoint;
  11.   TPoint = object(TPointGroup)
  12.     constructor Init(InitX, InitY, InitZ: integer);
  13.     procedure Draw; virtual;
  14.   end;
  15.  
  16.   PPolygon = ^TPolygon;
  17.   TPolygon = object(TPointGroup)
  18.     C: integer;
  19.     constructor Init(InitX, InitY, InitZ, InitC: integer);
  20.     procedure Draw; virtual;
  21.     procedure DrawFilled; virtual;
  22.   end;
  23.  
  24.   PRect = ^TRect;
  25.   TRect = object(TPolygon)
  26.     H, W: integer;
  27.     constructor Init(InitX, InitY, InitZ, InitC: integer; InitH, InitW: integer);
  28.     procedure Draw; virtual;
  29.   end;
  30.  
  31.   PPoly6 = ^TPoly6;
  32.   TPoly6 = object(TPolygon)
  33.     Side: integer;
  34.     constructor Init(InitX, InitY, InitZ, InitC: integer; InitSide: integer);
  35.   end;
  36.  
  37.   procedure MConvertPoints(M: PMatrix; var S: PMatrix);
  38.  
  39. implementation
  40.  
  41. {-------------------------}
  42. { global }
  43. procedure MConvertPoints(M: PMatrix; var S: PMatrix);
  44. var
  45.   i : integer;
  46.   PM: P3dPoint;
  47.   PS: P2dPoint;
  48. begin
  49.   NewMatrix(S, M^.DimRow+1, 2);
  50.   for i := 1 to M^.DimRow do
  51.   begin
  52.     PM := P3dPoint(GetPtr(M, i, 1));
  53.     PS := P2dPoint(GetPtr(S, i, 1));
  54.     ConvertPoint(PM^.x, PM^.y, PM^.z, PS^.x, PS^.y);
  55.   end;
  56.   P2dPoint(GetPtr(S,S^.DimRow,1))^ := P2dPoint(S^.Buf)^
  57. end;
  58.  
  59. {-------------------------}
  60. constructor TPolygon.Init(Initx, InitY, InitZ, InitC: integer);
  61. begin
  62.   TPointGroup.Init(InitX, InitY, InitZ);
  63.   C := InitC;
  64. end;
  65.  
  66. procedure TPolygon.Draw;
  67. var
  68.   S: PMatrix;
  69. begin
  70.   MConvertPoints(M, S);
  71.   SetColor(DefaultColor);
  72.   DrawPoly(N+1, S^.Buf^);
  73.   DelMatrix(S);
  74. end;
  75.  
  76. procedure TPolygon.DrawFilled;
  77. var
  78.   S: PMatrix;
  79. begin
  80.   SetFillStyle(SolidFill, C);
  81.   MConvertPoints(M, S);
  82.   FillPoly(N+1, S^.Buf^);
  83.   DelMatrix(S);
  84. end;
  85.  
  86. {-----------------------}
  87. { TPoint }
  88.  
  89. constructor TPoint.Init(InitX, InitY, InitZ: integer);
  90. begin TPointGroup.Init(InitX, InitY, InitZ);
  91. end;
  92.  
  93. procedure TPoint.Draw;
  94. var
  95.   Sx, Sy: integer;
  96. begin
  97.   ConvertPoint(GetX(1),GetY(1),GetZ(1),Sx,Sy);
  98.   PutPixel(Sx, Sy, DefaultColor);
  99. end;
  100.  
  101. {-----------------------}
  102. { TRect }
  103.  
  104. constructor TRect.Init(InitX, InitY, InitZ, InitC: integer; InitH, InitW: integer);
  105. begin
  106.   TPolygon.Init(InitX, InitY, InitZ, InitC);
  107.   InsertPoint(InitX+H, InitY, InitZ);
  108.   InsertPoint(InitX+H, InitY+W, InitZ);
  109.   InsertPoint(InitX, InitY+W, InitZ);
  110.   H := InitH;
  111.   W := InitW;
  112. end;
  113.  
  114. procedure TRect.Draw;
  115. begin
  116.   TPolygon.Draw;
  117. end;
  118.  
  119. {----------------------}
  120. { TPoly6 }
  121.  
  122. constructor TPoly6.Init(InitX, InitY, InitZ, InitC: integer; InitSide: integer);
  123. var
  124.   Temp : integer;
  125. begin
  126.   TPolygon.Init(InitX, InitY, InitZ, InitC);
  127.   Temp := Trunc(InitSide * Sqrt(5));
  128.   InsertPoint(InitX-InitSide div 2    , InitY+Temp div 2, InitZ);
  129.   InsertPoint(InitX                   , InitY+Temp      , InitZ);
  130.   InsertPoint(InitX+(3*InitSide) div 2, InitY+Temp      , InitZ);
  131.   InsertPoint(InitX+InitSide*2        , InitY+Temp div 2, InitZ);
  132.   InsertPoint(InitX+(3*InitSide) div 2, InitY           , InitZ);
  133.   Side := InitSide;
  134. end;
  135.  
  136.  
  137. end.