Autor Beitrag
luckyluc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103



BeitragVerfasst: Fr 12.11.10 15:12 
hallo!
Ich möchte eine Kugel an einem Panel abprallen lassen. Hier meine Überlegung, die aber nicht funktioniert. (a, b, (a+10), (b+10) sind die variablen für die ellipse die aufgespannt wurde also für den ball.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
 
 if b> (Panel1.Top+Panel1.Height) then d:=-1;
 if a > (Panel1.Left+Panel1.Width)  then c:=-1;
 if (b+10) < Panel1.Top  then d:= -1;
 if (a+10) < Panel1.Left  then c:=-1;

Könnt ihr mir helfen?
Thx
Einloggen, um Attachments anzusehen!
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Fr 12.11.10 15:40 
Warum nimmst du für die Kugel keinen zentrierten Punkt vom Typ TPoint und einen Radius, so kannst du gute Vergleiche für alle Eventualitäten aufstellen.

_________________
Es gibt 10 Gruppen von Menschen: diejenigen, die das Binärsystem verstehen, und die anderen.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 13.11.10 10:42 
Was bei dir c und d ist, weiss ich nicht.

1. Ich würde zuerst mal berechnen, ob die Kugel innerhalb des Panels ist.
2. Dann würde ich schauen, ob der Ball eine Ecke berührt, falls ja, dann Einfallswinkel=Ausfallswinkel zu einer imaginären Kante im 90°-Winkel zur Verbindungsgerade zwischen Mittelpunkt des Balles und der Ecke (ist halt ein wenig Vektorrechnung*).
3. Falls nicht, dann bestimmten, welche Kante berührt wird und dann wieder Einfallswinkel=Ausfallswinkel (d.h. eine Geschwindigkeitskomponente negieren).

*Zwei Vektoren v und w aneinander Spiegeln kann man so: Spiegeln(w an v) = 2*(v*w)/(v*v)*v-w. Im Fall der Ecke spiegelst du den Geschwindigkeitvektor an den Vektor von der Ecke zum Mittelpunkt des Balles.
Fiete
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 617
Erhaltene Danke: 364

W7
Delphi 6 pro
BeitragVerfasst: So 14.11.10 12:58 
Moin luckyluc,
suche mal nach Ballbewegung in OOP
Gruß
Fiete

_________________
Fietes Gesetz: use your brain (THINK)
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 15.11.10 23:10 
Zum Spass...
Einloggen, um Attachments anzusehen!