CapsAdmin

Untitled

Sep 19th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. if SERVER then return end
  2.  
  3. local html = aahh.Create("html")
  4. html:SetSize(Vec2()+400)
  5. html:LoadURL("http://morten.ae/stream/")
  6.  
  7. local voldata = Vec3(1,1,1) -- V, L, R
  8. local should_play = true
  9.  
  10. local function calcsource(eye, rgt, src, dist, fwd)
  11.     local vol = math.clamp(-((eye - src):GetLength() / dist) + 1, 0, 1)
  12.     local dot = rgt:Dot((src - eye):Normalize())
  13.  
  14.     voldata.x = vol * 2
  15.  
  16.     voldata.y = math.clamp(-dot, 0, 1) + 0.5
  17.     voldata.z = math.clamp(dot, 0, 1) + 0.5
  18.  
  19.     should_play = vol ~= 0
  20. end
  21.  
  22. local source = here
  23. local function CalcVolumeData()
  24.     local ply = entities.GetLocalPlayer()
  25.     if ply:IsValid() then
  26.         local ang = ply:GetViewRotation():GetAng3()
  27.         return calcsource(ply:GetEyePos(), ang:GetRight(), source, 10, ang:GetForward())
  28.     else
  29.         local x,y = mouse.GetPos()
  30.         local w,h = render.GetScreenSize()
  31.         voldata.x = y / h
  32.        
  33.         voldata.y = x / w
  34.         voldata.z = x / w
  35.     end
  36. end
  37.  
  38.  
  39. function html:OnThink()
  40.     CalcVolumeData()
  41.    
  42.     if should_play then
  43.         print(self.webview:ExecuteJavascriptWithResult(("setVolume(%s); setPanning(%s)"):format(voldata.x, voldata.y * voldata.z)))
  44.     end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment