| 2450 | |
| 2451 | |
| 2452 | def shadow(A, B, C): |
| 2453 | # Sorting by y, from lowest to highest in value but from top to bottom in what u see |
| 2454 | if A[9] > B[9]: |
| 2455 | A, B = B, A |
| 2456 | if B[9] > C[9]: |
| 2457 | B, C = C, B |
| 2458 | if A[9] > B[9]: |
| 2459 | A, B = B, A |
| 2460 | # Remove some of those out of screen |
| 2461 | if (A[9] >= cam.height or |
| 2462 | C[9] < 0 or |
| 2463 | A[9] == C[9] or |
| 2464 | A[8] < 0 and B[8] < 0 and C[8] < 0 or |
| 2465 | A[8] >= cam.width and B[8] >= cam.width and C[8] >= cam.width): |
| 2466 | return |
| 2467 | |
| 2468 | # Perspective correction |
| 2469 | A[2] = 1 / A[2] |
| 2470 | B[2] = 1 / B[2] |
| 2471 | C[2] = 1 / C[2] |
| 2472 | |
| 2473 | if A[9] == B[9]: |
| 2474 | if A[8] > B[8]: |
| 2475 | A, B = B, A |
| 2476 | if A[9] >= 0: |
| 2477 | if A[8] <= 0: |
| 2478 | x_start = 0 |
| 2479 | else: |
| 2480 | x_start = A[8] |
| 2481 | if B[8] >= cam.width - 1: |
| 2482 | x_end = cam.width - 1 |
| 2483 | else: |
| 2484 | x_end = B[8] |
| 2485 | |
| 2486 | for x in range(x_start, x_end): |
| 2487 | p1 = (x - A[8]) / (B[8] - A[8]) |
| 2488 | p2 = 1 - p1 |
| 2489 | z3d = 1 / (p2 * A[2] + p1 * B[2]) |
| 2490 | if z3d < depth_buffer[A[9]][x]: |
| 2491 | depth_buffer[A[9]][x] = z3d |
| 2492 | # if cam.light.type != 2: |
| 2493 | # depth_buffer[A[9]][x] = z3d |
| 2494 | # elif (x - cam.light.shadow_properties[4]) * (x - cam.light.shadow_properties[4]) + A[9] * A[9] < cam.light.shadow_properties[5]: |
| 2495 | # depth_buffer[A[9]][x] = z3d |
| 2496 | |
| 2497 | tAC = (A[8] - C[8]) / (A[9] - C[9]) |
| 2498 | bAC = A[8] - A[9] * tAC |
| 2499 | tBC = (B[8] - C[8]) / (B[9] - C[9]) |
| 2500 | bBC = B[8] - B[9] * tBC |
| 2501 | |
| 2502 | if B[9] <= 0: |
| 2503 | y_start = 0 |
| 2504 | else: |
| 2505 | y_start = B[9] |
| 2506 | if C[9] >= cam.height - 1: |
| 2507 | y_end = cam.height - 1 |
| 2508 | else: |
| 2509 | y_end = C[9] |