For debug use only. Must applied when other rendering process is done
(frame, cam:Camera, objects)
| 3485 | |
| 3486 | |
| 3487 | def add_obj_dir(frame, cam:Camera, objects): |
| 3488 | """ |
| 3489 | For debug use only. Must applied when other rendering process is done |
| 3490 | """ |
| 3491 | def add_line(M, N, color): |
| 3492 | if M[0] == N[0]: |
| 3493 | if 0 <= M[0] < cam.width: |
| 3494 | if M[1] > N[1]: |
| 3495 | M, N = N, M |
| 3496 | for y in range(max(0, M[1]), min(cam.height - 1, N[1])): |
| 3497 | frame[y][M[0]] = color |
| 3498 | elif abs(k:=(M[1] - N[1]) / (M[0] - N[0])) <= 1: |
| 3499 | b = M[1] - k * M[0] |
| 3500 | if M[0] > N[0]: |
| 3501 | M, N = N, M |
| 3502 | for x in range(max(0, M[0]), min(cam.width - 1, N[0])): |
| 3503 | # CodeUndone |
| 3504 | y = int(k * x + b) |
| 3505 | if 0 <= y < cam.height: |
| 3506 | frame[y][x] = color |
| 3507 | else: |
| 3508 | t = 1 / k |
| 3509 | b = M[0] - t * M[1] |
| 3510 | if M[1] > N[1]: |
| 3511 | M, N = N, M |
| 3512 | for y in range(max(0, M[1]), min(cam.height - 1, N[1])): |
| 3513 | x = int(t * y + b) |
| 3514 | if 0 <= x < cam.width: |
| 3515 | frame[y][x] = color |
| 3516 | |
| 3517 | # CodeUndone |
| 3518 | obj:Object |
| 3519 | for obj in objects: |
| 3520 | if obj.hidden: |
| 3521 | continue |
| 3522 | x_in_cam = obj.center[0] - cam.x |
| 3523 | y_in_cam = obj.center[1] - cam.y |
| 3524 | z_in_cam = obj.center[2] - cam.z |
| 3525 | x_in_cam, y_in_cam, z_in_cam = ( |
| 3526 | x_in_cam * cam.rotation[0][0] + y_in_cam * cam.rotation[0][1] + z_in_cam * cam.rotation[0][2], |
| 3527 | x_in_cam * cam.rotation[1][0] + y_in_cam * cam.rotation[1][1] + z_in_cam * cam.rotation[1][2], |
| 3528 | x_in_cam * cam.rotation[2][0] + y_in_cam * cam.rotation[2][1] + z_in_cam * cam.rotation[2][2], |
| 3529 | ) |
| 3530 | rotation = obj.rotation |
| 3531 | rotation = ( |
| 3532 | ( |
| 3533 | rotation[0][0] * cam.rotation[0][0] + rotation[0][1] * cam.rotation[0][1] + rotation[0][2] * cam.rotation[0][2], |
| 3534 | rotation[0][0] * cam.rotation[1][0] + rotation[0][1] * cam.rotation[1][1] + rotation[0][2] * cam.rotation[1][2], |
| 3535 | rotation[0][0] * cam.rotation[2][0] + rotation[0][1] * cam.rotation[2][1] + rotation[0][2] * cam.rotation[2][2], |
| 3536 | ), |
| 3537 | ( |
| 3538 | rotation[1][0] * cam.rotation[0][0] + rotation[1][1] * cam.rotation[0][1] + rotation[1][2] * cam.rotation[0][2], |
| 3539 | rotation[1][0] * cam.rotation[1][0] + rotation[1][1] * cam.rotation[1][1] + rotation[1][2] * cam.rotation[1][2], |
| 3540 | rotation[1][0] * cam.rotation[2][0] + rotation[1][1] * cam.rotation[2][1] + rotation[1][2] * cam.rotation[2][2], |
| 3541 | ), |
| 3542 | ( |
| 3543 | rotation[2][0] * cam.rotation[0][0] + rotation[2][1] * cam.rotation[0][1] + rotation[2][2] * cam.rotation[0][2], |
| 3544 | rotation[2][0] * cam.rotation[1][0] + rotation[2][1] * cam.rotation[1][1] + rotation[2][2] * cam.rotation[1][2], |
nothing calls this directly
no test coverage detected