local function FormatViewModelAttachment(vOrigin, bFrom )
local view
= render.
GetViewSetup()
local vEyePos
= view.origin
local aEyesRot
= view.angles
local vOffset
= vOrigin
- vEyePos
local vForward
= aEyesRot:
Forward()
local nViewX
= math.
tan( view.fovviewmodel_unscaled
* math.pi
/ 360)
if (nViewX
== 0)
then
vForward:
Mul(
vForward:
Dot(vOffset))
vEyePos:
Add(vForward)
return vEyePos
end
local nWorldX
= math.
tan( view.fov_unscaled
* math.pi
/ 360)
if (nWorldX
== 0)
then
vForward:
Mul(
vForward:
Dot(vOffset))
vEyePos:
Add(vForward)
return vEyePos
end
local vRight
= aEyesRot:
Right()
local vUp
= aEyesRot:
Up()
if (bFrom)
then
local nFactor
= nWorldX
/ nViewX
vRight:
Mul(
vRight:
Dot(vOffset)
* nFactor)
vUp:
Mul(
vUp:
Dot(vOffset)
* nFactor)
else
local nFactor
= nViewX
/ nWorldX
vRight:
Mul(
vRight:
Dot(vOffset)
* nFactor)
vUp:
Mul(
vUp:
Dot(vOffset)
* nFactor)
end
vForward:
Mul(
vForward:
Dot(vOffset))
vEyePos:
Add(vRight)
vEyePos:
Add(vUp)
vEyePos:
Add(vForward)
return vEyePos
end
SWEP.BoxAttachment
= "muzzle"
SWEP.BoxMins
= Vector(
-2,
-2,
-2)
SWEP.BoxMaxs
= Vector(
2,
2,
2)
SWEP.BoxColor
= Color(
0,
255,
0)
function SWEP:
ViewModelDrawn()
local pOwner
= self:
GetOwner()
if (
not pOwner:
IsValid())
then return end
local pViewModel
= pOwner:
GetViewModel()
if (
not pViewModel:
IsValid())
then return end
local uAttachment
= pViewModel:
LookupAttachment(self.BoxAttachment)
if (uAttachment
< 1)
then return end
local tAttachment
= pViewModel:
GetAttachment(uAttachment)
if (tAttachment
== nil)
then return end
render.
DrawWireframeBox(
FormatViewModelAttachment(tAttachment.Pos,
false), tAttachment.Ang, self.BoxMins, self.BoxMaxs, self.BoxColor,
true)
end