Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@
if dot >= 1 then -- also account for rounding errors, somehow the dot product can be >1, which makes scaling nan
-- direction stays the same, no need for a corner, just skip this point, unless it is the last segment of a closed path (last segment of a open path is handled explicitly above)
if i == num+1 then
corners[#corners+1] = { r={x=x1-dir.y*size, y=y1+dir.x*size}, l={x=x1+dir.y*size, y=y1-dir.x*size} }

Check warning on line 354 in lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
end
elseif dot <= -1 then -- new direction is inverse, just add perpendicular nodes
corners[#corners+1] = { r={x=x1-dir.y*size, y=y1+dir.x*size}, l={x=x1+dir.y*size, y=y1-dir.x*size} }
else
local scaling = size*math.tan(math.acos(dot)/2)
if dir.x*-lastdir.y + dir.y*lastdir.x > 0 then -- right bend, checked by getting the dot product between dir and lastDir:rotate(90)
local offsetx = -lastdir.y*size-lastdir.x*scaling

Check warning on line 361 in lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
local offsety = lastdir.x*size-lastdir.y*scaling
if dot < 0 then -- sharp corner, add two points to the outer edge to not have insanely long spikes
corners[#corners+1] = { r={x=x1+offsetx, y=y1+offsety}, l={x=x1+(lastdir.x+lastdir.y)*size, y=y1+(lastdir.y-lastdir.x)*size} }
Expand All @@ -367,7 +367,7 @@
corners[#corners+1] = { r={x=x1+offsetx, y=y1+offsety}, l={x=x1-offsetx, y=y1-offsety} }
end
else -- left bend
local offsetx = lastdir.y*size-lastdir.x*scaling

Check warning on line 370 in lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
local offsety = -lastdir.x*size-lastdir.y*scaling
if dot < 0 then
corners[#corners+1] = { l={x=x1+offsetx, y=y1+offsety}, r={x=x1+(lastdir.x-lastdir.y)*size, y=y1+(lastdir.y+lastdir.x)*size} }
Expand Down Expand Up @@ -418,15 +418,48 @@
return {-1,-1}
end

local EmitterCursorOffset = Vector( -64, 0, 64 )
local DefaultEmitterOffset = Vector( 0, 0, 71 )
local DefaultEmitterAngle = Angle( 0, 0, 90 )
local DefaultEmitterScale = 0.25
local function GetEmitterCursorTransform( this )
local useRT = this.GetUseRT and this:GetUseRT()

local scale = this:GetDrawScale()
if not scale or scale == 0 then
scale = DefaultEmitterScale
end

local offset = this:GetDrawOffsetPos()
if not offset then
offset = DefaultEmitterOffset
end

local drawAngle = this:GetDrawOffsetAng()
if not drawAngle then
drawAngle = DefaultEmitterAngle
end

local pos
if useRT then
pos = this:LocalToWorld( offset )
else
pos = this:LocalToWorld( offset + EmitterCursorOffset )
end
local ang = this:LocalToWorldAngles( drawAngle )

return pos, ang, scale, useRT
end

function EGP:EGPCursor( this, ply )
if not EGP:ValidEGP(this) then return {-1,-1} end
if not IsValid(ply) or not ply:IsPlayer() then return ReturnFailure( this ) end

local Normal, Pos, monitor, Ang
local Normal, Pos, monitor, Ang, scale, emitterUseRT
-- If it's an emitter, set custom normal and pos
if (this:GetClass() == "gmod_wire_egp_emitter") then
Normal = this:GetRight()
Pos = this:LocalToWorld( Vector( -64, 0, 135 ) )
Pos, Ang, scale, emitterUseRT = GetEmitterCursorTransform( this )
Normal = Ang:Up()

monitor = { Emitter = true }
else
Expand Down Expand Up @@ -454,10 +487,16 @@

if (B >= 0) then
if (monitor.Emitter) then
local HitPos = Start + Dir * B
HitPos = this:WorldToLocal( HitPos ) - Vector( -64, 0, 135 )
local x = HitPos.x*(512/128)
local y = HitPos.z*-(512/128)
local HitPos = WorldToLocal( Start + Dir * B, Angle(), Pos, Ang )
local x, y

if emitterUseRT then
x = 256 + (HitPos.x / scale)
y = 256 - (HitPos.y / scale)
else
x = HitPos.x / scale
y = -HitPos.y / scale
end
x, y = ScaleCursor( this, x, y )
return {x,y}
else
Expand Down
Loading