Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static bool, Vector2, Vector2 LineClipCircle (Vector2 v1, Vector2 v2, Vector2 c, double r) {
- let a = v1;
- let b = v2 - v1;
- let d = a - c;
- double quadA = b dot b;
- double quadB = b dot d;
- double quadC = d dot d - r * r;
- double discriminant = quadB * quadB - 4 * quadA * quadC;
- if (discriminant < 0) {
- return false, v1, v2;
- } else {
- double discSqrt = sqrt (discriminant);
- let lambda0 = (-quadB + discSqrt) / (2 * quadA);
- let lambda1 = (-quadB - discSqrt) / (2 * quadA);
- let interPoint0 = a + lambda0 * b;
- let interPoint1 = a + lambda1 * b;
- return true, interPoint0, interPoint1;
- }
- }
- [...]
- double angleCos = Cos (-pPawn.angle), angleSin = Sin (-pPawn.angle);
- Vector3 pPawnXYPos = (pPawn.prev + (TicFrac * (pPawn.pos - pPawn.prev)));
- Vector2 radarOffs = (radarPos.x - RADAR_RADIUS, radarPos.y + RADAR_RADIUS);
- let linesIterator = BlockLinesIterator.Create (CPlayer.mo, RADAR_MAXDIST);
- while (linesIterator.Next ()) {
- let curLine = linesIterator.CurLine;
- // Coords
- Vector2 worldPosV0 = (pPawnXYPos.xy - curLine.v1.p) / RADAR_SCALE, screenPosV0 = radarOffs;
- Vector2 worldPosV1 = (pPawnXYPos.xy - curLine.v2.p) / RADAR_SCALE, screenPosV1 = radarOffs;
- screenPosV0 += (worldPosV0.x * angleSin + worldPosV0.y * angleCos,
- worldPosV0.x * angleCos - worldPosV0.y * angleSin);
- screenPosV1 += (worldPosV1.x * angleSin + worldPosV1.y * angleCos,
- worldPosV1.x * angleCos - worldPosV1.y * angleSin);
- bool intersected;
- [intersected, screenPosV0, screenPosV1] = LineClipCircle (screenPosV0, screenPosV1, radarOffs, RADAR_RADIUS);
- if (!intersected)
- continue;
- if (screenPosV0 == screenPosV1) // Just in case
- continue;
- DrawLine (screenPosV0, screenPosV1, Color (256, 256, 256, 0), DI_SCREEN_RIGHT_TOP);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement