Garry's Mod Wiki

Revision Difference

math.CubicBezier#551370

<cat>libraryfunc</cat>⤶ <function name="CubicBezier" parent="math" type="libraryfunc">⤶ <description>Lerp point between 4 control points with cubic bezier.⤶ <note>There is quadratic function <page>math.QuadraticBezier</page> which works with 3 control points.</note>⤶ </description>⤶ <realm>Shared and Menu</realm>⤶ <added>2023.08.03</added>⤶ <file line="258-L264">lua/includes/extensions/math.lua</file>⤶ <args>⤶ <arg name="frac" type="number">The fraction for finding the result. This number is clamped between 0 and 1.</arg>⤶ <arg name="p0" type="Vector">First control point</arg>⤶ <arg name="p1" type="Vector">First tangent</arg>⤶ <arg name="p2" type="Vector">Second tangent</arg>⤶ <arg name="p3" type="Vector">Second control point</arg>⤶ </args>⤶ <rets>⤶ <ret name="" type="Vector">Point between control points at the specified fraction</ret>⤶ </rets>⤶ </function>⤶ ⤶ <example>⤶ <description>Demonstrates the use of this function.</description>⤶ <code>⤶ 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, 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[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 )⤶ </code>⤶ <output>⤶ <image src="https://i.imgur.com/5TeyaJP.gif"/>⤶ </output>⤶ </example>⤶ ⤶