Skip to content

Commit

Permalink
Fixed findOtherSideOfPoly
Browse files Browse the repository at this point in the history
Still need to solve for tris inside of a shape
  • Loading branch information
Stooberton committed May 17, 2024
1 parent 66cc895 commit 033b5f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
33 changes: 26 additions & 7 deletions lua/acf/core/utilities/traces_sh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ do -- ACF.trace
local h = rayNormal:Cross(edge2)
local a = edge1:Dot(h)

if a > -0.0001 and a < 0.0001 then return false end -- Ray is perpendicular to plane
if a > -0.001 and a < 0.001 then return false end -- Ray is perpendicular to plane

-- Ray passes through the triangle?
local f = 1 / a
local s = rayOrigin - p1 -- Displacement from to origin from p1
local u = f * s:Dot(h)
Expand All @@ -120,7 +119,7 @@ do -- ACF.trace
-- Length of ray to intersection
local t = f * edge2:Dot(q)

if t < 0.0001 then return false end -- Ray is too close
if t < 0.001 then return false end -- Ray is too close

return t
end
Expand All @@ -131,8 +130,10 @@ do -- ACF.trace
local incidentalPos = v0

Check warning on line 130 in lua/acf/core/utilities/traces_sh.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Unused variable"

Unused variable: incidentalPos
local incidentalLen = math.huge

for _, hull in pairs(ent:GetPhysicsObject():GetMeshConvexes()) do -- Loop over mesh
debugoverlay.Line(rayOrigin + Vector(0, 0, 1), rayOrigin + Vector(0, 0, 1) + rayNormal * 12, 0.05, Color(255, 160, 0), true)
debugoverlay.Line(rayOrigin + Vector(0, 0, 1), rayOrigin + Vector(0, 0, 1) + surfaceNormal * 12, 0.05, Color(160, 255, 0), true)

for _, hull in pairs(ent:GetPhysicsObject():GetMeshConvexes()) do -- Loop over mesh
for i = 1, #hull, 3 do -- Loop over each tri (groups of 3)
-- Points on tri
local p1 = ent:LocalToWorld(hull[i].pos)
Expand All @@ -143,11 +144,11 @@ do -- ACF.trace
local edge1 = p2 - p1
local edge2 = p3 - p1

nomTest = rayIntersectTri(rayOrigin, surfaceNormal, p1, edge1, edge2)
incTest = rayIntersectTri(rayOrigin, rayNormal, p1, edge1, edge2)
nomTest = rayIntersectTri(rayOrigin, surfaceNormal, p1, edge1, edge2)

if incTest and incTest < incidentalLen then incidentalLen = incTest end
if nomTest and nomTest < nominalLen then nominalLen = nomTest end
if incTest and incTest < incTest then incidentalLen = incTest end
end
end

Expand All @@ -169,7 +170,6 @@ do -- ACF.trace
surfaceNormal = -surfaceNormal

local ip, il, np, nl = findOtherSideOfPoly(entity, rayPos, rayNormal, surfaceNormal)

Check warning on line 172 in lua/acf/core/utilities/traces_sh.lua

View workflow job for this annotation

GitHub Actions / Lint / lint

"Unused variable"

Unused variable: il

local exit = ACF.trace({start = rayPos, endpos = ip, filter = {entity}}).HitPos -- Not strictly an exit... may have run into an intersecting entity inside

output.nominal = nl * 25.4
Expand All @@ -181,3 +181,22 @@ do -- ACF.trace
return output
end
end

if SERVER then
function test()
timer.Create("peee", 0.02, 0, function()
local trace = eye()

if trace.HitNonWorld then
local depth = ACF.getThickness(trace.Entity, trace.HitPos, (trace.HitPos - trace.StartPos):GetNormalized(), trace.HitNormal)

debugoverlay.Line(trace.HitPos, depth.incidentalPos, 0.05, Color(200, 50, 50), true)
debugoverlay.Line(trace.HitPos, depth.normalPos, 0.05, Color(50, 200, 50), true)

debugoverlay.Cross(trace.HitPos, 6, 0.05, Color(255, 255, 255), true)
debugoverlay.Cross(depth.incidentalPos, 3, 0.05, Color(255, 0, 0 ), true)
debugoverlay.Cross(depth.normalPos, 3, 0.05, Color(0, 255, 0), true)
end
end)
end
end
10 changes: 0 additions & 10 deletions lua/weapons/gmod_tool/stools/acfarmorprop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,6 @@ else -- Serverside-only stuff
local Weapon = self.Weapon

if ACF.Check(Ent) then
PrintTable(trace)
local depth = ACF.getThickness(Ent, trace.HitPos, (trace.HitPos - trace.StartPos):GetNormalized(), trace.HitNormal)

debugoverlay.Line(trace.HitPos, depth.incidentalPos, 0.3, Color(255, 50, 50), true)
debugoverlay.Line(trace.HitPos, depth.normalPos, 0.3, Color(50, 255, 50), true)

debugoverlay.Cross(trace.HitPos, 6, 0.3, Color(255, 255, 255), true)
debugoverlay.Cross(depth.incidentalPos, 3, 0.3, Color(255, 0, 0 ), true)
debugoverlay.Cross(depth.normalPos, 3, 0.3, Color(0, 255, 0), true)

Player:ConCommand("acfarmorprop_area " .. Ent.ACF.Area)
Player:ConCommand("acfarmorprop_thickness " .. self:GetClientNumber("thickness")) -- Force sliders to update themselves

Expand Down

0 comments on commit 033b5f8

Please sign in to comment.