diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml
index d0cab7118c..458f97b6d0 100644
--- a/Docs/Luadoc/Lua.xml
+++ b/Docs/Luadoc/Lua.xml
@@ -1361,6 +1361,14 @@
+
+
+
+
+
+
+
+
@@ -1393,6 +1401,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml
index 2142ce3cb5..599f9e9dba 100644
--- a/Docs/Luadoc/LuaDocumentation.xml
+++ b/Docs/Luadoc/LuaDocumentation.xml
@@ -126,6 +126,9 @@ save yourself some time, copy this for undocumented things:
converts them to equivalent lua files. See Docs/Themerdocs/XmlToLua.txt
for details.
+
+ Creates a RageBezier2D for you to use. Make sure you destroy the RageBezier2D when you're done with it, or you will have a memory leak.
+
Creates a CubicSplineN for you to use. Make sure you destroy the CubicSplineN when you're done with it, or you will have a memory leak.
@@ -4027,6 +4030,32 @@ save yourself some time, copy this for undocumented things:
Returns the value of rc from .
+
+
+ You must call create_bezier to create a RageBezier2D to use any of these functions. When you are done with the object, destroy it with its destroy function to avoid a memory leak.
+ A RageBezier2D is two RageQuadratics, one for the x coordinate and one for the y.
+ This class is provided as a tool for designers working with bezier tweens who need a tool that displays the tween curve visually.
+ If you use Actor:tween(time, "TweenType_Bezier", {xa, ya, xb, yb, xc, yc, xd, yd}) to tween an actor, the actor creates a RageBezier2D internally and calls evaluate_y_from_x each frame to set where it is in the tween.
+
+
+ Destroys the RageBezier2D. Do not attempt to use it after it has been destroyed.
+
+
+ Evaluates the bezier curve at the given t and returns the x and y values. This is equivalent to using get_x and get_y to fetch the quadratic parts and calling evaluate on them directly.
+
+
+ Takes the x given and converts it to a t value, then evaluates the y quadratic with the t value and returns the result.
+
+
+ Returns the RageQuadratic used for the x component.
+
+
+ Returns the RageQuadratic used for the y component.
+
+
+ Sets the values used by the two quadratics. This is equivalent to using get_x and get_y to get the quadratics and setting them directly. Note that the components for the x quadratic and the y quadratic are interleaved.
+
+
Return the height of the display.
@@ -4113,6 +4142,33 @@ save yourself some time, copy this for undocumented things:
Return an array of connected input device descriptions.
+
+
+ If you use Actor:tween(time, "TweenType_Bezier", {a, b, c, d}) to tween an actor, the actor creates a RageQuadratic internally and calls evaluate each frame to set where it is in the tween.
+
+
+ Evaluates the quadratic at the given t value and returns the result.
+
+
+ Returns the four values that form the quadratic equation. This function returns multiple values, so you must do something like this to get them:
+ a, b, c, d= quadratic:get_bezier()
+
+
+ Equivalent to evaluate(1), but faster.
+
+
+ Equivalent to evaluate(0), but faster.
+
+
+ Returns the slope of the curve at the given t value.
+
+
+ Sets the four values that form the quadratic equation.
+
+
+ Sets the four values that form the quadratic equation, treating the arguments as from a cubic equation instead of as from a bezier curve.
+
+
See for loading a sound.
diff --git a/src/RageMath.cpp b/src/RageMath.cpp
index bc35fbdbe7..4f403e34d5 100644
--- a/src/RageMath.cpp
+++ b/src/RageMath.cpp
@@ -729,6 +729,119 @@ void RageBezier2D::SetFromBezier(
m_Y.SetFromBezier( fC1Y, fC2Y, fC3Y, fC4Y );
}
+#include "LuaBinding.h"
+
+struct LunaRageQuadratic : Luna
+{
+ static int evaluate(T* p, lua_State* L)
+ {
+ lua_pushnumber(L, p->Evaluate(FArg(1)));
+ return 1;
+ }
+ static int get_bezier(T* p, lua_State* L)
+ {
+ float a, b, c, d;
+ p->GetBezier(a, b, c, d);
+ lua_pushnumber(L, a);
+ lua_pushnumber(L, b);
+ lua_pushnumber(L, c);
+ lua_pushnumber(L, d);
+ return 4;
+ }
+ static int get_bezier_end(T* p, lua_State* L)
+ {
+ lua_pushnumber(L, p->GetBezierEnd());
+ return 1;
+ }
+ static int get_bezier_start(T* p, lua_State* L)
+ {
+ lua_pushnumber(L, p->GetBezierStart());
+ return 1;
+ }
+ static int get_slope(T* p, lua_State* L)
+ {
+ lua_pushnumber(L, p->GetSlope(FArg(1)));
+ return 1;
+ }
+ static int set_from_bezier(T* p, lua_State* L)
+ {
+ p->SetFromBezier(FArg(1), FArg(2), FArg(3), FArg(4));
+ COMMON_RETURN_SELF;
+ }
+ static int set_from_cubic(T* p, lua_State* L)
+ {
+ p->SetFromCubic(FArg(1), FArg(2), FArg(3), FArg(4));
+ COMMON_RETURN_SELF;
+ }
+ LunaRageQuadratic()
+ {
+ ADD_METHOD(evaluate);
+ ADD_METHOD(get_bezier);
+ ADD_METHOD(get_bezier_end);
+ ADD_METHOD(get_bezier_start);
+ ADD_METHOD(get_slope);
+ ADD_METHOD(set_from_bezier);
+ ADD_METHOD(set_from_cubic);
+ }
+};
+LUA_REGISTER_CLASS(RageQuadratic);
+
+struct LunaRageBezier2D : Luna
+{
+ static int evaluate(T* p, lua_State* L)
+ {
+ float x, y;
+ p->Evaluate(FArg(1), &x, &y);
+ lua_pushnumber(L, x);
+ lua_pushnumber(L, y);
+ return 2;
+ }
+ static int evaluate_y_from_x(T* p, lua_State* L)
+ {
+ lua_pushnumber(L, p->EvaluateYFromX(FArg(1)));
+ return 1;
+ }
+ static int get_x(T* p, lua_State* L)
+ {
+ p->get_x().PushSelf(L);
+ return 1;
+ }
+ static int get_y(T* p, lua_State* L)
+ {
+ p->get_y().PushSelf(L);
+ return 1;
+ }
+ static int set_from_bezier(T* p, lua_State* L)
+ {
+ p->SetFromBezier(FArg(1), FArg(2), FArg(3), FArg(4), FArg(5), FArg(6), FArg(7), FArg(8));
+ COMMON_RETURN_SELF;
+ }
+ static int destroy(T* p, lua_State* L)
+ {
+ SAFE_DELETE(p);
+ return 0;
+ }
+ LunaRageBezier2D()
+ {
+ ADD_METHOD(destroy);
+ ADD_METHOD(evaluate);
+ ADD_METHOD(evaluate_y_from_x);
+ ADD_METHOD(get_x);
+ ADD_METHOD(get_y);
+ ADD_METHOD(set_from_bezier);
+ }
+};
+LUA_REGISTER_CLASS(RageBezier2D);
+
+int LuaFunc_create_bezier(lua_State* L);
+int LuaFunc_create_bezier(lua_State* L)
+{
+ RageBezier2D* bezier= new RageBezier2D;
+ bezier->PushSelf(L);
+ return 1;
+}
+LUAFUNC_REGISTER_COMMON(create_bezier);
+
/*
* Copyright (c) 2001-2006 Chris Danford, Glenn Maynard
* All rights reserved.
diff --git a/src/RageMath.h b/src/RageMath.h
index cac76e9549..12b91fe556 100644
--- a/src/RageMath.h
+++ b/src/RageMath.h
@@ -8,6 +8,7 @@
#define RadianToDegree( radian ) ((radian) * (180.0f / PI))
+struct lua_State;
struct RageVector2;
struct RageVector3;
struct RageVector4;
@@ -70,6 +71,7 @@ public:
float GetBezierStart() const { return m_fD; }
float GetBezierEnd() const { return m_fA + m_fB + m_fC + m_fD; }
+ void PushSelf(lua_State* L);
private:
float m_fA, m_fB, m_fC, m_fD;
};
@@ -83,6 +85,9 @@ public:
void Evaluate( float fT, float *pX, float *pY ) const;
float EvaluateYFromX( float fX ) const;
+ RageQuadratic& get_x() { return m_X; }
+ RageQuadratic& get_y() { return m_Y; }
+ void PushSelf(lua_State* L);
private:
RageQuadratic m_X;
RageQuadratic m_Y;