![]() |
Re: Bitmap perspektivisch in 3D drehen
Hat jemand eine schnelle Lösung für einen PlgBltersatz der die Textur in der z-Achse kleiner werden lässt? Meine Variante baut auf WarpBlt auf:
Delphi-Quellcode:
und ist zu langsam. Selbst, wenn man GetPixel und Setpixel durch direkte Speicherzugriffe beschleunigt, ist die Geschwindigkeit inakzeptabel :(
procedure CopySourceToDest(hdcDst: HDC; ul, ur, lr, ll: TPoint;
hdcSrc: HDC; x1, y1, x2, y2: LONGINT); var tm, lm, rm, bm, m: TPoint; mx, my: Longint; cr: COLORREF; begin // Does the destination area specify a single pixel? if ((abs(ul.x - ur.x) < THRESH) and (abs(ul.x - lr.x) < THRESH) and (abs(ul.x - ll.x) < THRESH) and (abs(ul.y - ur.y) < THRESH) and (abs(ul.y - lr.y) < THRESH) and (abs(ul.y - ll.y) < THRESH)) then begin cr := GetPixel(hdcSrc, (x1 shr SHIFTS), (y1 shr SHIFTS)); SetPixel(hdcDst, (ul.x shr SHIFTS), (ul.y shr SHIFTS), cr); end else begin // No // Quarter the source and the destination, and then recurse. tm.x := (ul.x + ur.x) shr 1; tm.y := (ul.y + ur.y) shr 1; bm.x := (ll.x + lr.x) shr 1; bm.y := (ll.y + lr.y) shr 1; lm.x := (ul.x + ll.x) shr 1; lm.y := (ul.y + ll.y) shr 1; rm.x := (ur.x + lr.x) shr 1; rm.y := (ur.y + lr.y) shr 1; m.x := (tm.x + bm.x) shr 1; m.y := (tm.y + bm.y) shr 1; mx := (x1 + x2) shr 1; my := (y1 + y2) shr 1; CopySourceToDest(hdcDst, ul, tm, m, lm, hdcSrc, x1, y1, mx, my); CopySourceToDest(hdcDst, tm, ur, rm, m, hdcSrc, mx, y1, x2, my); CopySourceToDest(hdcDst, m, rm, lr, bm, hdcSrc, mx, my, x2, y2); CopySourceToDest(hdcDst, lm, m, bm, ll, hdcSrc, x1, my, mx, y2); end; end; procedure WarpBlt(hdcDst: HDC; ul, ur, lr, ll: TPoint; hdcSrc: HDC; x1, y1, x2, y2: Longint); begin ul.x := ul.x shl SHIFTS; ul.y := ul.y shl SHIFTS; ur.x := ur.x shl SHIFTS; ur.y := ur.y shl SHIFTS; lr.x := lr.x shl SHIFTS; lr.y := lr.y shl SHIFTS; ll.x := ll.x shl SHIFTS; ll.y := ll.y shl SHIFTS; x1 := x1 shl SHIFTS; y1 := y1 shl SHIFTS; x2 := x2 shl SHIFTS; y2 := y2 shl SHIFTS; CopySourceToDest(hdcDst, ul, ur, lr, ll, hdcSrc, x1, y1, x2, y2); end; Peter [edit=SirThornberry]Delphi-Tags gesetzt - Mfg, SirThornberry[/edit] |
Re: Bitmap perspektivisch in 3D drehen
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,
also an und für sich hab ich das jetzt ganz schön hinbekommen. Nur die Winkelberechnung da probier ich ewig in der gegend rum aber checks irgendwie nich :-( leider... soll ja so ca aussehen wie madotate... wenn das einer kennt. also so weit hab ichs mal:
Delphi-Quellcode:
so sieht das auch ganz nett aus aber nur auf nem 1600 x 1200 er Monitor und ausserdem isses irgendwie ...naja sieht zwar nett aus aber is noch nich die richtige perspektive so...
procedure TForm2.DoDrawEx(ACanvas: TCanvas; ALeft, ATop: Integer);
var l3DObj : T3DObj; lDestPoints : Array[0..2] of TPoint; lPoint : T3DPoint; lDrawHeight, lDrawWidth : Integer; begin l3DObj := T3DObj.Create(nil); lDrawHeight := image2.Height; lDrawWidth := image2.Width; l3DObj.DoubleBuffered := True; l3DObj.Add((lDrawWidth - fBmp.Width) div 2, (lDrawHeight - fBmp.Height) div 2, lDrawWidth div 2); l3DObj.Add((lDrawWidth - fBmp.Width) div 2 + fBmp.Width, (lDrawHeight - fBmp.Height) div 2, lDrawWidth div 2); l3DObj.Add((lDrawWidth - fBmp.Width) div 2, fBmp.Height + (lDrawHeight - fBmp.Height) div 2, lDrawWidth div 2); lPoint := l3DObj.CenterPoint; lPoint.X := l3DObj.Points[0].X + (l3DObj.Points[1].X - l3DObj.Points[0].X) div 2; lPoint.Y := l3DObj.Points[0].Y + (l3DObj.Points[2].Y - l3DObj.Points[0].Y) div 2; lPoint.Z := lDrawWidth div 2; l3DObj.CenterPoint := lPoint; //------------- l3DObj.WinkelXY := trunc( (Top / 24) + (Screen.Height / 15) ); //(Top/10)+ 55); l3DObj.WinkelYZ := trunc( ( (left / 12) + (Screen.Width / 60) ) *-1 ); //((left/12)+40)*-1); //------------- SetStretchBltMode(ACanvas.Handle, STRETCH_HALFTONE); SetBrushOrgEx(ACanvas.Handle, 0, 0, nil); lDestPoints[0] := Point(l3DObj.CalcedPoints[0].Z, l3DObj.CalcedPoints[0].Y); lDestPoints[1] := Point(l3DObj.CalcedPoints[1].Z, l3DObj.CalcedPoints[1].Y); lDestPoints[2] := Point(l3DObj.CalcedPoints[2].Z, l3DObj.CalcedPoints[2].Y); Windows.PlgBlt(ACanvas.Handle, lDestPoints, fBmp.Canvas.Handle, 0, 0, fBmp.Width, fBmp.Height, 0, 0, 0); l3DObj.Free; end; achja und die perspektivische verzerrung nach hinten... sollte ja eher wie ein Trapez aussehen...das fehlt mir auch noch und im Internet find ich nicht wirklich viel dazu ...leider... nur unter OpenGL oder DirectX da wärs kein Problem. Aber DirectX und OpenGL kann ich ja nicht transparent auf den desktop zeichnen. Daher wär da ne funktion die das bitmap so bearbeitet auch noch ne tolle sache. kennt sich einer von euch da bischen aus? Wär echt toll :-) Gruß Tom |
Re: Bitmap perspektivisch in 3D drehen
Hi,
ok also den einen Winkel hab ich jetzt an den Monitor angepasst und zwar so: l3DObj.WinkelYZ := trunc( ( (XLeft - (Screen.Width/2) ) /30) ); nur Nr2 stimmt noch nich leider... und da gehts auch nich wenn ichs einfach genauso mach wie in dem oben... ja und für die trapez verzerrung hab ich auch was gefunden aber da hab ich ein problem an der Stelle savetostream und loadfromstream... ich bekomme keinen Fehler vom Compiler oder so, aber das Image32 is einfach leer... ich verstehs nich...
Delphi-Quellcode:
procedure TForm2.MakeTrapezStretch(PTX0,PTY0,PTX1,PTY1,PTX2,PTY2,PTX3,PTY3 : Integer;SrcBMP,DstBMP : TBitmap); Var // Objekt für die Transformation PT: TProjectiveTransformation; srcBMPX, dstBMPX : TImage32; tempstream : TMemoryStream; begin tempstream := TMemoryStream.Create; srcBMPX := TImage32.Create(Form2); dstBMPX := TImage32.Create(Form2); SrcBMP.SaveToStream(tempstream); srcBMPX.Bitmap.LoadFromStream(tempstream); tempstream.Free; PT:=TProjectiveTransformation.Create; //Oben/Linke PT.X0:= PTX0; //30; PT.Y0:= PTY0; //0; //Oben/Rechts PT.X1:= PTX1; //Src.Bitmap.Width-30; PT.Y1:= PTY1; //0; //Unten/Rechts PT.X2:= PTX2; //Src.Bitmap.Width; PT.Y2:= PTY2; //Src.Bitmap.Height; //Unten/Links PT.X3:= PTX3; //0; PT.Y3:= PTY3; //Src.Bitmap.Height; PT.SrcRect:=FloatRect(0,0,SrcBMPX.Width-1,SrcBMPX.Height-1); DstBMPX.BeginUpdate; DstBMPX.Bitmap.Clear(0); Transform(DstBMPX.Bitmap,SrcBMPX.Bitmap,PT); DstBMPX.EndUpdate; DstBMPX.Invalidate; tempstream := TMemoryStream.Create; dstBMPX.Bitmap.SaveToStream(tempstream); DstBMP.LoadFromStream(tempstream); PT.Free; DstBMPX.Free; srcBMPX.Free; tempstream.Free; end; |
Re: Bitmap perspektivisch in 3D drehen
Zwischen "SaveToStream" und "LoadFromStream" die Position im Stream wieder auf 0 setzen.
|
Re: Bitmap perspektivisch in 3D drehen
Dein desktop mit gedrehten Fenstern sieht aus wie ein Patent, was Apple vor kurzem eingereicht hatte zur Räumlichen Darstellung von Desktops.
Gruß Matthias |
Re: Bitmap perspektivisch in 3D drehen
Hi,
also einmal DANKE :-) für das mit den Streams das klappt jetzt *freu* und dann hab ich nun den zweiten winkel auch noch hinbekommen: l3DObj.WinkelXY := trunc(90 - ((XTop -(Screen.Height/2))/30)); l3DObj.WinkelYZ := trunc( ( (XLeft - (Screen.Width/2) ) /30) *-1 ); so jetzt klappt fast alles nur transparentcolor wird verhaun von meiner trapezverzerrung an dieser stelle: DstBMPX.Bitmap.Clear(Color32(TransparentColorValue )); und natürlich muss ich da die winkel auch noch anpassen...also rumprobieren *g* so falls jemand das brauchen kann:
Delphi-Quellcode:
procedure TForm2.DoDrawEx(ACanvas: TCanvas; ALeft, ATop: Integer);
var l3DObj : T3DObj; lDestPoints : Array[0..2] of TPoint; lPoint : T3DPoint; lDrawHeight, lDrawWidth : Integer; XLeft, XTop : Integer; begin //------------Trapezverz. if not CalculatingPic then begin CalculatingPic := True; fBmp := image2.Picture.Bitmap; l3DObj := T3DObj.Create(nil); lDrawHeight := fBmp.Height; // + StretchX damit irgendwie das resizen zur ca originalgröße machen lDrawWidth := fBmp.Width; l3DObj.DoubleBuffered := True; l3DObj.Add((lDrawWidth - fBmp.Width) div 2, (lDrawHeight - fBmp.Height) div 2, lDrawWidth div 2); l3DObj.Add((lDrawWidth - fBmp.Width) div 2 + fBmp.Width, (lDrawHeight - fBmp.Height) div 2, lDrawWidth div 2); l3DObj.Add((lDrawWidth - fBmp.Width) div 2, fBmp.Height + (lDrawHeight - fBmp.Height) div 2, lDrawWidth div 2); lPoint := l3DObj.CenterPoint; lPoint.X := l3DObj.Points[0].X + (l3DObj.Points[1].X - l3DObj.Points[0].X) div 2; lPoint.Y := l3DObj.Points[0].Y + (l3DObj.Points[2].Y - l3DObj.Points[0].Y) div 2; lPoint.Z := lDrawWidth div 2; l3DObj.CenterPoint := lPoint; XLeft := Left + Trunc(lDrawWidth / 2); XTop := Top + Trunc(lDrawHeight / 2); l3DObj.WinkelXY := trunc(90 - ((XTop -(Screen.Height/2))/30)); l3DObj.WinkelYZ := trunc( ( (XLeft - (Screen.Width/2) ) /30) *-1 ); //--------------------------------------------------------- if Left > (Screen.Width / 2) then begin if Top > (Screen.Height / 2) then begin //rechts unten MakeTrapezStretch(0,trunc((XTop -(Screen.Height/2))/60), //unten/Linke fBmp.Width--trunc((XTop -(Screen.Height/2))/60),0, //Oben/links fBmp.Width,fBmp.Height, //oben/Rechts 0,fBmp.Height, //Unten/rechts fBmp,fBmp); end else begin //rechts oben MakeTrapezStretch(0,trunc((XTop -(Screen.Height/2))/60), //unten/Linke fBmp.Width--trunc((XTop -(Screen.Height/2))/60),0, //Oben/links fBmp.Width,fBmp.Height, //oben/Rechts 0,fBmp.Height, //Unten/rechts fBmp,fBmp); end; end else begin if Top > (Screen.Height / 2) then begin //links unten MakeTrapezStretch(trunc((XTop -(Screen.Height/2))/60),0, //unten/Linke fBmp.Width-trunc((XTop -(Screen.Height/2))/60),0, //Oben/links fBmp.Width,fBmp.Height, //oben/Rechts 0,fBmp.Height, //Unten/rechts fBmp,fBmp); end else begin //links oben MakeTrapezStretch(trunc((XTop -(Screen.Height/2))/60),0, //unten/Linke fBmp.Width-trunc((XTop -(Screen.Height/2))/60),0, //Oben/links fBmp.Width,fBmp.Height, //oben/Rechts 0,fBmp.Height, //Unten/rechts fBmp,fBmp); end; end; //--------------------------------------------------------- SetStretchBltMode(ACanvas.Handle, STRETCH_HALFTONE); SetBrushOrgEx(ACanvas.Handle, 0, 0, nil); lDestPoints[0] := Point(l3DObj.CalcedPoints[0].Z, l3DObj.CalcedPoints[0].Y); lDestPoints[1] := Point(l3DObj.CalcedPoints[1].Z, l3DObj.CalcedPoints[1].Y); lDestPoints[2] := Point(l3DObj.CalcedPoints[2].Z, l3DObj.CalcedPoints[2].Y); Windows.PlgBlt(ACanvas.Handle, lDestPoints, fBmp.Canvas.Handle, 0, 0, fBmp.Width, fBmp.Height, 0, 0, 0); l3DObj.Free; CalculatingPic := False; end; end; procedure TForm2.MakeTrapezStretch(PTX0,PTY0,PTX1,PTY1,PTX2,PTY2,PTX3,PTY3 : Integer;SrcBMP,DstBMP : TBitmap); Var // Objekt für die Transformation PT: TProjectiveTransformation; srcBMPX, dstBMPX : TImage32; tempstream : TMemoryStream; begin srcBMPX := TImage32.Create(Form2); dstBMPX := TImage32.Create(Form2); tempstream := TMemoryStream.Create; SrcBMP.SaveToStream(tempstream); tempstream.Position := 0; srcBMPX.Bitmap.LoadFromStream(tempstream); PT:=TProjectiveTransformation.Create; //Oben/Linke PT.X0:= PTX0; PT.Y0:= PTY0; //Oben/Rechts PT.X1:= PTX1; PT.Y1:= PTY1; //Unten/Rechts PT.X2:= PTX2; PT.Y2:= PTY2; //Unten/Links PT.X3:= PTX3; PT.Y3:= PTY3; PT.SrcRect:=FloatRect(0,0,SrcBMPX.Width,SrcBMPX.Height); DstBMPX.Bitmap.Width:=SrcBMPX.Bitmap.Width; DstBMPX.Bitmap.Height:=SrcBMPX.Bitmap.Height; DstBMPX.BeginUpdate; DstBMPX.Bitmap.Clear(Color32(TransparentColorValue)); Transform(DstBMPX.Bitmap,SrcBMPX.Bitmap,PT); DstBMPX.EndUpdate; DstBMPX.Invalidate; tempstream.Clear; tempstream.Position := 0; dstBMPX.Bitmap.SaveToStream(tempstream); tempstream.Position := 0; DstBMP.LoadFromStream(tempstream); PT.Free; tempstream.Free; DstBMPX.Free; srcBMPX.Free; end; hmmm ob Apple da was gemacht hat weiß ich nich, es gibt aber eben die Freeware Madotate die auch so ähnlich is, und ich glaub von Stardock gibts auch sowas in der Art. Gruß Tom |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:43 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz