Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Zitat von »"Toa"«
Ein Projekt fürs Studium? Ist das für das Softwarepraktikum? Der Kollisions-Algorithmus den du hier nutzt nennt sich übrigends Bounding Circle.. Was studierst du wenn man fragen darf?
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
// Berechnung der Kollision zweier Kreise struct Vector2D_Taube { float x_Taube; float y_Taube; }; struct Vector2D_Projektil { float x_Projektil; float y_Projektil; }; float RadiusA = 10; // Radius Taube float RadiusB = 3; // Radius Projektil float CenterA; float CenterB; BOOL APIENTRY CircleHitsCircle(const Vector2D_Taube& CenterA, // Mittelpunkt Kreis A const float RadiusA, // Radius Kreis A const Vector2D_Projektil& CenterB, // Mittelpunkt Kreis B const float RadiusB) // Radius von Kreis B { // Wenn die Entfernung der beiden Mittelpunkte kleiner oder gleich // der Summe der beiden Radien ist, liegt eine Kollision vor. return (CenterA - CenterB).LengthSq() <= (RadiusA + RadiusB) * (RadiusA + RadiusB); } |
Zitat
Ich kenn das & in C nur von fscanf.
Zitat von »"GR-PA"«
Zitat
Ich kenn das & in C nur von fscanf.
Daraus interpretiere ich, dass du in C programmierst (und nicht in C++). Wenn das so ist, dann hättest du das besser in deinem ersten Post mit angegeben. Wenn nicht, dann kannst du diesen Post einfach ignorieren.
In C gibt's keine Referenzen. In C gibt's auch keine benutzerdefinierte Operatoren und in C gibt's keine Elementfunktionen. Deshalb wird dieser Code in C niemals funktionieren.
C-/C++-Quelltext |
|
1 2 3 4 |
BOOL APIENTRY CircleHitsCircle(const Vector2D_Taube* const CenterA, // Mittelpunkt Kreis A const float RadiusA, // Radius Kreis A const Vector2D_Projektil* const CenterB, // Mittelpunkt Kreis B const float RadiusB) // Radius von Kreis B |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
struct Vector2D { float x; float y; }; BOOL APIENTRY CircleHitsCircle(const Vector2D* const CenterA, // Mittelpunkt Kreis A const float RadiusA, // Radius Kreis A const Vector2D* const CenterB, // Mittelpunkt Kreis B const float RadiusB) // Radius von Kreis B { return ((CenterA->x-CenterB->x)* (CenterA->x-CenterB->x)+(CenterA->y-CenterB->y)*(CenterA->y-CenterB->y)) <= ((RadiusA+RadiusB)*(RadiusA+RadiusB)); } |
Zitat von »"GR-PA"«
Und du darfst in deiner Funktion nicht die beiden Mittelpunkte voneinander subtrahieren. Der Code der Funktion muss dann ungefähr so aussehen:
C-/C++-Quelltext
1 2 3 4 5 6 7 8 9 10 11 12 struct Vector2D { float x; float y; }; BOOL APIENTRY CircleHitsCircle(const Vector2D* const CenterA, // Mittelpunkt Kreis A const float RadiusA, // Radius Kreis A const Vector2D* const CenterB, // Mittelpunkt Kreis B const float RadiusB) // Radius von Kreis B { return ((CenterA->x-CenterB->x)* (CenterA->x-CenterB->x)+(CenterA->y-CenterB->y)*(CenterA->y-CenterB->y)) <= ((RadiusA+RadiusB)*(RadiusA+RadiusB)); }
C-/C++-Quelltext |
|
1 2 3 4 |
BOOL APIENTRY CircleHitsCircle(Vector2D CenterA, // Mittelpunkt Kreis A float RadiusA, // Radius Kreis A Vector2D CenterB, // Mittelpunkt Kreis B float RadiusB) // Radius von Kreis B |
Werbeanzeige