Guest User

graphics

a guest
Jun 17th, 2013
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. --Focal distance. Tweak to change lens angle
  2. local focalDistance = 20
  3. --Display width and height.
  4. local dispWidth, dispHeight = term.getSize()
  5.  
  6. function project(vertex)
  7.     local zval = vertex.z
  8.     if zval == 0 then zval = 1 end --Stops divide by zeros
  9.    
  10.     --I've applied centring to the display (after all the camera doesn't need to include this)
  11.     --Note focal projection is square but centring is applied according to screen dimensions
  12.     local xmap = (focalDistance * vertex.x) / (vertex.z + math.min(dispHeight,dispWidth)/2) + dispWidth/3
  13.     local ymap = (focalDistance * vertex.y) / (vertex.z + math.min(dispHeight,dispWidth)/2) + dispHeight/2
  14.    
  15.     --Correcting for pixel size
  16.     xmap = (3 * xmap) / 2
  17.    
  18.     return { x = xmap, y = ymap }
  19. end
Advertisement
Add Comment
Please, Sign In to add comment