diff --git a/lua/autorun/trackassembly_init.lua b/lua/autorun/trackassembly_init.lua index 1e4d5b2b..bd129584 100644 --- a/lua/autorun/trackassembly_init.lua +++ b/lua/autorun/trackassembly_init.lua @@ -35,7 +35,7 @@ local asmlib = trackasmlib ------ CONFIGURE ASMLIB ------ asmlib.InitBase("track","assembly") -asmlib.SetOpVar("TOOL_VERSION","5.438") +asmlib.SetOpVar("TOOL_VERSION","5.439") asmlib.SetIndexes("V",1,2,3) asmlib.SetIndexes("A",1,2,3) asmlib.SetIndexes("S",4,5,6,7) @@ -260,7 +260,7 @@ if(CLIENT) then asmlib.ConCommandPly(oPly, "anchor" , anchor) asmlib.ConCommandPly(oPly, "igntype" , "0") asmlib.ConCommandPly(oPly, "spnflat" , "0") - asmlib.ConCommandPly(oPly, "ydegsnp" , "45") + asmlib.ConCommandPly(oPly, "angsnap" , "45") asmlib.ConCommandPly(oPly, "pointid" , "1") asmlib.ConCommandPly(oPly, "pnextid" , "2") asmlib.ConCommandPly(oPly, "spawncn" , "0") @@ -2897,8 +2897,8 @@ if(CLIENT) then -- con >> control, def >> deafault, hd >> header, lb >> label asmlib.SetLocalify("en","tool."..gsToolNameL..".activrad_con" , "Active radius:") asmlib.SetLocalify("en","tool."..gsToolNameL..".count" , "Maximum number of pieces to create while stacking") asmlib.SetLocalify("en","tool."..gsToolNameL..".count_con" , "Pieces count:") - asmlib.SetLocalify("en","tool."..gsToolNameL..".ydegsnp" , "Snap the first piece spawned at this much degrees") - asmlib.SetLocalify("en","tool."..gsToolNameL..".ydegsnp_con" , "Yaw snap amount:") + asmlib.SetLocalify("en","tool."..gsToolNameL..".angsnap" , "Snap the first piece spawned at this much degrees") + asmlib.SetLocalify("en","tool."..gsToolNameL..".angsnap_con" , "Angular alignment:") asmlib.SetLocalify("en","tool."..gsToolNameL..".resetvars" , "Click to reset the additional values") asmlib.SetLocalify("en","tool."..gsToolNameL..".resetvars_con" , "V Reset variables V") asmlib.SetLocalify("en","tool."..gsToolNameL..".nextpic" , "Additional origin angular pitch offset") @@ -2992,8 +2992,8 @@ if(CLIENT) then -- con >> control, def >> deafault, hd >> header, lb >> label asmlib.SetLocalify("bg","tool."..gsToolNameL..".activrad_con" , "Активен радиус:") asmlib.SetLocalify("bg","tool."..gsToolNameL..".count" , "Максимален брой парчета които може да се създадат при натрупване") asmlib.SetLocalify("bg","tool."..gsToolNameL..".count_con" , "Брой парчета:") - asmlib.SetLocalify("bg","tool."..gsToolNameL..".ydegsnp" , "Залепете първото създадено парче на толкова градуса") - asmlib.SetLocalify("bg","tool."..gsToolNameL..".ydegsnp_con" , "Залепване по азимут:") + asmlib.SetLocalify("bg","tool."..gsToolNameL..".angsnap" , "Залепете първото създадено парче на толкова градуса") + asmlib.SetLocalify("bg","tool."..gsToolNameL..".angsnap_con" , "Ъглово подравняване:") asmlib.SetLocalify("bg","tool."..gsToolNameL..".resetvars" , "Цъкнете за да нулирате допълнителните стойности") asmlib.SetLocalify("bg","tool."..gsToolNameL..".resetvars_con" , "V Нулиране на променливите V") asmlib.SetLocalify("bg","tool."..gsToolNameL..".nextpic" , "Допълнително отместване на началото по тангаж") @@ -3087,8 +3087,8 @@ if(CLIENT) then -- con >> control, def >> deafault, hd >> header, lb >> label asmlib.SetLocalify("fr","tool."..gsToolNameL..".activrad_con" , "Rayon actif:") asmlib.SetLocalify("fr","tool."..gsToolNameL..".count" , "Nombre maximum de pièces à créer pendant l'empilement") asmlib.SetLocalify("fr","tool."..gsToolNameL..".count_con" , "Nombre de pièces:") - asmlib.SetLocalify("fr","tool."..gsToolNameL..".ydegsnp" , "Aligner la première pièce créée sur ce degré") - asmlib.SetLocalify("fr","tool."..gsToolNameL..".ydegsnp_con" , "Alignement du lacet:") + asmlib.SetLocalify("fr","tool."..gsToolNameL..".angsnap" , "Aligner la première pièce créée sur ce degré") + asmlib.SetLocalify("fr","tool."..gsToolNameL..".angsnap_con" , "Alignement angulaire:") asmlib.SetLocalify("fr","tool."..gsToolNameL..".resetvars" , "Cliquez pour réinitialiser les valeurs supplémentaires") asmlib.SetLocalify("fr","tool."..gsToolNameL..".resetvars_con" , "V Réinitialiser les variables V") asmlib.SetLocalify("fr","tool."..gsToolNameL..".nextpic" , "Décalage angulaire supplémentaire sur la position initial du tangage") @@ -3182,8 +3182,8 @@ if(CLIENT) then -- con >> control, def >> deafault, hd >> header, lb >> label asmlib.SetLocalify("ru","tool."..gsToolNameL..".activrad_con" , "Активный радиус:") asmlib.SetLocalify("ru","tool."..gsToolNameL..".count" , "Максимальное количество куски для нагромождения") asmlib.SetLocalify("ru","tool."..gsToolNameL..".count_con" , "Количество кусков:") - asmlib.SetLocalify("ru","tool."..gsToolNameL..".ydegsnp" , "Приклейте первый кусок созданный тем положением градусов") - asmlib.SetLocalify("ru","tool."..gsToolNameL..".ydegsnp_con" , "Приклеивание азимутом:") + asmlib.SetLocalify("ru","tool."..gsToolNameL..".angsnap" , "Приклейте первый кусок созданный тем положением градусов") + asmlib.SetLocalify("ru","tool."..gsToolNameL..".angsnap_con" , "Угловое выравнивание:") asmlib.SetLocalify("ru","tool."..gsToolNameL..".resetvars" , "Нажмите чтобы сбросить дополнительные значения") asmlib.SetLocalify("ru","tool."..gsToolNameL..".resetvars_con" , "V Сбросить переменные V") asmlib.SetLocalify("ru","tool."..gsToolNameL..".nextpic" , "Дополнительный сдвиг начала тангажом") diff --git a/lua/trackassembly/trackasmlib.lua b/lua/trackassembly/trackasmlib.lua index 1b497154..514f5959 100644 --- a/lua/trackassembly/trackasmlib.lua +++ b/lua/trackassembly/trackasmlib.lua @@ -3044,6 +3044,13 @@ function ProcessDSV(sDelim) end ----------------------------- SNAPPING ------------------------------ + +local function GetSurfaceAngle(oPly, vNorm) + local vF = oPly:GetAimVector() + local vR = vF:Cross(vNorm); vF:Set(vNorm:Cross(vR)) + return vF:AngleEx(vNorm) +end + --[[ * This function calculates the cross product normal angle of * a player by a given trace. If the trace is missing it takes player trace @@ -3054,20 +3061,17 @@ end * nYSnp > Yaw snap amount ]]-- function GetNormalAngle(oPly, stTrace, bSnap, nYSnp) - local aAng = Angle() - if(not IsPlayer(oPly)) then return aAng end - local nYSn = (tonumber(nYSnp) or 0) + local aAng, nYSn = Angle(), (tonumber(nYSnp) or 0); if(not IsPlayer(oPly)) then + return StatusLog(aAng,"GetNormalAngle: No player <"..tostring(oPly)..">", aAng) end if(bSnap) then -- Snap to the surface - local stTr = stTrace - if(not (stTr and stTr.Hit)) then + local stTr = stTrace; if(not (stTr and stTr.Hit)) then stTr = GetTracePly(oPly) if(not (stTr and stTr.Hit)) then return aAng end - end - local vUp, vRg = stTr.HitNormal, oPly:GetRight() - aAng:Set(vUp:Cross(vRg):AngleEx(vUp)) + end; aAng:Set(GetSurfaceAngle(oPly, stTr.HitNormal)) 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 + -- Snap player yaw, pitch and roll are not needed + aAng:SnapTo("pitch", nYSn):SnapTo("yaw", nYSn):SnapTo("roll", nYSn) end; return aAng end diff --git a/lua/weapons/gmod_tool/stools/trackassembly.lua b/lua/weapons/gmod_tool/stools/trackassembly.lua index 2cf19de5..b9bd6772 100644 --- a/lua/weapons/gmod_tool/stools/trackassembly.lua +++ b/lua/weapons/gmod_tool/stools/trackassembly.lua @@ -90,7 +90,7 @@ TOOL.ClientConVar = { [ "anchor" ] = gsNoAnchor, [ "igntype" ] = "0", [ "spnflat" ] = "0", - [ "ydegsnp" ] = "45", + [ "angsnap" ] = "45", [ "pointid" ] = "1", [ "pnextid" ] = "2", [ "nextpic" ] = "0", @@ -245,8 +245,8 @@ function TOOL:GetActiveRadius() return mathClamp(self:GetClientNumber("activrad") or 0,0,asmlib.GetAsmVar("maxactrad", "FLT")) end -function TOOL:GetYawSnap() - return mathClamp(self:GetClientNumber("ydegsnp"),0,gnMaxOffRot) +function TOOL:GetAngSnap() + return mathClamp(self:GetClientNumber("angsnap"),0,gnMaxOffRot) end function TOOL:GetForceLimit() @@ -459,7 +459,7 @@ function TOOL:GetStatus(stTrace,anyMessage,hdEnt) sDu = sDu..sSpace.." HD.Mass: <"..tostring(self:GetMass())..">"..sDelim sDu = sDu..sSpace.." HD.StackCNT: <"..tostring(self:GetCount())..">"..sDelim sDu = sDu..sSpace.." HD.Freeze: <"..tostring(self:GetFreeze())..">"..sDelim - sDu = sDu..sSpace.." HD.YawSnap: <"..tostring(self:GetYawSnap())..">"..sDelim + sDu = sDu..sSpace.." HD.YawSnap: <"..tostring(self:GetAngSnap())..">"..sDelim sDu = sDu..sSpace.." HD.Gravity: <"..tostring(self:GetGravity())..">"..sDelim sDu = sDu..sSpace.." HD.Adviser: <"..tostring(self:GetAdviser())..">"..sDelim sDu = sDu..sSpace.." HD.ForceLimit: <"..tostring(self:GetForceLimit())..">"..sDelim @@ -491,6 +491,7 @@ function TOOL:GetStatus(stTrace,anyMessage,hdEnt) sDu = sDu..sSpace.." HD.MaxStackCnt: <"..tostring(asmlib.GetAsmVar("maxstcnt" ,"INT"))..">"..sDelim sDu = sDu..sSpace.." HD.BoundErrMod: <"..tostring(asmlib.GetAsmVar("bnderrmod","STR"))..">"..sDelim sDu = sDu..sSpace.." HD.MaxFrequent: <"..tostring(asmlib.GetAsmVar("maxfruse" ,"INT"))..">"..sDelim + sDu = sDu..sSpace.." HD.MaxTrMargin: <"..tostring(asmlib.GetAsmVar("maxtrmarg","FLT"))..">"..sDelim sDu = sDu..sSpace.." HD.Anchor: {"..tostring(anEnt or gsNoAV).."}<"..tostring(aninfo)..">"..sDelim sDu = sDu..sSpace.." HD.PointID: ["..tostring(pointid).."] >> ["..tostring(pnextid).."]"..sDelim sDu = sDu..sSpace.." HD.AngOffsets: ["..tostring(nextx)..","..tostring(nexty)..","..tostring(nextz).."]"..sDelim @@ -527,7 +528,7 @@ function TOOL:LeftClick(stTrace) local count = self:GetCount() local ply = self:GetOwner() local freeze = self:GetFreeze() - local ydegsnp = self:GetYawSnap() + local angsnap = self:GetAngSnap() local gravity = self:GetGravity() local elevpnt = self:GetElevation() local nocollide = self:GetNoCollide() @@ -552,7 +553,7 @@ function TOOL:LeftClick(stTrace) local nextpic, nextyaw, nextrol = self:GetAngOffsets() if(stTrace.HitWorld) then -- Switch the tool mode ( Spawn ) local vPos = Vector(); vPos:Set(stTrace.HitPos) - local aAng = asmlib.GetNormalAngle(ply,stTrace,surfsnap,ydegsnp) + local aAng = asmlib.GetNormalAngle(ply,stTrace,surfsnap,angsnap) if(spawncn) then -- Spawn on mass centre aAng:RotateAroundAxis(aAng:Up() ,-nextyaw) aAng:RotateAroundAxis(aAng:Right() , nextpic) @@ -786,9 +787,9 @@ function TOOL:UpdateGhost(ePiece, oPly) local nextx, nexty, nextz = self:GetPosOffsets() local nextpic, nextyaw, nextrol = self:GetAngOffsets() if(stTrace.HitWorld) then - local ydegsnp = self:GetYawSnap() + local angsnap = self:GetAngSnap() local surfsnap = self:GetSurfaceSnap() - local aAng = asmlib.GetNormalAngle(oPly,stTrace,surfsnap,ydegsnp) + local aAng = asmlib.GetNormalAngle(oPly,stTrace,surfsnap,angsnap) if(self:GetSpawnCenter()) then aAng:RotateAroundAxis(aAng:Up() ,-nextyaw) aAng:RotateAroundAxis(aAng:Right() , nextpic) @@ -1049,11 +1050,11 @@ function TOOL:DrawHUD() if(not self:GetDeveloperMode()) then return end self:DrawTextSpawn(hudMonitor, "k","SURF",{"Trebuchet18"}) elseif(stTrace.HitWorld) then local nRad = nrad - local ydegsnp = self:GetYawSnap() + local angsnap = self:GetAngSnap() local elevpnt = self:GetElevation() local surfsnap = self:GetSurfaceSnap() local workmode = self:GetWorkingMode() - local aAng = asmlib.GetNormalAngle(oPly,stTrace,surfsnap,ydegsnp) + local aAng = asmlib.GetNormalAngle(oPly,stTrace,surfsnap,angsnap) if(self:GetSpawnCenter()) then -- Relative to MC aAng:RotateAroundAxis(aAng:Up() ,-nextyaw) aAng:RotateAroundAxis(aAng:Right() , nextpic) @@ -1333,8 +1334,8 @@ function TOOL.BuildCPanel(CPanel) 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", 0, gnMaxOffRot, 7) - pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".ydegsnp")) + pItem = CPanel:NumSlider(languageGetPhrase ("tool."..gsToolNameL..".angsnap_con"), gsToolPrefL.."angsnap", 0, gnMaxOffRot, 7) + pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".angsnap")) pItem = CPanel:Button (languageGetPhrase ("tool."..gsToolNameL..".resetvars_con"), gsToolPrefL.."resetvars") pItem:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".resetvars")) pItem = CPanel:NumSlider(languageGetPhrase ("tool."..gsToolNameL..".nextpic_con"), gsToolPrefL.."nextpic" , -gnMaxOffRot, gnMaxOffRot, 7) diff --git a/readme.md b/readme.md index c23cd771..91ae5a24 100644 --- a/readme.md +++ b/readme.md @@ -66,7 +66,7 @@ about their track packs or in some other way. It is possible that missed someone * Snapping/spawning with [custom user offsets](https://www.youtube.com/watch?v=e1IK2zJ_Djk) * Snapping/spawning with zero pitch. Good for track leveling * Snapping/spawning at the mass-center or the active point ( if checked ) - * Snapping the first piece yaw to user defined angle + * Snapping the first piece angle to user defined value * Snapping already spawned pieces by [using only the physgun](https://www.youtube.com/watch?v=BxMlZMMGHrs) * Fast changing the active track ends ( Alt + mouse scroll ). Good switching turns direction * Custom user defined active radius based snapping @@ -156,7 +156,7 @@ Will stack as many pieces as shown by the slider `Pieces count`. 5. Piece mass slider is used to set the mass of the next track piece to be spawned. 6. Active radius is used to set the minimum distance needed to select an active point when pointing at a piece. 7. Pieces count shows the maximum number of pieces to be stacked. -8. The `Yaw snap amount` slider is used to snap the first piece ( Requested by [Magnum](http://steamcommunity.com/profiles/76561198004847743) ) +8. The `Angular alignment` slider is used to snap the first piece ( Requested by [Magnum](http://steamcommunity.com/profiles/76561198004847743) ) to a user-defined angle ( Usually 45 ) so that the track building process becomes easier. The whole track build will be snapped also because you are building it relative to the first piece. 9. The force limit slider ( Requested by The Arbitor 90 ) defines the maximum force to be applied