Created
January 7, 2022 20:15
-
-
Save treellama/d9aab6d88627b1a562912ed7878e4c55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ray_to_line_segment(x0, y0, z0, pitch, yaw) | |
local max = 32767 / 1024 | |
local min = -32 | |
local dx = math.cos(pitch) * math.cos(yaw) | |
local dy = math.cos(pitch) * math.sin(yaw) | |
local dz = math.sin(pitch) | |
local x1 = x0 + reach * dx | |
local y1 = y0 + reach * dy | |
local z1 = z0 + reach * dz | |
if x1 <= min then | |
x1 = min | |
y1 = y0 + dy * (min - x0) / dx | |
z1 = z0 + dz * (min - x0) / dx | |
end | |
if x1 >= max then | |
x1 = max | |
y1 = y0 + dy * (max - x0) / dx | |
z1 = z0 + dz * (max - x0) / dx | |
end | |
if y1 <= min then | |
y1 = min | |
x1 = x0 + dx * (min - y0) / dy | |
z1 = z0 + dz * (min - y0) / dy | |
end | |
if y1 >= max then | |
y1 = max | |
x1 = x0 + dx * (max - y0) / dy | |
z1 = z0 + dz * (max - y0) / dy | |
end | |
if z1 <= min then | |
z1 = min | |
x1 = x0 + dx * (min - z0) / dz | |
y1 = y0 + dy * (min - z0) / dz | |
end | |
if z1 >= max then | |
z1 = max | |
x1 = x0 + dx * (min - z0) / dz | |
y1 = y0 + dy * (min - z0) / dz | |
end | |
return x1, y1, z1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment