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

Fix cursor position when weapon FOV does not match player FOV #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions imgui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local function shouldAcceptInput()
end

-- don't process input if we're doing VGUI stuff (and not in context menu)
if vgui.CursorVisible() and vgui.GetHoveredPanel() ~= g_ContextMenu then
if vgui.CursorVisible() and vgui.GetHoveredPanel() ~= g_ContextMenu and not vgui.IsHoveringWorld() then
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seemed necessary because when calling gui.EnableScreenClicker(true) in my weapon to bring up the mouse, input did not seem to be accepted because I was hovering the world panel.

return false
end

Expand Down Expand Up @@ -148,7 +148,7 @@ function imgui.Start3D2D(pos, angles, scale, distanceHide, distanceFadeStart)
local eyenormal

if vgui.CursorVisible() and vgui.IsHoveringWorld() then
eyenormal = gui.ScreenToVector(gui.MousePos())
eyenormal = imgui.ScreenToVector(input.GetCursorPos())
else
eyenormal = tr.Normal
end
Expand Down Expand Up @@ -191,6 +191,14 @@ function imgui.Start3D2D(pos, angles, scale, distanceHide, distanceFadeStart)
return true
end

function imgui.ScreenToVector(x, y)
local view = render.GetViewSetup()
local w, h = ScrW(), ScrH()
local fov = view.fovviewmodel

return util.AimVector(view.angles, fov, x, y, w, h)
end

function imgui.Entity3D2D(ent, lpos, lang, scale, ...)
gState.entity = ent
local ret = imgui.Start3D2D(ent:LocalToWorld(lpos), ent:LocalToWorldAngles(lang), scale, ...)
Expand Down