mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
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:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user