Einzelnen Beitrag anzeigen

Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#13

Re: Pixelkoordinaten einer Linie

  Alt 28. Jul 2007, 18:31
Delphi-Quellcode:
function TSpieler.FreieSicht(x1,y1,x2,y2,nummer:integer):boolean;
var
m: double; // <-- Steigungskonstante
x3, y3: integer; // <-- Spielerkoordinaten
begin
  x3 := mdaten.daten[nummer].X;
  y3 := mdaten.daten[nummer].Y;

  // Wenn P1 und P2 senkrecht stehen:
  if (x1 = x2) and (x3 = x1) then
    Result:=y3 >= y1) and (y3 <= y2)) or ((y3 <= y1) and (y3 >= y2)
  else begin
    m := (y2-y1)/(x2-x1); // Berechnung der Steigung
    Result:=((x3 >= x1) and (x3 <= x2)) or ((x3 <= x1) and (x3 >= x2))
      and (y3 = round(x3 * m + y1));
  end;
end;
Das finde ich etwas einfacher.
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat