Einzelnen Beitrag anzeigen

Benutzerbild von igel457
igel457

Registriert seit: 31. Aug 2005
1.622 Beiträge
 
FreePascal / Lazarus
 
#334

Re: Andorra 2D [Ver. 0.20 ALPHA 2, 05.10.07]

  Alt 21. Okt 2007, 13:43
Nach wie vor ist das natürlich von OpenGl oder Direct3d unabhängig und läuft mit beidem.
Spezielle OpenGl/DirectX Funktionen kommen nicht zum Einsatz - an der Plugin-DLL wurde nichts verändert.
Vielmehr generiere ich aus dickeren Linien ein Polygon:
Delphi-Quellcode:

function OrthogonalPoints(x1, y1, x2, y2, d: integer): TAdCanvasQuad;
var
  alpha:double;
  l:double;
begin
  FillChar(result, SizeOf(result), 0);

  l := sqrt(sqr(x2-x1)+sqr(y2-y1));

  if l > 0 then
  begin
    alpha := arccos((x2-x1)/l);

    if (y2 > y1) then
    begin
      alpha := 2 * pi - alpha;
    end;
    alpha := - alpha;

    result.p1.X := x1 + cos(alpha + 0.5*pi) * d / 2;
    result.p1.Y := y1 + sin(alpha + 0.5*pi) * d / 2;
    result.p2.X := x1 + cos(alpha - 0.5*pi) * d / 2;
    result.p2.Y := y1 + sin(alpha - 0.5*pi) * d / 2;

    result.p3.X := x2 + cos(alpha + 0.5*pi) * d / 2;
    result.p3.Y := y2 + sin(alpha + 0.5*pi) * d / 2;
    result.p4.X := x2 + cos(alpha - 0.5*pi) * d / 2;
    result.p4.Y := y2 + sin(alpha - 0.5*pi) * d / 2;
  end;
end;

[...]

    //Calculate Vertices
    FPoints.StartIteration;
    i := 0;
    lp := nil;
    while not FPoints.ReachedEnd do
    begin
      cp := PAdLinePoint(FPoints.GetCurrent);

      [...]

      if lp <> nil then
      begin
        FLastQuad := quad;
        quad := OrthogonalPoints(lp^.x, lp^.y, cp^.x, cp^.y, FPen.Width);

        Vertices[i*2].Position := AdVector3(quad.p3.x, quad.p3.y, 0);
        Vertices[i*2].Color := cp^.Color;
        Vertices[i*2+1].Position := AdVector3(quad.p4.x, quad.p4.y, 0);
        Vertices[i*2+1].Color := cp^.Color;

        if i = 1 then
        begin
          Vertices[0].Position := AdVector3(quad.p1.x, quad.p1.y, 0);
          Vertices[0].Color := lp^.Color;
          Vertices[1].Position := AdVector3(quad.p2.x, quad.p2.y, 0);
          Vertices[1].Color := lp^.Color;
        end;
      end;

      lp := cp;
      i := i + 1;
    end;

[...]

    //Calculate Indices
    for i := 0 to FPoints.Count - 2 do
    begin
      Indices[i * 6] := (i * 2) + 1;
      Indices[i * 6 + 1] := (i * 2);
      Indices[i * 6 + 2] := (i * 2) + 2;
      Indices[i * 6 + 3] := (i * 2) + 1;
      Indices[i * 6 + 4] := (i * 2) + 2;
      Indices[i * 6 + 5] := (i * 2) + 3;
    end;
DirectX (über IDXLine oder sö ähnlich) oder OpenGl (über SetLineWidth oder so) machen das vermutlich intern genauso.

Zur Veranschaulichung habe ich nochmal ein Bild angehängt:
Miniaturansicht angehängter Grafiken
canvasline_117.png  
Andreas
"Sollen sich auch alle schämen, die gedankenlos sich der Wunder der Wissenschaft und Technik bedienen, und nicht mehr davon geistig erfasst haben als die Kuh von der Botanik der Pflanzen, die sie mit Wohlbehagen frisst." - Albert Einstein
  Mit Zitat antworten Zitat