here's a little snippet of some old Delphi 3D code I wrote, it's even got comments, not sure how useful they are ... check out the tranform procedure at the bottom hehe.
here's another bit:
It all worked well, it was a 3D screensaver.
procedure TMain.FillPolyPoints; var n: Integer; begin {rotate Normal point} x := NX[DrawingPoly]; y := NY[DrawingPoly]; z := NZ[DrawingPoly]; Transform; {get Normal Unit vector} NormU := round(Sqrt (tx*tx + ty*ty + tz*tz)); If NormU = 0 then NormU := 1; nsx := tx/NormU; nsy := ty/NormU; nsz := tz/NormU; {rotate Line Of Sight point ... 1st point on polygon} Offset := E[EdgeOffset[DrawingPoly]]; x := PX[Offset]; y := PY[Offset]; z := PZ[Offset]; Transform; tz := tz + persp; {get Line Of Sight Unit vector} LOSU := round(Sqrt (tx*tx + ty*ty + tz*tz)); If LOSU = 0 then LOSU := 1; lx := tx/LOSU; ly := ty/LOSU; lz := tz/LOSU; {calc illumination} ilum := lx*nsx + ly*nsy + lz*nsz; If ilum < 0 then DrawIt := True else begin DrawIt := False; exit; end; For n := 0 to DrawingPolyNoEdges do begin Offset := E[EdgeOffset[DrawingPoly]+n]; //// starting point x := PX[Offset]; y := PY[Offset]; z := PZ[Offset]; Transform; // calc perspective ratio denom := tz + persp; If denom = 0 then denom := 1; // plot screen point with perspective PolyPoints[n].X := CenterX + (tx * persp) div denom ; PolyPoints[n].Y := CenterY + (ty * persp) div denom; end; end; //*************************** procedure TMain.Transform; begin //// x axis //// y1 := (y*c1 + z*-s1) div scale; z1 := (y*s1 + z*c1) div scale; //// y axis //// x2 := (x*c2 + z1*s2) div scale; tz := (x*-s2 + z1*c2) div scale; //// z axis //// tx := ( x2*c3 + y1*-s3) div scale; ty := ( x2*s3 + y1*c3) div scale; ////movement tz := tz + Zoom; tx := tx + offx; ty := ty + offy; end;
here's another bit:
procedure TMain.CalcNormals; var n : Integer; l1x, l1y, l1z: Integer; l2x, l2y, l2z: Integer; begin For n := 0 to NumPolys do begin Offset := EdgeOffset[n]; l1x := PX[E[Offset+1]] - PX[E[Offset+0]]; l1y := PY[E[Offset+1]] - PY[E[Offset+0]]; l1z := PZ[E[Offset+1]] - PZ[E[Offset+0]]; l2x := PX[E[Offset+2]] - PX[E[Offset+1]]; l2y := PY[E[Offset+2]] - PY[E[Offset+1]]; l2z := PZ[E[Offset+2]] - PZ[E[Offset+1]]; NX[n] := l1y*l2z - l1z*l2y; NY[n] := l1z*l2x - l1x*l2z; NZ[n] := l1x*l2y - l1y*l2x; end; end;
It all worked well, it was a 3D screensaver.