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 gimbal gizmo #3273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
37 changes: 37 additions & 0 deletions lua/entities/gmod_wire_gimbal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@ DEFINE_BASECLASS( "base_wire_entity" )
ENT.PrintName = "Wire Gimbal"
ENT.WireDebugName = "Gimbal"

local ORIGIN_COLOR = Color(255, 150, 50)
local FORWARD_COLOR = Color(255, 100, 100)
local RIGHT_COLOR = Color(100, 255, 100)
local UP_COLOR = Color(100, 100, 255)

local function DrawOutlinedBeam(startPos, endPos, size, color)
render.DrawBeam(startPos, endPos, size + 0.2, 0, 1, color_black)
render.DrawBeam(startPos, endPos, size, 0, 1, color)
end

function ENT:Draw()
BaseClass.Draw(self)
if not self:BeingLookedAtByLocalPlayer() then return end

local weapon = LocalPlayer():GetActiveWeapon():GetClass()
if weapon ~= "weapon_physgun" and weapon ~= "gmod_tool" then return end
Comment on lines +18 to +21
Copy link
Contributor

Choose a reason for hiding this comment

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

Can ENT:DrawWorldTip be used instead? Then you can get rid of these lines.


local origin = self:GetPos()
local mi, ma = self:GetRenderBounds()
local forwardSize = math.max(math.abs(mi[1]), ma[1])
local rightSize = math.max(math.abs(mi[2]), ma[2])
local upSize = math.max(math.abs(mi[3]), ma[3])

local forward = self:GetForward() * forwardSize
local right = self:GetRight() * rightSize
local up = self:GetUp() * upSize

render.SetColorMaterialIgnoreZ()

DrawOutlinedBeam(origin, origin + forward, 0.2, FORWARD_COLOR)
DrawOutlinedBeam(origin, origin + right, 0.2, RIGHT_COLOR)
DrawOutlinedBeam(origin, origin + up, 0.2, UP_COLOR)

render.DrawSphere(origin, 0.35, 8, 8, color_black)
render.DrawSphere(origin, 0.2, 8, 8, ORIGIN_COLOR)
end

if CLIENT then return end -- No more client

function ENT:Initialize()
Expand Down