#include "raylib.h" bool get_line_intersect(float p0_x, float p0_y, float p1_x, float p1_y, float p2_x ,float p2_y, float p3_x, float p3_y); bool polypolycollide(Vector2 poly1[],int as1, Vector2 poly2[], int as2); int debug=0; int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib example."); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); // // Create a Vector2 array and create some points in it // Vector2 pol1[3]; pol1[0] = (Vector2){200,100}; pol1[1] = (Vector2){20,300}; pol1[2] = (Vector2){280,300}; Vector2 pol2[3]; pol2[0] = (Vector2){50+GetMouseX()-50,50+GetMouseY()-50}; pol2[1] = (Vector2){20+GetMouseX()-50,150+GetMouseY()-50}; pol2[2] = (Vector2){90+GetMouseX()-50,150+GetMouseY()-50}; if(polypolycollide( pol1,sizeof(pol1)/sizeof(pol1[0]), pol2,sizeof(pol2)/sizeof(pol2[0]))==true){ DrawText(FormatText("Collision"),0,0,20,RED); } DrawText(FormatText("%i",debug),0,20,20,RED); DrawTriangle(pol1[0],pol1[1],pol1[2],RED); DrawTriangle(pol2[0],pol2[1],pol2[2],YELLOW); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } bool polypolycollide(Vector2 poly1[],int as1, Vector2 poly2[], int as2){ //'first check if the second polygon is inside the first polygon int x=-5000; int y=-5000; int cnt=0; for(int i=1;i 0 )return true; //'Now check if the first polygon is inside the second polygon x=-5000; y=-5000; cnt=0; for(int i=1;i 0)return true; //' //' Now check if any of the lines of the two polygons touch for(int i=1;i= 0 && s <= 1 && t >= 0 && t <= 1) return true; return false; // No collision }