Advertisement
GravityCube

MonitorLink

Dec 26th, 2018
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. --[[
  2.    
  3.             --*--*--*--*--*--*--*--*--*--*--*--*--*--*--   
  4.             --*     MonitorLink with OpenCCSensors   *--
  5.             --*     https://pastebin.com/qaYR1mMu    *--
  6.             --*    by: GravityCube and Archmaestro   *--
  7.             --*--*--*--*--*--*--*--*--*--*--*--*--*--*--
  8.  
  9.            
  10.     Changelog:
  11.         1.0.0 First Release
  12.        
  13. --]]
  14. --------------------------------------------------------
  15. -->                    Variables                     <--
  16. --------------------------------------------------------
  17. x0 = 6.19744
  18. y0 = 5.1204934
  19.  
  20. x00 = -0.8715613
  21. y00 = 1.1154351
  22.  
  23. proX = 142/math.abs(x0-x00)
  24. proY = 51/math.abs(y0-y00)
  25.  
  26. --------------------------------------------------------
  27. -->                   Main Program                  <--
  28. --------------------------------------------------------
  29. function make(xval, yval, zval)
  30.     return {x=xval, y=yval, z=zval}
  31. end
  32.  
  33. function plus(lhs, rhs)
  34.     return make(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z)
  35. end
  36.  
  37. function minus(lhs, rhs)
  38.     return make(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z)
  39. end
  40.  
  41. function times(lhs, scale)
  42.     return make(scale * lhs.x, scale * lhs.y, scale * lhs.z)
  43. end
  44.  
  45. function dot(lhs, rhs)
  46.     return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z
  47. end
  48.  
  49. function tostr(val)
  50.     return "(" .. val.x .. ", " .. val.y .. ", " .. val.z .. ")"
  51. end
  52.  
  53. function intersectPoint(rayVector, rayPoint, planeNormal, planePoint)
  54.     diff = minus(rayPoint, planePoint)
  55.     prod1 = dot(diff, planeNormal)
  56.     prod2 = dot(rayVector, planeNormal)
  57.     prod3 = prod1 / prod2
  58.     return minus(rayPoint, times(rayVector, prod3))
  59. end
  60.  
  61. function getLookVector(yaw,pitch)
  62.     local yaw = (yaw+360+90)*2*math.pi/360
  63.     local pitch = pitch*2*math.pi/360
  64.     local xzLen = math.cos(pitch)
  65.     local x = -xzLen * math.cos(yaw)
  66.     local y = -math.sin(pitch)
  67.     local z = -xzLen * math.sin(-yaw)
  68.     return make(x,y,z)
  69. end
  70. function getCursorPos(x1, y1, z1, yaw, pitch)
  71.     v1 = getLookVector(yaw,pitch)
  72.     p1 = make(x1,y1+1.62,z1)
  73.     vn = make(0,0,1)
  74.     vp = make(0,0,0.5)
  75.    
  76.     --NEED TO ADD DIRECTION CALC
  77.     int = intersectPoint(v1, p1, vn, vp)
  78.     local x = math.floor((x0-int.x)*proX)+1
  79.     local y = math.floor((y0-int.y)*proY)+1
  80.    
  81.     return x, y
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement