unit umy3dtype;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Graphics;
type
TPoint3D =
record
x,y,z:Integer;
end;
// TPoint3D
function Point3DTo2D(
const x, y, z, a:Integer):TPoint;
function Point3D(
const x,y,z:Integer):TPoint3D;
procedure Draw3DRect(Canvas:TCanvas;
const P1, P2, P3, P4:TPoint3D;
const a:Integer;
const ViewPoint:TPoint);
implementation
function Point3DTo2D(
const x, y, z, a: Integer): TPoint;
begin
result.x:=(a*x)
div z;
result.y:=(a*y)
div z;
end;
// Point3DTo2D
function Point3D(
const x, y, z: Integer): TPoint3D;
begin
result.x:=x;
result.y:=y;
result.z:=z;
end;
// Point3D
procedure Draw3DRect(Canvas:TCanvas;
const P1, P2, P3, P4:TPoint3D;
const a:Integer;
const ViewPoint:TPoint);
var
TempPoint:TPoint;
Points:
array[0..3]
of TPoint;
px,py:Integer;
begin
// px:=(a*P1.X) div P1.Z;
// py:=(a*P1.Y) div P1.Z;
TempPoint:=Point3DTo2D(P1.x, P1.y, P1.z, a);
Points[1]:=Point(ViewPoint.X+TempPoint.X,ViewPoint.Y+TempPoint.Y);
// px:=(a*P1.X) div P1.Z;
// py:=(a*P1.Y) div P1.Z;
TempPoint:=Point3DTo2D(P2.x, P2.y, P2.z, a);
Points[0]:=Point(ViewPoint.X+TempPoint.X,ViewPoint.Y+TempPoint.Y);
// px:=(a*P1.X) div P1.Z;
// py:=(a*P1.Y) div P1.Z;
TempPoint:=Point3DTo2D(P3.x, P3.y, P3.z, a);
Points[2]:=Point(ViewPoint.X+TempPoint.X,ViewPoint.Y+TempPoint.Y);
// px:=(a*P1.X) div P1.Z;
// py:=(a*P1.Y) div P1.Z;
TempPoint:=Point3DTo2D(P4.x, P4.y, P4.z, a);
Points[3]:=Point(ViewPoint.X+TempPoint.X,ViewPoint.Y+TempPoint.Y);
Canvas.Polygon(Points)
end;
// Draw3DRect
end.
// Angewendet:
// Rechts
Draw3DRect(Canvas, Point3D(5,10,10), Point3D(10,10,10), Point3D(5,10,15), Point3D(10,10,15),a, Point(cx, cy));
// Mitte
Draw3DRect(Canvas, Point3D(0,10,10), Point3D(-5,10,10), Point3D(0,10,15), Point3D(-5,10,15),a, Point(cx, cy));
// Links
Draw3DRect(Canvas, Point3D(-10,10,10), Point3D(-14,10,10), Point3D(-10,10,15), Point3D(-14,10,15),a, Point(cx, cy));
// Mitte, weiter Vorne
Draw3DRect(Canvas, Point3D(0,10,5), Point3D(-5,10,5), Point3D(0,10,8), Point3D(-5,10,8),a, Point(cx, cy));
// Rechts, weiter Vorne
Draw3DRect(Canvas, Point3D(5,10,5), Point3D(10,10,5), Point3D(5,10,7), Point3D(10,10,7),a, Point(cx, cy));
Draw3DRect(Canvas, Point3D(5,10,20), Point3D(10,10,20), Point3D(5,10,22), Point3D(10,10,22),a, Point(cx, cy));
Draw3DRect(Canvas, Point3D(-10,10,20), Point3D(-14,10,20), Point3D(-10,10,22), Point3D(-14,10,22),a, Point(cx, cy));
Draw3DRect(Canvas, Point3D(0,10,30), Point3D(-5,10,30), Point3D(0,10,36), Point3D(-5,10,36),a, Point(cx, cy));
end;
// TMySkyroads.Paint