thomasfn

Angle mathz

Jul 1st, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1.  
  2.  
  3. local bladeInfo = {
  4.     [1] = { 0, 1 }, -- Top blade
  5.     [2] = { 1, 0 }, -- Right blade
  6.     [3] = { 0, -1 }, -- Bottom blade
  7.     [3] = { -1, 0 } -- Left blade
  8. }
  9.  
  10.  
  11. FACING_FORWARD = 0
  12. FACING_RIGHT = math.pi / 2
  13. FACING_BACK = math.pi
  14. FACING_LEFT = (math.pi / 2) * 3
  15.  
  16. function DoWindmillArms( x, y, z, ang, facing )
  17.     -- This function assumes the previous blocks of the windmill blades have already been cleared
  18.     -- x, y, z is the origin - the center of the windmill blades
  19.     -- ang is the angle of the entire windmill
  20.     -- facing is the direction the windmill is facing, on the y axis
  21.    
  22.     local bladeLength = 1
  23.    
  24.     for i=1, 4 do -- For each blade
  25.         -- i is the blade ID
  26.        
  27.         for j=1, bladeLength do -- For each block along the blade
  28.             -- Get the block coordinate along the blade, if the windmill was at angle 0
  29.             local bX = bladeInfo[i][1] * j
  30.             local bY = bladeInfo[i][2] * j
  31.            
  32.             -- Now, we'll rotate the coordinate by ang
  33.             bX = bX * math.cos( ang ) - bY * math.sin( ang )
  34.             bY = bX * math.sin( ang ) + bY * math.cos( ang )
  35.            
  36.             -- Finally, calculate the absolute block coordinates
  37.             local blockX = x + (bX * math.cos( facing ))
  38.             local blockY = y + bY
  39.             local blockZ = z + (-bX * math.sin( facing))
  40.            
  41.             -- We have a block coordinate!
  42.             -- TODO: Call function to set block ID to wood (or whatever) here
  43.        
  44.        
  45.         end
  46.        
  47.     end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment