Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bezier = {}
- bezier.__index = bezier
- function bezier:curve ( xv, yv ) -- Thx to ma homeboi Rajendro
- local reductor = { __index = function ( self, ind )
- return setmetatable ( { tree = self, level = ind }, { __index = function ( curves, ind )
- return function ( t )
- local x1, y1 = curves.tree[curves.level-1][ind](t)
- local x2, y2 = curves.tree[curves.level-1][ind+1](t)
- return x1 + ( x2 - x1 ) * t, y1 + ( y2 - y1 ) * t
- end
- end } )
- end }
- local points = { }
- for i = 1, #xv do
- points[i] = function ( t ) return xv[i], yv[i] end
- end
- return setmetatable ( { points }, reductor )[#points][1]
- end
- -- TEST
- local curve = bezier:curve ( { 50, 30, 100 }, { 90, 50, 30 } )
- addEventHandler ( "onClientRender", root,
- function ( )
- local curves = { }
- for i = 0.01, 1, 0.1 do
- local x, y = curve ( i )
- table.insert ( curves, { x, y } )
- end
- for i,v in ipairs ( curves ) do
- local x, y = unpack ( v )
- local z = getGroundPosition ( x, y, 1000 )
- if curves[i+1] then
- local nx, ny = unpack ( curves[i+1] )
- local nz = getGroundPosition ( nx, ny, 1000 )
- --dxDrawLine3D ( x, y, z + 0.1, nx, ny, nz + 0.1, tocolor ( 255, 0, 0, 255 ), 4 )
- dxDrawLine ( x, y, nx, ny, tocolor ( 255, 255, 255, 255 ) )
- end
- end
- curves = nil
- end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement