Einzelnen Beitrag anzeigen

Benutzerbild von alleinherrscher
alleinherrscher

Registriert seit: 8. Jul 2004
Ort: Aachen
797 Beiträge
 
Delphi XE2 Professional
 
#9

Re: [Projekt] CoverFlow mit Gr32

  Alt 29. Jun 2008, 13:46
Danke, das freut mich sehr... übrigens, wenn du 90 Grad als Winkel eingibst, stehen die Cover ja praktisch genau senkrecht zur Betrachterebene, d.h. du kannst einfach folgende PaintCover Procedure verwenden, dann gibts keine Division durch null mehr:

Delphi-Quellcode:
procedure PaintCover(DestBitmap:TBitmap32; x,y,width,height:integer; perspectiv:single;angle:integer; Abdunklung:integer;Alpha:integer; picture:TBitmap32);
var lo,lu,ro,ru:TPoint;
    mo,mu:extended;
    i,j:integer;
    dummy:integer;
    color:tcolor32;
    reflextionlength:integer;
    Points:TArrayOfFixedPoint;
    poly:tPolygon32;
begin


//vier Eckpunkte des Covers berechnen:

lo.x:=x;
lo.Y:=y;
lu.X:=x;
lu.Y:=y+height;
ru.x:=round(lu.x+width*cos(abs(angle)/360*2*Pi));
ru.y:=round(lu.y-perspectiv*height/2*sin(abs(angle)/360*2*Pi));
ro.X:=ru.x;
ro.Y:=round(ru.y-height+perspectiv*height*sin(abs(angle)/360*2*Pi));

if angle<0 then
begin
  dummy:=ro.y;
  ro.y:=lo.y;
  lo.y:=dummy;
  dummy:=ru.y;
  ru.y:=lu.y;
  lu.y:=dummy;
  dummy:=(width-(ro.x-lo.x));
  lo.x:=lo.x+dummy;
  lu.x:=lu.X+dummy;
  ro.x:=ro.X+dummy;
  ru.x:=ru.x+dummy;
end;

//Steigung der oberen und unteren Kante berechnen:


if ((ro.x-lo.X)=0) or ((ru.x-lu.x)=0) then exit; //Cover stehen senkrecht zum Betrachter

  mo:=-(ro.Y-lo.Y)/(ro.x-lo.X);
  mu:=-(ru.Y-lu.Y)/(ru.x-lu.x);


//Bild perspektivisch zeichnen:
DestBitmap.BeginUpdate;

for i:=0 to (ro.X-lo.x) do
 for j:=round(-i*mo) to round((lu.Y-lo.y)+i*mo) do
   begin
     if not (lo.x+i>DestBitmap.Width-1) and not (lo.y+j>DestBitmap.Height-1) then
       if not (lo.x+i<0) and not (lo.y+j<0) then
         begin
          color:=picture.Pixels[round(picture.Width/(ro.x-lo.X)*i), round(picture.Height/((lu.Y-lo.y)+2*i*mo)*(j+i*mo))];
          TColor32Entry(color).A := alpha;
          DestBitmap.SetPixelT(lo.X+i,lo.Y+j,color);
         end;
   end;
  
 //Reflextion berechnen:

for i:=0 to (ro.X-lo.x) do
 begin
  ReflextionLength:=round(((lu.y-lo.y)+(mo*i)));
  if ReflextionLength>0 then
     for j:= 0 to ReflextionLength do
       begin
        if not (lo.x+i>DestBitmap.Width-1) and not (lu.Y+round(mo*i)+j>DestBitmap.Height-1) then
         if not (lo.x+i<0) and not (lu.Y+round(mo*i)+j<0) then
           begin
             color:=DestBitmap.Pixel[lo.X+i,lu.Y+round(mo*i)-j];
             color:=GR32_Blend.Lighten(color,round(-Abdunklung)); //Reflextion ist verdunkeltes und gespiegeltes Original
             //TColor32Entry(color).A := round(alpha*(1-1/ReflextionLength*j)); //Transparente Reflextionen mit AlphaBlending
             DestBitmap.SetPixelT(lo.X+i,lu.Y+round(mo*i)+j,color);
           end;
       end;
 end;



//Rechteck zeichnen:

  poly:=TPolygon32.create;
  poly.Add(fixedpoint(lo.x,lo.Y));
  poly.Add(fixedpoint(lu.x,lu.y));
  poly.Add(fixedpoint(ru.x,ru.y));
  poly.Add(fixedpoint(ro.x,ro.y));
  poly.AntialiasMode:=am32times; //32faches Antialiasing bremst die Darstellung und kann auch deaktiviert werden
  poly.Antialiased:=true;
  poly.Closed:=true;
  poly.DrawEdge(DestBitmap,Color32(20,20,20,255));

  freeandnil(poly);



DestBitmap.EndUpdate;

end;
Wenn jemand lust hat, ein bisschen weiter dran zu schreiben, fänd ich das sehr cool!

Grüße und schönes Fussball WE,

Euer Alleinherrscher

[edit=Matze]Leerzeichen eingefügt, da ein horizontaler Scrollbalken erzeugt wurde. MfG, Matze[/edit]
„Software wird schneller langsamer als Hardware schneller wird. “ (Niklaus Wirth, 1995)

Mein Netzwerktool: Lan.FS
  Mit Zitat antworten Zitat