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
+8
View File
@@ -26,6 +26,7 @@
// LOVE
#include "common/Module.h"
#include "common/math.h"
#include "common/Vector.h"
#include "common/int.h"
// Noise
@@ -39,6 +40,8 @@ namespace love
namespace math
{
class BezierCurve;
class Math : public Module
{
private:
@@ -95,6 +98,11 @@ public:
**/
RandomGenerator *newRandomGenerator();
/**
* Creates a new bezier curve.
**/
BezierCurve *newBezierCurve(const std::vector<Vector> &points);
virtual const char *getName() const
{
return "love.math";