Revision Difference
math.BSplinePoint#551296
<function name="BSplinePoint" parent="math" type="libraryfunc">
<description>Basic code for algorithm.</description>
<description>Basic code for Bezier-Spline algorithm.</description>
<realm>Shared and Menu</realm>
<file line="144-L160">lua/includes/extensions/math.lua</file>
<args>
<arg name="tDiff" type="number">From 0 to 1, where alongside the spline the point will be.</arg>
<arg name="tPoints" type="table">A table of <page>Vector</page>s. The amount cannot be less than 4.</arg>
<arg name="tMax" type="number">Just leave this at 1.</arg>
</args>
<rets>
<ret name="" type="Vector">Point on Bezier curve, related to tDiff.</ret>
</rets>
</function>
<example>
<description>Example usage of the function, makes a black box moving along the beizer curve made out of 4 points.</description>
<code>
local points = { Vector( 100, 100, 0 ), Vector( 200, 200, 0 ), Vector( 300, 100, 0 ), Vector( 400, 200, 0 ) }
hook.Add( "HUDPaint", "BSplinePointExample", function()
-- Draw the points
for _, p in ipairs( points ) do
draw.RoundedBox( 0, p.x - 2, p.y - 2, 4, 4, color_white )
end
-- Draw the spline
surface.SetDrawColor( 255, 0, 0, 255 )⤶
local lastPos = math.BSplinePoint( 0, points, 1 )⤶
for i=0, 10 do⤶
local pos = math.BSplinePoint( i / 10, points, 1 )⤶
surface.DrawLine( lastPos.x, lastPos.y, pos.x, pos.y )⤶
lastPos = pos⤶
end⤶
⤶
-- Draw a point on the spline⤶
local pos = math.BSplinePoint( ( math.cos( CurTime() ) + 1 ) / 2, points, 1 )
draw.RoundedBox( 0, pos.x - 2, pos.y - 2, 4, 4, color_black )
end )
⤶
end )
</code>
</example>