daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Jul 17th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local viewport = {}
  2.  
  3. viewport.width, viewport.height = 640,480
  4.  
  5. local cam = Camera.get()[1]
  6. local buffer = Graphics.CaptureBuffer(cam.width,cam.height)
  7.  
  8. function viewport.onInitAPI()
  9.     registerEvent(viewport,"onCameraUpdate")
  10. end
  11.  
  12. function viewport.onCameraUpdate()
  13.  
  14.     local boundary = player.sectionObj.boundary
  15.    
  16.     local pHeight = player:getCurrentPlayerSetting().hitboxHeight
  17.    
  18.     local midX = player.x + player.width/2
  19.     local midY = player.y + player.height - pHeight/2
  20.    
  21.     local x = {min = midX - viewport.width /2, max = midX + viewport.width /2}
  22.     local y = {min = midY - viewport.height/2, max = midY + viewport.height/2}
  23.    
  24.     if x.min < boundary.left then
  25.         x.max = x.max + (boundary.left - x.min)
  26.         x.min = boundary.left
  27.     elseif x.max > boundary.right then
  28.         x.min = x.min - (x.max - boundary.right)
  29.         x.max = boundary.right
  30.     end
  31.    
  32.     if y.min < boundary.top then
  33.         y.max = y.max + (boundary.top - y.min)
  34.         y.min = boundary.top
  35.     elseif y.max > boundary.bottom then
  36.         y.min = y.min - (y.max - boundary.bottom)
  37.         y.max = boundary.bottom
  38.     end
  39.        
  40.     x.min = (x.min - cam.x)/cam.width
  41.     x.max = (x.max - cam.x)/cam.width
  42.     y.min = (y.min - cam.y)/cam.height
  43.     y.max = (y.max - cam.y)/cam.height
  44.    
  45.     buffer:captureAt(-0.2)
  46.     Graphics.glDraw{
  47.         texture = buffer,
  48.         vertexCoords = {
  49.             0,         0,
  50.             cam.width, 0,
  51.             cam.width, cam.height,
  52.             0,         cam.height
  53.         },
  54.         textureCoords = {
  55.             x.min, y.min,
  56.             x.max, y.min,
  57.             x.max, y.max,
  58.             x.min, y.max
  59.         },
  60.         primitive = Graphics.GL_TRIANGLE_FAN,
  61.         priority = -0.1
  62.     }
  63. end
  64.  
  65. return viewport
RAW Paste Data
Top