math/BSplinePoint

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Code still referenced a variable e, which does not exist.)
 
Line 35: Line 35:
  
 
-- Draw the spline
 
-- Draw the spline
local pos = math.BSplinePoint( ( math.cos( CurTime() ) + 1 ) / 2, e, 1 )
+
local pos = math.BSplinePoint( ( math.cos( CurTime() ) + 1 ) / 2, points, 1 )
 
draw.RoundedBox( 0, pos.x - 2, pos.y - 2, 4, 4, Color( 0, 0, 0 ) )
 
draw.RoundedBox( 0, pos.x - 2, pos.y - 2, 4, 4, Color( 0, 0, 0 ) )
 
end )
 
end )
 
}}
 
}}

Latest revision as of 14:48, 20 September 2019

 math.BSplinePoint( )

Contents

Description

Basic code for Bézier-Spline algorithm.

Arguments

number tDiff

From 0 to 1, where alongside the spline the point will be.

Arguments

table tPoints

A table of Vectors. The amount cannot be less than 4.

Arguments

number tMax

Just leave this at 1.

Returns

Vector

Point on Bezier curve, related to tDiff.

Examples

Example

Example usage of the function, makes a black box moving along the beizer curve made out of 4 points

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 id, p in pairs( points ) do
		draw.RoundedBox( 0, p.x - 2, p.y - 2, 4, 4, color_white )
	end

	-- Draw 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( 0, 0, 0 ) )
end )


Personal tools
Navigation