unit m_beta02;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TPoly =
record
Punkt1,Punkt2,Punkt3,Punkt4: TPoint;
end;
type
TMyPoint =
record
X_Koordinate,Y_Koordinate,Z_Koordinate: Real;
end;
type
TForm1 =
class(TForm)
Image1: TImage;
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Punkt:
array [1..100]
of TMyPoint;
Ko_B:
array [1..100]
of TPoint;
poly:
array [1..100]
of TPoly;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i,d,h,a:integer;
begin
a:=Image1.Width
div 2;
// Verschiebt den Ursprung des Koordinatensystems auf der Leinwand
d:=StrToInt(Edit1.Text);
// Beschreibt den Abstand des Betrachters zur Bildebene
h:=Image1.Height
div 2;
// Verschiebt den Ursprung des Koordinatensystems auf der Leinwand
// Koordinaten der Punkte des Würfels
with Punkt[1]
do
begin
X_Koordinate:= (100);
Y_Koordinate:= (100);
Z_Koordinate:= (100);
end;
with Punkt[2]
do
begin
X_Koordinate:= (100);
Y_Koordinate:= (100);
Z_Koordinate:= (200);
end;
with Punkt[3]
do
begin
X_Koordinate:= (200);
Y_Koordinate:= (100);
Z_Koordinate:= (200);
end;
with Punkt[4]
do
begin
X_Koordinate:= (200);
Y_Koordinate:= (100);
Z_Koordinate:= (100);
end;
with Punkt[5]
do
begin
X_Koordinate:= (100);
Y_Koordinate:= (200);
Z_Koordinate:= (100);
end;
with Punkt[6]
do
begin
X_Koordinate:= (100);
Y_Koordinate:= (200);
Z_Koordinate:= (200);
end;
with Punkt[7]
do
begin
X_Koordinate:= (200);
Y_Koordinate:= (200);
Z_Koordinate:= (200);
end;
with Punkt[8]
do
begin
X_Koordinate:= (200);
Y_Koordinate:= (200);
Z_Koordinate:= (100);
end;
{ Umrechnen der gegebenen 3-dimensionalen Koordinaten
in 2-dimensionale Koordinaten auf der Bildebene }
for i:= 1
to 8
do
begin
Ko_B[i]:=Point
( round(a+(d/(d+Punkt[i].Z_Koordinate))*Punkt[i].X_Koordinate),
round(h+(d/(d+Punkt[i].Z_Koordinate))*Punkt[i].Y_Koordinate));
end;
{ Definition der Polygone }
with poly[1]
do
begin
Punkt1:= Ko_B[2];
Punkt2:= Ko_B[3];
Punkt3:= Ko_B[7];
Punkt4:= Ko_B[6];
end;
with poly[2]
do
begin
Punkt1:= Ko_B[5];
Punkt2:= Ko_B[6];
Punkt3:= Ko_B[7];
Punkt4:= Ko_B[8];
end;
with poly[3]
do
begin
Punkt1:= Ko_B[1];
Punkt2:= Ko_B[2];
Punkt3:= Ko_B[6];
Punkt4:= Ko_B[5];
end;
with poly[4]
do
begin
Punkt1:= Ko_B[3];
Punkt2:= Ko_B[4];
Punkt3:= Ko_B[8];
Punkt4:= Ko_B[7];
end;
with poly[5]
do
begin
Punkt1:= Ko_B[1];
Punkt2:= Ko_B[4];
Punkt3:= Ko_B[8];
Punkt4:= Ko_B[5];
end;
with poly[6]
do
begin
Punkt1:= Ko_B[1];
Punkt2:= Ko_B[2];
Punkt3:= Ko_B[3];
Punkt4:= Ko_B[4];
end;
{ Zeichnen des Objektes }
with Image1.Canvas
do
begin
{ Einstellen der Farbe, in der gezeichnet wird }
Brush.Color := clwhite;
Pen.Color := clblack;
{ Zeichnen der Polygone in richtiger Reihenfolge }
for i:= 1
to high(poly)
do
Polygon([poly[i].Punkt1,poly[i].Punkt2,poly[i].Punkt3,poly[i].Punkt4]);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
// Löschen der Bildebene
begin
with Image1.Canvas
do
begin
Brush.Color := clwhite;
Pen.Color := clwhite;
rectangle(0,0,Image1.Width,Image1.Height);
end;
end;
end.