Ствол: сегмент [turret_end_1, turret_end2]
в 3D, где turret_end_1
точка на башне, из которой выходит пуля.
Экран: фокус F
и плоскость экрана с именем screen_plane
.
# From 3D to 2D: projection from 3D space on the screen_plane:
Mouse = [mouse_x, mouse_y] # given on the screen_plane
B1 = project_on_screen_plane(turret_end_1)
B2 = project_on_screen_plane(turret_end_2)
# Calculations in 2D, i.e. on the screen_plane
U = B1-B2
U = ( dot_product(Mouse-B1, U) / dot_product(U, U) ) * U
U = B1 + U # this is the point you are looking for on the screen
# From 2D back to 3D: connect the focal point with the point U on the screen plane
# to form a line and find its intersection point in 3D with the line B1 B2
# aligned with the turret.
# line through F with directing vector Vector_from_F_to(U)
# line through B1 with directing vector B1-B2
V = intersect( F, Vector_from_F_to(U), B1, B1-B2 ) # the point you are looking for in 3D