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
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
bool TestCollision(int Rect1[4], int Rect2[4]) { bool CollisionX = TestCollisionX(Rect1,Rect2); bool CollisionY = TestCollisionY(Rect1,Rect2); if((CollisionX == true)&&(CollisionY == true)) return true; else return false; } bool TestCollisionX(int Rect1[4], int Rect2[4]) { for(int y1 = Rect1[1]; y1 >= Rect1[3]; y1++) { for(int x1 = Rect1[0]; x1 >= Rect1[2]; x1 += Rect1[2] - Rect1[0]) { for(int y2 = Rect2[1]; y2 >= Rect2[3]; y2++) { for(int x2 = Rect2[0]; x2 >= Rect2[2]; x2 += Rect2[2] - Rect2[0]) { if((x1 == x2)&&(y1 == y2)) { return true; } } } } } return false; } bool TestCollisionY(int Rect1[4], int Rect2[4]) { for(int y1 = Rect1[0]; y1 >= Rect1[2]; y1++) { for(int x1 = Rect1[1]; x1 >= Rect1[3]; x1 += Rect1[3] - Rect1[1]) { for(int y2 = Rect2[0]; y2 >= Rect2[2]; y2++) { for(int x2 = Rect2[1]; x2 >= Rect2[3]; x2 += Rect2[3] - Rect2[1]) { if((x1 == x2)&&(y1 == y2)) { return true; } } } } } return false; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
template <typename T> bool SubTest(const T& min1, const T& max1, const T& min2, const T& max2) { return (min1 <= min2 && max1 >= min2) || (min1 <= max2 && max1 >= max2); } //Jeweils die zwei extreme (Minimum und maximum) bool TestCollision(vector2D vMin1, vector2D vMax1, vector2D vMin2, vector2D vMax2) { return SubTest(vMin1.x, vMax1.x, vMin2.x, vMax2.x) && SubTest(vMin1.y, vMax1.y, vMin2.y, vMax2.y); } |
Quellcode |
|
1 |
for(int y1 = Rect1[1]; y1 >= Rect1[3]; y1++) |
Quellcode |
|
1 |
for(int y1 = Rect1[1]; y1 < Rect1[3]; y1++) |
Werbeanzeige