Garry's Mod Wiki

math.CubicBezier

  Vector math.CubicBezier( number frac, Vector p0, Vector p1, Vector p2, Vector p3 )

Description

Lerp point between 4 control points with cubic bezier.

See math.QuadraticBezier for a similar function which works with 3 control points.

Arguments

1 number frac
The fraction for finding the result. This number is clamped between 0 and 1.
2 Vector p0
First control point
3 Vector p1
First tangent
4 Vector p2
Second tangent
5 Vector p3
Second control point

Returns

1 Vector
Point between control points at the specified fraction

Example

Demonstrates the use of this function.

local points = { Vector( 128, 128 ), Vector( 384, 128 ), Vector( 384, 384 ), Vector( 128, 384 ) } hook.Add( "HUDPaint", "math.CubicBezier", function() local frac = RealTime() % 1 local point = math.CubicBezier( frac, points[1], points[2], points[3], points[4] ) 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[2].x - 4, points[2].y - 4, 8, 8 ) surface.DrawRect( points[3].x - 4, points[3].y - 4, 8, 8 ) surface.DrawRect( points[4].x - 4, points[4].y - 4, 8, 8 ) end )
Output: