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

Conversation

dhkatz
Copy link

@dhkatz dhkatz commented Oct 29, 2023

This is a PR which fixes #35

As far as I can tell this hasn't broken anything else but if someone can confirm that would be great.

I ended up adding a new function specifically for weapons because we only want to do FOV corrects for view models.

I did not automatically convert the position and angles using ENTITY:LocalToWorld(pos) because I assumed most people will be positioning view model UI relative to bone positions and ENTITY:GetBonePosition(n) always returns values in world space coordinates.

Before Fix:

gmod_huaxYFYBfd.mp4

Notice how the mouse does not line up with the cursor while the screen clicker is active (the virtual cursor is being rendered by the weapon's SWEP:PostDrawViewMode)

After Fix:

gmod_hKxs9xbz2R.mp4

I can interact with both the button positioned in the world and the button positioned on the view model accurately to the mouse cursor.

@@ -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.

@dhkatz
Copy link
Author

dhkatz commented Oct 29, 2023

Ok it looks like this did break some things, so I might need to add a specific function for weapons like entities have

@dhkatz
Copy link
Author

dhkatz commented Oct 29, 2023

Ok I seem to have fixed the issues by adding a new function to only correct FOV using view model when rendering for a weapon

Copy link
Contributor

@wyozi wyozi left a comment

Choose a reason for hiding this comment

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

Looks good, thanks. If you can just add ScrW and ScrH to .luacheckrc, I can merge this. Could also add a short mention to README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImGUI on viewmodel doesn't properly find cursor position
2 participants