Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a max distance input to the cam controller #3237

Merged
merged 3 commits into from
Jan 6, 2025
Merged
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
21 changes: 16 additions & 5 deletions lua/entities/gmod_wire_cameracontroller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
local enabled = false
local self

local clientprop

Check warning on line 48 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: clientprop

-- Position
local pos = Vector(0,0,0)
Expand All @@ -53,9 +53,10 @@

-- Distance & zooming
local distance = 0
local curdistance = 0

Check warning on line 56 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: curdistance
local oldcurdistance = 0

Check warning on line 57 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: oldcurdistance
local smoothdistance = 0
local maxdistance = 16000

local zoomdistance = 0
local zoombind = 0
Expand All @@ -64,11 +65,11 @@
local ang = Angle(0,0,0)
local smoothang = Angle(0,0,0)

local oldeyeang = Angle(0,0,0)

Check warning on line 68 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: oldeyeang
local unroll = false

-- Options
local ParentLocal = false

Check warning on line 72 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: ParentLocal
local AutoMove = false
local FreeMove = false
local LocalMove = false
Expand Down Expand Up @@ -114,7 +115,7 @@
local tr = {
start = start,
endpos = endpos,
mask = (AutoUnclip_IgnoreWater and CONTENTS_SOLID or bit.bor(MASK_WATER, CONTENTS_SOLID)),

Check warning on line 118 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
mins = Vector(-8,-8,-8),
maxs = Vector(8,8,8)
}
Expand Down Expand Up @@ -150,11 +151,11 @@
smoothpos = LerpVector( FrameTime() * pos_speed, smoothpos, curpos )

local pos_speed = pos_speed_convar:GetFloat()
local ang_speed = pos_speed - 2

Check warning on line 154 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: ang_speed

if AllowZoom then
if zoombind ~= 0 then
zoomdistance = math.Clamp(zoomdistance + zoombind * FrameTime() * 100 * max((abs(curdistance) + abs(zoomdistance))/10,10),0,16000-curdistance)
zoomdistance = math.Clamp(zoomdistance + zoombind * FrameTime() * 100 * max((abs(curdistance) + abs(zoomdistance))/10,10),0,math.min(16000-curdistance, maxdistance))
zoombind = 0
end
curdistance = curdistance + zoomdistance
Expand Down Expand Up @@ -268,6 +269,11 @@

-- distance
distance = math.Clamp(net.ReadFloat(),-16000,16000)
maxdistance = net.ReadFloat()

if AutoMove and AllowZoom then
zoombind = 1
end

-- Parent
WaitingForID = net.ReadInt(32)
Expand Down Expand Up @@ -374,6 +380,7 @@
"Angle (Sets the direction of the camera, in angle form.\nIf clientside movement is enabled, this is ignored.) [ANGLE]",
"Position (Sets the position of the camera.\nIf clientside movement is enabled, this specifies the center of the camera's orbit.) [VECTOR]",
"Distance (Sets the 'distance' of the camera.\nIn other words, the camera will be moved away from the specified position by this amount.\nIf clientside zooming is enabled, this is the farthest you can zoom in.)",
"MaxDistance (Sets the max distance the camera can zoom out to.\n Needs clientside movement and clientside zooming to be enabled.)",
"UnRoll (If free movement is enabled, this resets the roll back to zero.)",
"Parent (Parents the camera to this entity.) [ENTITY]",
"FilterEntities (In addition to ignoring the contraption of the 'Parent' entity, or the cam controller itself\nif parent isn't used, entities in this list will be ignored by the 'HitPos' and 'Trace' outputs) [ARRAY]",
Expand All @@ -390,6 +397,7 @@
self.Position = Vector(0,0,0)
self.Angle = Angle(0,0,0)
self.Distance = 0
self.MaxDistance = 16000
self.UnRoll = false

self.Players = {}
Expand Down Expand Up @@ -456,7 +464,7 @@
-- Data sending
--------------------------------------------------

local function SendPositions( pos, ang, dist, parent, unroll )
local function SendPositions( pos, ang, dist, parent, unroll, maxdist )
-- pos/ang
net.WriteFloat( pos.x )
net.WriteFloat( pos.y )
Expand All @@ -469,6 +477,7 @@

-- distance
net.WriteFloat( dist )
net.WriteFloat( maxdist )

-- parent
local id = IsValid( parent ) and parent:EntIndex() or -1
Expand All @@ -492,7 +501,7 @@
net.WriteBit( self.AutoUnclip_IgnoreWater )
net.WriteBit( self.DrawPlayer )
net.WriteBit( self.DrawParent )
SendPositions( self.Position, self.Angle, self.Distance, self.Parent, self.UnRoll )
SendPositions( self.Position, self.Angle, self.Distance, self.Parent, self.UnRoll, self.MaxDistance )
end
net.Send( ply )
end
Expand All @@ -501,9 +510,9 @@
util.AddNetworkString( "wire_camera_controller_sync" )
function ENT:SyncPositions( ply )
if not IsValid(ply) then ply = self.Players end
net.Start( "wire_camera_controller_sync" )
net.Start( "wire_camera_controller_sync", true )
net.WriteEntity( self )
SendPositions( self.Position, self.Angle, self.Distance, self.Parent, self.UnRoll )
SendPositions( self.Position, self.Angle, self.Distance, self.Parent, self.UnRoll, self.MaxDistance )
net.Send( ply )
end

Expand Down Expand Up @@ -578,7 +587,7 @@
local tr = {
start = start,
endpos = endpos,
mask = (self.AutoUnclip_IgnoreWater and CONTENTS_SOLID or bit.bor(MASK_WATER, CONTENTS_SOLID)),

Check warning on line 590 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
mins = Vector(-8,-8,-8),
maxs = Vector(8,8,8)
}
Expand Down Expand Up @@ -863,6 +872,8 @@
self.Position = value
elseif name == "Distance" then
self.Distance = value
elseif name == "MaxDistance" then
self.MaxDistance = value
elseif name == "UnRoll" then
self.UnRoll = tobool(value)
elseif name == "Direction" then
Expand Down
Loading