Skip to content

Commit

Permalink
Fixed: User is now able to select a zero yaw snap which disables the …
Browse files Browse the repository at this point in the history
…feature completely

Fixed: /function TOOL:DrawRelationRay(oScreen, oPly, stSpawn)/ drawing at zero position/angle when no relation is set
Fixed: Relation ray is drawn at zero position/angle when the holder piece has only one active point
Added: Intersect relation flag /ray_inter_relayenb/ controlling the relation draw on zero position and orientation
Changed: Intersection missing relation ray now outputs general notification instead of error report
Changed: User is now able to snap a piece to the trace if no relation ray is found resulting in skipping intersection
Updated: Convar lower bounds of /GetActiveRadius/ to zero for user to evade the active points
Updated: /GetNormalAngle/ with Angle:SnapTo("yaw")
Updated: /GetNormalAngle/ now has the ability to apply both trace surface snap and yaw-snap simultaneously or separately or none
Removed: /function SnapValue(nvVal, nvSnap)/ due to using a library function
  • Loading branch information
dvdvideo1234 committed Sep 19, 2017
1 parent 2e91866 commit dcc2632
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local asmlib = trackasmlib

------ CONFIGURE ASMLIB ------
asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","5.378")
asmlib.SetOpVar("TOOL_VERSION","5.379")
asmlib.SetIndexes("V",1,2,3)
asmlib.SetIndexes("A",1,2,3)
asmlib.SetIndexes("S",4,5,6,7)
Expand Down
25 changes: 4 additions & 21 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1010,23 +1010,6 @@ function RoundValue(nvExact, nFrac)
return nFrac * (q + (f > 0.5 and 1 or 0))
end

function SnapValue(nvVal, nvSnap)
if(not nvVal) then return 0 end
local nVal = tonumber(nvVal)
if(not IsExistent(nVal)) then
return StatusLog(0,"SnapValue: Convert value NAN {"..type(nvVal).."}<"..tostring(nvVal)..">") end
if(not IsExistent(nvSnap)) then return nVal end
local nSnap = tonumber(nvSnap)
if(not IsExistent(nSnap)) then
return StatusLog(0,"SnapValue: Convert snap NAN {"..type(nvSnap).."}<"..tostring(nvSnap)..">") end
if(nSnap == 0) then return nVal end
local nvSnp, nvVal = mathAbs(nSnap), mathAbs(nVal)
local nRst, nRez = (nvVal % nvSnp), 0
if((nvSnp - nRst) < nRst) then nRez = nvVal + nvSnp - nRst else nRez = nvVal - nRst end
if(nVal < 0) then return -nRez; end
return nRez;
end

function GetCenterMC(oEnt)
-- Set the ENT's Angles first!
if(not (oEnt and oEnt:IsValid())) then
Expand Down Expand Up @@ -2953,10 +2936,10 @@ function GetNormalAngle(oPly, stTrace, bSnap, nYSnp)
end
local vUp, vRg = stTr.HitNormal, oPly:GetRight()
aAng:Set(vUp:Cross(vRg):AngleEx(vUp))
end -- Get only the player yaw, pitch and roll are not needed
if(nYSn and (nYSn >= 0) and (nYSn <= GetOpVar("MAX_ROTATION"))) then
aAng[caY] = SnapValue(oPly:GetAimVector():Angle()[caY],nYSn) end
return aAng
else aAng[caY] = oPly:GetAimVector():Angle()[caY] end
if(nYSn and (nYSn > 0) and (nYSn <= GetOpVar("MAX_ROTATION"))) then
aAng:SnapTo("yaw", nYSn) -- Snap player yaw, pitch and roll are not needed
end; return aAng
end

--[[
Expand Down
41 changes: 26 additions & 15 deletions lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function TOOL:GetPointID()
end

function TOOL:GetActiveRadius()
return mathClamp(self:GetClientNumber("activrad") or 1,1,asmlib.GetAsmVar("maxactrad", "FLT"))
return mathClamp(self:GetClientNumber("activrad") or 0,0,asmlib.GetAsmVar("maxactrad", "FLT"))
end

function TOOL:GetYawSnap()
Expand Down Expand Up @@ -304,6 +304,7 @@ function TOOL:IntersectClear(bEnb)
end; asmlib.IntersectRayClear(oPly, "ray_relate")
if(ntEnb and SERVER) then
asmlib.PrintNotifyPly(oPly,"Intersection relation clear !","CLEANUP") end
oPly:SetNW2Bool ("ray_inter_relayenb", false)
oPly:SetNW2Vector("ray_inter_relaypos", nil)
oPly:SetNW2Vector("ray_inter_relayang", nil)
return asmlib.StatusLog(true,"TOOL:IntersectClear("..tostring(ntEnb).."): Relation cleared")
Expand All @@ -315,6 +316,7 @@ function TOOL:IntersectRelate(oPly, oEnt, vHit, vNorm)
if(not stRay) then -- Create/update the ray in question
return asmlib.StatusLog(false,"TOOL:IntersectRelate(): Update fail") end
if(SERVER) then
oPly:SetNW2Bool ("ray_inter_relayenb", true)
oPly:SetNW2Vector("ray_inter_relaypos", stRay.Orw)
oPly:SetNW2Vector("ray_inter_relayang", stRay.Diw)
local femod = stringToFileName(oEnt:GetModel())
Expand Down Expand Up @@ -371,7 +373,7 @@ function TOOL:IntersectSnap(trEnt, vHit, stSpawn, bLoop)
local xx, x1, x2, stRay1, stRay2 = asmlib.IntersectRayHash(ply, "ray_origin", "ray_relate")
if(not xx) then
if(bLoop) then return nil
else asmlib.PrintNotifyPly(ply, "Define intersection relation !", "ERROR")
else asmlib.PrintNotifyPly(ply, "Define intersection relation !", "GENERIC")
return asmlib.StatusLog(nil, "TOOL:IntersectSnap(): Active ray mismatch")
end
end
Expand Down Expand Up @@ -659,8 +661,9 @@ function TOOL:LeftClick(stTrace)
return asmlib.StatusLog(true,"TOOL:LeftClick(Stack): Success")
else -- Switch the tool mode ( Snapping )
if(workmode == 2) then -- Make a ray intersection spawn update
if(not self:IntersectSnap(trEnt, stTrace.HitPos, stSpawn)) then
return asmlib.StatusLog(false, self:GetStatus(stTrace,"TOOL:LeftClick(Ray): Intersect snapping fail")) end
local stRay1, stRay2 = self:IntersectSnap(trEnt, stTrace.HitPos, stSpawn)
if(not (stRay1 and stRay2)) then
asmlib.LogInstance("TOOL:LeftClick(Ray): Skip intersection sequence. Snapping") end
end
local ePiece = asmlib.MakePiece(ply,model,stSpawn.SPos,stSpawn.SAng,mass,bgskids,conPalette:Select("w"),bnderrmod)
if(ePiece) then
Expand Down Expand Up @@ -801,9 +804,11 @@ function TOOL:UpdateGhost(ePiece, oPly)
if(stSpawn) then
if(workmode == 2) then
local stRay = asmlib.IntersectRayRead(oPly, "ray_relate")
oPly:SetNW2Vector("ray_inter_spawnpos", stSpawn.SPos)
oPly:SetNW2Vector("ray_inter_relaypos", stRay and stRay.Orw or nil)
oPly:SetNW2Vector("ray_inter_relayang", stRay and stRay.Diw or nil)
if(stRay) then
oPly:SetNW2Vector("ray_inter_spawnpos", stSpawn.SPos)
oPly:SetNW2Vector("ray_inter_relaypos", stRay.Orw)
oPly:SetNW2Vector("ray_inter_relayang", stRay.Diw)
end
end
ePiece:SetAngles(stSpawn.SAng); ePiece:SetPos(stSpawn.SPos); ePiece:SetNoDraw(false) end
end
Expand All @@ -819,9 +824,11 @@ function TOOL:UpdateGhost(ePiece, oPly)
if(stSpawn) then
if(workmode == 2) then
local stRay1, stRay2 = self:IntersectSnap(trEnt, stTrace.HitPos, stSpawn, true)
oPly:SetNW2Vector("ray_inter_spawnpos", stSpawn.SPos)
oPly:SetNW2Vector("ray_inter_relaypos", stRay2 and stRay2.Orw or nil)
oPly:SetNW2Vector("ray_inter_relayang", stRay2 and stRay2.Diw or nil)
if(stRay1 and stRay2) then
oPly:SetNW2Vector("ray_inter_spawnpos", stSpawn.SPos)
oPly:SetNW2Vector("ray_inter_relaypos", stRay2.Orw)
oPly:SetNW2Vector("ray_inter_relayang", stRay2.Diw)
end
end
ePiece:SetPos(stSpawn.SPos); ePiece:SetAngles(stSpawn.SAng); ePiece:SetNoDraw(false)
end
Expand Down Expand Up @@ -874,6 +881,7 @@ function TOOL:DrawTextSpawn(oScreen, stSpawn, sCol, sMeth, tArgs)
end

function TOOL:DrawRelationRay(oScreen, oPly, stSpawn)
local bEnb = oPly:GetNW2Bool ("ray_inter_relayenb")
local ePos = oPly:GetNW2Vector("ray_inter_relaypos")
local eAng = oPly:GetNW2Angle ("ray_inter_relayang")
local sPos, Ss = oPly:GetNW2Vector("ray_inter_spawnpos")
Expand All @@ -884,9 +892,12 @@ function TOOL:DrawRelationRay(oScreen, oPly, stSpawn)
local Re = (ePos + nLn * eAng:Forward()):ToScreen()
local nR = mathSqrt((Re.x - Rp.x)^2 + (Re.y - Rp.y)^2)
local Ru = (ePos + nLn * 0.5 * eAng:Up()):ToScreen()
oScreen:DrawLine(Rp, Re, "r")
oScreen:DrawLine(Rp, Ru, "b")
oScreen:DrawCircle(Rp, nR / 6, "y"); return Rp, Re, Ss
if(bEnb) then
oScreen:DrawLine(Rp, Re, "r")
oScreen:DrawLine(Rp, Ru, "b")
oScreen:DrawCircle(Rp, nR / 6, "y")
return Rp, Re, Ss
end; return nil
end; return nil
end

Expand Down Expand Up @@ -1319,11 +1330,11 @@ function TOOL.BuildCPanel(CPanel)
local nMaxOffLin = asmlib.GetAsmVar("maxlinear","FLT")
pItem = CPanel:NumSlider(languageGetPhrase ("tool."..gsToolNameL..".mass_con"), gsToolPrefL.."mass", 1, asmlib.GetAsmVar("maxmass" ,"FLT") , 0)
pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".mass"))
pItem = CPanel:NumSlider(languageGetPhrase ("tool."..gsToolNameL..".activrad_con"), gsToolPrefL.."activrad", 1, asmlib.GetAsmVar("maxactrad", "FLT"), 7)
pItem = CPanel:NumSlider(languageGetPhrase ("tool."..gsToolNameL..".activrad_con"), gsToolPrefL.."activrad", 0, asmlib.GetAsmVar("maxactrad", "FLT"), 7)
pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".activrad"))
pItem = CPanel:NumSlider(languageGetPhrase ("tool."..gsToolNameL..".count_con"), gsToolPrefL.."count" , 1, asmlib.GetAsmVar("maxstcnt" , "INT"), 0)
pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".count"))
pItem = CPanel:NumSlider(languageGetPhrase ("tool."..gsToolNameL..".ydegsnp_con"), gsToolPrefL.."ydegsnp", 1, gnMaxOffRot, 7)
pItem = CPanel:NumSlider(languageGetPhrase ("tool."..gsToolNameL..".ydegsnp_con"), gsToolPrefL.."ydegsnp", 0, gnMaxOffRot, 7)
pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".ydegsnp"))
pItem = CPanel:Button (languageGetPhrase ("tool."..gsToolNameL..".resetvars_con"), gsToolPrefL.."resetvars")
pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".resetvars"))
Expand Down

0 comments on commit dcc2632

Please sign in to comment.