Einzelnen Beitrag anzeigen

.chicken

Registriert seit: 5. Dez 2006
459 Beiträge
 
#37

Re: Pong - Problem bei der Ballkollision

  Alt 11. Dez 2006, 17:22
Alles ausser Class is doch fast das ganze Projekt!? Oder meinste damit alles ausser der Elements.pas?

Da sind soviele Variablen, dass ich bei jeder Prozedur tausend mal nachgucken muss, was das war...

Naja dann dauert des ganze halt ma zwei Stunden Ich setz mich heute Abend ma dran...

Delphi-Quellcode:
Function EllipseRechteckcollision(E1, R1: Trect): boolean;
Type
  Tpunkt = Record
    X, Y: Extended;
  End;
Var
  SN1, SN2, X, Alpha: extended;
  p1, p2: Tpoint;
  N1, N2: Tpunkt;
  radius1, radius2: integer;
Begin
  result := false;
  If E1.left > E1.right Then tausche(E1.left, E1.right);
  If E1.Top > E1.bottom Then tausche(E1.top, E1.bottom);
  If r1.left > r1.right Then tausche(r1.left, r1.right);
  If r1.Top > r1.bottom Then tausche(r1.top, r1.bottom);
  p1.x := E1.left + ((E1.right - E1.left) Div 2);
  p1.y := E1.top + ((E1.Bottom - E1.top) Div 2);
  p2.x := r1.left + ((r1.right - r1.left) Div 2);
  p2.y := r1.top + ((r1.Bottom - r1.top) Div 2);
  Alpha := arcTangens(p1.x - p2.x, p1.y - p2.y);
  X := Hypot(p1.x - p2.x, p1.y - p2.y);
  Radius1 := p1.x - E1.left;
  Radius2 := p1.y - E1.top; // Radius 1 Horizontal, Radius2 Vertikal
  N1.X := cosinus(alpha) * radius1 + P1.X;
  N1.Y := sinus(Alpha) * radius2 + P1.Y;
  SN1 := Hypot(p1.x - n1.x, p1.y - n1.y);
  Case round(Alpha) Of
    0..45: Begin
        n2.x := R1.right;
        n2.y := round(tangens(alpha) * ((r1.Bottom - p2.y) / 2)) + p2.y;
      End;
    46..90: Begin
        n2.y := R1.top;
        n2.x := round(tangens(alpha - 45) * ((r1.right - p2.x) / 2)) + p2.x;
      End;
    91..135: Begin
        n2.y := R1.top;
        n2.x := round(tangens(alpha - 90) * ((r1.right - p2.x) / 2)) + p2.x;
      End;
    136..225: Begin
        n2.x := r1.left;
        n2.y := round(tangens(alpha) * ((r1.Bottom - p2.y) / 2)) + p2.y;
      End;
    226..270: Begin
        n2.y := r1.bottom;
        n2.x := round(tangens(alpha - 225) * ((r1.right - p2.x) / 2)) + p2.x;
      End;
    271..315: Begin
        n2.y := r1.bottom;
        n2.x := round(tangens(alpha - 270) * ((r1.right - p2.x) / 2)) + p2.x;
      End;
    316..360: Begin
        n2.x := R1.right;
        n2.y := round(tangens(alpha) * ((r1.Bottom - p2.y) / 2)) + p2.y;
      End;
  End;
  SN2 := Hypot(p2.x - n2.x, p2.y - n2.y);
  If (x <= (sn1 + Sn2)) Then result := true;
End;
So also wenn mich nich alles taeuscht ist das doch das was ich suche oder??? Wie man berechnet wie der Ball abprallt wenn er auf ein Rechteck trifft....so und ich steig da mal garnicht durch!!!

Ich hab null Plan davon was du da gemacht hast ^^

Delphi-Quellcode:
  Alpha := arcTangens(p1.x - p2.x, p1.y - p2.y);
  X := Hypot(p1.x - p2.x, p1.y - p2.y);
  Radius1 := p1.x - E1.left;
  Radius2 := p1.y - E1.top; // Radius 1 Horizontal, Radius2 Vertikal
  N1.X := cosinus(alpha) * radius1 + P1.X;
  N1.Y := sinus(Alpha) * radius2 + P1.Y;
  SN1 := Hypot(p1.x - n1.x, p1.y - n1.y);
Speziell mit dem Teil habe ich Probleme also ich verstehs nun soweit, dass du zuerst die Steigung ziwschen den beiden Mittelpunkten ausrechnest, richtig?
Dann nimmst du von der Steigung den ArcTangenten...(ich versteh nur nich wozu )
Und dann wofür diese Sinus und Cosinus Funktionen mit den Radien sind versteh ich auch nich ganz ^^
  Mit Zitat antworten Zitat