bool LineToRectangle(const VEC2& start, const VEC2& end, const VEC2& rect_pos, const VEC2& rect_pos2, float* _t) { assert(rect_pos.x<=rect_pos2.x && rect_pos.y<=rect_pos2.y); const VEC2 topRight(rect_pos2.x, rect_pos.y), bottomLeft(rect_pos.x, rect_pos2.y); if(_t) { float tt, t = 1.001f; if(LineToLine(start, end, rect_pos, topRight, &tt) && tt < t) t = tt; if(LineToLine(start, end, topRight, rect_pos2, &tt) && tt < t) t = tt; if(LineToLine(start, end, rect_pos2, bottomLeft, &tt) && tt < t) t = tt; if(LineToLine(start, end, bottomLeft, rect_pos, &tt) && tt < t) t = tt; *_t = t; return (t <= 1.f); } else { if(LineToLine(rect_pos, topRight, start, end)) return true; if(LineToLine(topRight, rect_pos2, start, end)) return true; if(LineToLine(rect_pos2, bottomLeft, start, end)) return true; if(LineToLine(bottomLeft, rect_pos, start, end)) return true; return false; } }
bool Physics::BoxToBox(Box& A, Box& B) { int A_count = A.count; int B_count = B.count; Line* A_S = A.S; Line* B_S = B.S; for (int i = 0; i < A_count; i++) for (int n = 0; n < B_count; n++) if (LineToLine(A_S[i], B_S[n])) return true; return false; }