mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Add vector.ray_parallelogram_intersection
This commit is contained in:
parent
c87effd9a5
commit
bcda0511b1
13
vector.lua
13
vector.lua
@ -206,8 +206,7 @@ function box_box_collision(diff, box, other_box)
|
||||
return true
|
||||
end
|
||||
|
||||
--+ Möller-Trumbore
|
||||
function ray_triangle_intersection(origin, direction, triangle)
|
||||
local function moeller_trumbore(origin, direction, triangle, is_tri)
|
||||
local point_1, point_2, point_3 = unpack(triangle)
|
||||
local edge_1, edge_2 = subtract(point_2, point_1), subtract(point_3, point_1)
|
||||
local h = cross3(direction, edge_2)
|
||||
@ -223,7 +222,7 @@ function ray_triangle_intersection(origin, direction, triangle)
|
||||
end
|
||||
local q = cross3(diff, edge_1)
|
||||
local v = f * dot(direction, q)
|
||||
if v < 0 or u + v > 1 then
|
||||
if v < 0 or (is_tri and u or 0) + v > 1 then
|
||||
return
|
||||
end
|
||||
local pos_on_line = f * dot(edge_2, q)
|
||||
@ -232,6 +231,14 @@ function ray_triangle_intersection(origin, direction, triangle)
|
||||
end
|
||||
end
|
||||
|
||||
function ray_triangle_intersection(origin, direction, triangle)
|
||||
return moeller_trumbore(origin, direction, triangle, true)
|
||||
end
|
||||
|
||||
function ray_parallelogram_intersection(origin, direction, parallelogram)
|
||||
return moeller_trumbore(origin, direction, parallelogram)
|
||||
end
|
||||
|
||||
function triangle_normal(triangle)
|
||||
local point_1, point_2, point_3 = unpack(triangle)
|
||||
local edge_1, edge_2 = subtract(point_2, point_1), subtract(point_3, point_1)
|
||||
|
Loading…
Reference in New Issue
Block a user