home *** CD-ROM | disk | FTP | other *** search
- Unit Gr3d_pt;
- {$N+,E+}
-
- interface
-
- uses
- MM_Mem, Graph;
-
- const
- GraphMidX: integer = 0;
- GraphMidY: integer = 0;
- DefaultColor: integer = Black;
- BackColor: integer = Black;
-
-
- type
-
- float = real;
-
- P3dPoint = ^T3dPoint;
- T3dPoint = record
- x, y, z: integer;
- end;
-
- P2dPoint = ^T2dPoint;
- T2dPoint = record
- x, y: integer;
- end;
-
- PPointGroup = ^TPointGroup;
- TPointGroup = object
- M: PMatrix;
- N: integer;
- constructor Init(InitX, InitY, InitZ: integer);
- destructor Done;
- procedure Move(DX, DY, DZ: integer); virtual;
- procedure Draw; virtual;
- procedure Hide; virtual;
- procedure RotateXZ(Angle: integer); virtual;
- procedure Rotate(AngleXZ, AngleXY, AngleYZ: integer); virtual;
- procedure InsertPoint(NewX, NewY, NewZ: integer);
- procedure Assign(R: byte; NewX, NewY, NewZ: integer);
- function Getx(R: byte): integer;
- function Gety(R: byte): integer;
- function Getz(R: byte): integer;
- end;
-
- procedure ConvertPoint(x,y,z: integer; var Sx, Sy: integer);
- procedure M3dShift(var M: PMatrix; Dx, Dy, Dz: integer);
-
- implementation
-
- procedure ConvertPoint(x,y,z: integer; var Sx, Sy: integer);
- begin
- if y <> 0 then
- begin
- Sx := (x*GraphMidx) div y + GraphMidx;
- Sy := GraphMidY - (z*GraphMidy) div y;
- end
- else
- begin
- Sx := x*GraphMidx;
- Sy := -z*GraphMidy;
- end;
- end;
-
- procedure M3dShift(var M: PMatrix; Dx, Dy, Dz: integer);
- var
- i: integer;
- begin
- for i := 1 to M^.DimRow do
- begin
- Inc(GetPtr(M, i, 1)^, Dx);
- Inc(GetPtr(M, i, 2)^, Dy);
- Inc(GetPtr(M, i, 3)^, Dz);
- end;
- end;
-
- {------------------}
- { TPointGroup }
-
- constructor TPointGroup.Init(InitX, InitY, InitZ: integer);
- begin
- N := 1;
- NewMatrix(M, N, 3);
- Assign(1, InitX, InitY, InitZ);
- end;
-
- destructor TPointGroup.Done;
- begin
- DelMatrix(M);
- end;
-
- procedure TPointGroup.InsertPoint(NewX, NewY, NewZ: integer);
- var
- T: PMatrix;
- begin
- N := N+1;
- NewMatrix(T, 1, 3);
- MStoreVal(T, 1, 1, NewX);
- MStoreVal(T, 1, 2, NewY);
- MStoreVal(T, 1, 3, NewZ);
- MInsert(M,T,M^.DimRow+1);
- DelMatrix(T);
- end;
-
- procedure TPointGroup.Assign(R: byte; NewX, NewY, NewZ: integer);
- begin
- MStoreVal(M, R, 1, NewX);
- MStoreVal(M, R, 2, NewY);
- MStoreVal(M, R, 3, NewZ);
- end;
-
- procedure TPointGroup.Move(DX, DY, DZ: integer);
- begin
- M3dShift(M, Dx, Dy, Dz);
- end;
-
- function TPointGroup.Getx(R: byte): integer;
- var
- Result: integer;
- begin
- MGetVal(M, R, 1, TMCell(Result));
- Getx := Result;
- end;
-
- function TPointGroup.Gety(R: byte): integer;
- var
- Result: integer;
- begin
- MGetVal(M, R, 2, TMCell(Result));
- Gety := Result;
- end;
-
- function TPointGroup.Getz(R: byte): integer;
- var
- Result: integer;
- begin
- MGetVal(M, R, 3, TMCell(Result));
- Getz := Result;
- end;
-
- procedure TPointGroup.Draw;
- begin
- end;
-
- procedure TPointGroup.Hide;
- var
- TempC: Integer;
- begin
- TempC := GetColor;
- SetColor(BackColor);
- Draw;
- SetColor(TempC);
- end;
-
- procedure TPointGroup.RotateXZ(Angle: integer);
- var
- Trans, Temp, R: PMatrix;
- VCos, VSin: float;
- P1, P2: P3dPoint;
- i,j: integer;
- const
- Factor: integer = 100;
- begin
- VCos := cos(Angle*pi/180);
- VSin := sin(Angle*pi/180);
- NewMatrix(Trans, M^.DimRow, M^.DimCol);
- for i := 1 to M^.DimRow do
- begin
- P1 := P3dPoint(GetPtr(M,i,1));
- P2 := P3dPoint(GetPtr(Trans,i,1));
- P2^.x := Trunc(P1^.x*VCos+P1^.z*VSin);
- P2^.y := P1^.y;
- P2^.z := Trunc(-P1^.x*VSin+P1^.z*VCos);
- end;
-
- Temp := M;
- M := Trans;
- Draw;
- M := Temp;
- DelMatrix(Trans);
- end;
-
- procedure TPointGroup.Rotate(AngleXZ, AngleXY, AngleYZ: integer);
- var
- Trans, Temp, R: PMatrix;
- VCosXZ, VSinXZ: float;
- VCosXY, VSinXY: float;
- VCosYZ, VSinYZ: float;
- P1, P2: P3dPoint;
- i: integer;
- begin
- VCosXZ := cos(AngleXZ*pi/180);
- VSinXZ := sin(AngleXZ*pi/180);
- VCosXY := cos(AngleXY*pi/180);
- VSinXY := sin(AngleXY*pi/180);
- VCosYZ := cos(AngleYZ*pi/180);
- VSinYZ := sin(AngleYZ*pi/180);
- NewMatrix(Trans, M^.DimRow, M^.DimCol);
-
- for i := 1 to M^.DimRow do
- begin
- P1 := P3dPoint(GetPtr(M,i,1));
- P2 := P3dPoint(GetPtr(Trans,i,1));
- if AngleXZ<>0 then
- begin
- P2^.x := Trunc(P1^.x*VCosXZ+P1^.z*VSinXZ);
- P2^.y := P1^.y;
- P2^.z := Trunc(-P1^.x*VSinXZ+P1^.z*VCosXZ);
- end;
- if AngleXY<>0 then
- begin
- P2^.x := Trunc(P1^.x*VCosXY+P1^.y*VCosXY);
- P2^.y := Trunc(-P1^.x*VSinXY+P1^.y*VCosXY);
- P2^.z := P1^.z;
- end;
- if AngleYZ<>0 then
- begin
- P2^.x := P1^.x;
- P2^.y := Trunc(P1^.y*VCosYZ+P1^.z*VSinYZ);
- P2^.z := Trunc(-P1^.y*VSinYZ+P1^.z*VCosYZ);
- end;
- end;
-
- Temp := M;
- M := Trans;
- Draw;
- M := Temp;
- DelMatrix(Trans);
- end;
- end. {Unit}