bool GraphicsUtil::linesCross(b2Vec2 v0, b2Vec2 v1, b2Vec2 t0, b2Vec2 t1, b2Vec2 &intersectionPoint) { if ( areVecsEqual(v1,t0) || areVecsEqual(v0,t0) || areVecsEqual(v1,t1) || areVecsEqual(v0,t1) ) return false; b2Vec2 vnormal = v1 - v0; vnormal = b2Cross(1.0f, vnormal); float v0d = b2Dot(vnormal, v0); float t0d = b2Dot(vnormal, t0); float t1d = b2Dot(vnormal, t1); if ( t0d > v0d && t1d > v0d ) return false; if ( t0d < v0d && t1d < v0d ) return false; b2Vec2 tnormal = t1 - t0; tnormal = b2Cross(1.0f, tnormal); t0d = b2Dot(tnormal, t0); v0d = b2Dot(tnormal, v0); float v1d = b2Dot(tnormal, v1); if ( v0d > t0d && v1d > t0d ) return false; if ( v0d < t0d && v1d < t0d ) return false; intersectionPoint = v0 + ((t0d-v0d)/(v1d-v0d)) * (v1-v0); return true; }
时间: 2024-10-16 03:16:52