math.CHSpline
Example
local points = {
Vector( 128, 128 ), -- point 1
Vector( 384, 128 ), -- tangent pos 1
Vector( 128, 384 ), -- point 2
Vector( 384, 384 ) -- tangent pos 2
}
hook.Add( "HUDPaint", "math.BezierLerp", function()
local frac = RealTime() % 1
local point = math.CHSpline( frac, unpack( points ) )
surface.SetDrawColor( 255, 255, 0 )
surface.DrawRect( point.x - 4, point.y - 4, 8, 8 )
surface.DrawRect( points[1].x - 4, points[1].y - 4, 8, 8 )
surface.DrawRect( points[3].x - 4, points[3].y - 4, 8, 8 )
surface.SetDrawColor( 255, 0, 0 )
surface.DrawRect( points[2].x - 4, points[2].y - 4, 8, 8 )
surface.DrawRect( points[4].x - 4, points[4].y - 4, 8, 8 )
-- Draw the spline
for i=0,20 do
local point = math.CHSpline( i / 20, unpack( points ) )
surface.SetDrawColor( 0, 255, 0 )
surface.DrawRect( point.x - 2, point.y - 2, 4, 4 )
end
end )