Skip to content

Commit

Permalink
Added: Simetral hit projection for node update in case both neighbors…
Browse files Browse the repository at this point in the history
… are not active rays
  • Loading branch information
dvdvideo1234 committed Aug 10, 2022
1 parent a8a6a77 commit 85abbaa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","8.686")
asmlib.SetOpVar("TOOL_VERSION","8.687")
asmlib.SetIndexes("V" ,1,2,3)
asmlib.SetIndexes("A" ,1,2,3)
asmlib.SetIndexes("WV",1,2,3)
Expand Down
50 changes: 34 additions & 16 deletions lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -781,33 +781,51 @@ function TOOL:SelectModel(sModel)
asmlib.LogInstance("Success <"..sModel..">",gtLogs); return true
end

function TOOL:GetCurveNodeActive(iD, vPnt, bM)
--[[
* Uses heuristics to provide the best suitable location the
* curve note closest location can be updated with. Three cases:
* 1. Both neighbours are active points. Intersect their active rays
* 2. Only one node is an active point. Project on its active ray
* 3. None of the neighbours are active points. Project on simetral
* iD > Curve node index to be updated
* vPnt > The new location to update the node with
* bMute > Mute mode. Used to disable server status messages
* Returns multiple values:
* 1. Curve node calculated heuristics location vector
* 2. The amount of neighbour nodes that are active rays
]]--
function TOOL:GetCurveNodeActive(iD, vPnt, bMute)
local ply = self:GetOwner()
local tC = asmlib.GetCacheCurve(ply)
if(iD <= 1) then -- Cannot chose first ID to intersect
if(not bM) then asmlib.Notify(ply,"Node point uses prev !","ERROR") end
if(not bMute) then asmlib.Notify(ply,"Node point uses prev !","ERROR") end
return nil -- The chosen node ID does not meet requirements
end
if(iD >= tC.Size) then -- Cannot chose last ID to intersect
if(not bM) then asmlib.Notify(ply,"Node point uses next !","ERROR") end
if(not bMute) then asmlib.Notify(ply,"Node point uses next !","ERROR") end
return nil -- The chosen node ID does not meet requirements
end
local iS, iE = (iD - 1), (iD + 1) -- Previous and next node indeces
local tS, tE = tC.Rays[iS], tC.Rays[iE] -- Previous and next node rays
if(tS[3] and tE[3]) then
local sD, eD = tS[2]:Forward(), tE[2]:Forward()
local f1, f2, x1, x2, xx = asmlib.IntersectRayPair(tS[1], sD, tE[1], eD)
return xx, true -- Both are active ponts and return ray intersection
return xx, 2 -- Both are active ponts and return ray intersection
else
if(tS[3]) then -- Previous is an active point
if(not bM) then asmlib.Notify(ply,"Node projection prev !","HINT") end
return asmlib.ProjectRay(tS[1], tS[2]:Forward(), vPnt), false
if(not bMute) then asmlib.Notify(ply,"Node projection prev !","HINT") end
return asmlib.ProjectRay(tS[1], tS[2]:Forward(), vPnt), 1
elseif(tE[3]) then -- Next is an active point
if(not bM) then asmlib.Notify(ply,"Node projection next !","HINT") end
return asmlib.ProjectRay(tE[1], tE[2]:Forward(), vPnt), false
if(not bMute) then asmlib.Notify(ply,"Node projection next !","HINT") end
return asmlib.ProjectRay(tE[1], tE[2]:Forward(), vPnt), 1
else -- None of the previous and next nodes are active points
if(not bM) then asmlib.Notify(ply,"Node intersect wrong ray !","ERROR") end
return nil -- The chosen node ID does not meet requirements
if(not bMute) then asmlib.Notify(ply,"Node project simetral !","HINT") end
local vS, vE = tC.Node[iS], tC.Node[iE] -- Read start and finish nodes
local vD = Vector(vE); vD:Sub(vS) -- Direction from start to finish
local vM = Vector(vD); vM:Mul(0.5); vM:Add(vS) -- Simetral origin
local vX = asmlib.ProjectRay(vS, vD, vPnt) -- Projection point
local vV = Vector(vPnt); vV:Sub(vX) -- Simetral direction vector
return asmlib.ProjectRay(vM, vV, vPnt), 0
end
end
end
Expand Down Expand Up @@ -1937,13 +1955,13 @@ function TOOL:DrawCurveNode(oScreen, oPly, stTrace)
if(bPnt and not tData.POA) then
local xx, sx = self:GetCurveNodeActive(mD, tData.Org, true)
if(xx) then
local xyX = xx:ToScreen()
if(sx) then
oScreen:DrawLine(xyX, xyO, "ry")
oScreen:DrawCircle(xyX, asmlib.GetViewRadius(oPly, xx), "b")
else
oScreen:DrawLine(xyX, xyO, "ry")
local xyX = xx:ToScreen(); oScreen:DrawLine(xyX, xyO, "ry")
if(sx == 0) then
oScreen:DrawCircle(xyX, asmlib.GetViewRadius(oPly, xx), "r")
elseif(sx == 1) then
oScreen:DrawCircle(xyX, asmlib.GetViewRadius(oPly, xx), "g")
elseif(sx == 2) then
oScreen:DrawCircle(xyX, asmlib.GetViewRadius(oPly, xx), "b")
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ set being solid with fading door `CLOSED` function state:
8. Pressing `ATTACK2` ( Def: `Right Mouse Button` ) + `SPEED` ( Def: `SHIFT` ) + `USE` ( Def: `E` )
* `CURVE` and `TURN`: Updates selected curve node in condition:
* When trace is a track piece, utilizes the trace entity active point as a curve node.
* Otherwise will utilize the intersection point from the previous and next nodes as the
curve node location. The middle normal vector is calculated using the previous and next
active points up vectors addition normalized.
* Otherwise will check various conditions and pick the most suitable curve node location vector:
1. When both neighbour (`start` **and** `final`) nodes are track active points will intersect their rays
2. When only one (`start` **or** `final`) node is an active point will project the hit node on its ray
3. When **none of the neighbors** are active points will project the hit node on their line simetral
9. Pressing `RELOAD` ( Def: `R` )
* When trace entity is a valid piece will just remove it.
* When `trackassembly_devmode` is enabled, will update the log control options.
Expand Down

0 comments on commit 85abbaa

Please sign in to comment.