Garry's Mod Wiki

math.BSplinePoint

Vector math.BSplinePoint( number tDiff, table tPoints, number tMax )

Description

Basic code for algorithm.

Arguments

1 number tDiff
From 0 to 1, where alongside the spline the point will be.
2 table tPoints
A table of Vectors. The amount cannot be less than 4.
3 number tMax
Just leave this at 1.

Returns

1 Vector
Point on Bezier curve, related to tDiff.

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 )

Page Links


Special Pages


Wikis

?

Render Time: 38ms

Session 0
DB GetPage 3
Generate Html 14
SaveChanges 7
Render Body 0
Render Sidebar 11