Add support for Bezier curves of arbitrary degree.

New functions:

bezier = love.math.newBezierCurve(control-points)
degree = bezier:getDegree() -- degree = #control-points - 1
x,y = bezier:getControlPoint(pos) -- pos < 0 => string.sub semantics
bezier:setControlPoint(pos, x, y) -- pos < 0 => string.sub semantics
bezier:insertControlPoint(x,y, [pos = -1])
x,y = bezier:eval(t) -- 0 <= t <= 1
polyline = bezier:render([accuracy = 5]) -- returns a table of points

Example:

function love.load()
	b = love.math.newBezierCurve(10,10, 80,400, 380,400, 470,10)
end

function love.draw()
	if not curve then -- curve rendering is expensive-ish
		curve = b:render()
	end
	love.graphics.line(curve)
end
This commit is contained in:
vrld
2013-05-12 21:57:06 +02:00
parent aa59761177
commit 19eade843c
6 changed files with 60 additions and 0 deletions
+1
View File
@@ -503,6 +503,7 @@ StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[] =
// Math
{"RandomGenerator", MATH_RANDOM_GENERATOR_ID},
{"BezierCurve", MATH_BEZIER_CURVE_ID},
// Audio
{"Source", AUDIO_SOURCE_ID},
+2
View File
@@ -60,6 +60,7 @@ enum Type
// Math
MATH_RANDOM_GENERATOR_ID,
MATH_BEZIER_CURVE_ID,
// Audio
AUDIO_SOURCE_ID,
@@ -136,6 +137,7 @@ const bits IMAGE_COMPRESSED_DATA_T = (bits(1) << IMAGE_COMPRESSED_DATA_ID) | DAT
// Math.
const bits MATH_RANDOM_GENERATOR_T = (bits(1) << MATH_RANDOM_GENERATOR_ID) | OBJECT_T;
const bits MATH_BEZIER_CURVE_T = (bits(1) << MATH_BEZIER_CURVE_ID) | OBJECT_T;
// Audio.
const bits AUDIO_SOURCE_T = (bits(1) << AUDIO_SOURCE_ID) | OBJECT_T;