Merge pull request #695 from kyzentun/bezier_lua
Added lua interface for using bezier curves. Merging for the documentation of bezier sake.
This commit is contained in:
@@ -1361,6 +1361,14 @@
|
||||
<Class name='RadarValues'>
|
||||
<Function name='GetValue'/>
|
||||
</Class>
|
||||
<Class name='RageBezier2D'>
|
||||
<Function name='destroy'/>
|
||||
<Function name='evaluate'/>
|
||||
<Function name='evaluate_y_from_x'/>
|
||||
<Function name='get_x'/>
|
||||
<Function name='get_y'/>
|
||||
<Function name='set_from_bezier'/>
|
||||
</Class>
|
||||
<Class name='RageDisplay'>
|
||||
<Function name='GetCumFPS'/>
|
||||
<Function name='GetDisplayHeight'/>
|
||||
@@ -1393,6 +1401,15 @@
|
||||
<Class name='RageInput'>
|
||||
<Function name='GetDescriptions'/>
|
||||
</Class>
|
||||
<Class name='RageQuadratic'>
|
||||
<Function name='evaluate'/>
|
||||
<Function name='get_bezier'/>
|
||||
<Function name='get_bezier_end'/>
|
||||
<Function name='get_bezier_start'/>
|
||||
<Function name='get_slope'/>
|
||||
<Function name='set_from_bezier'/>
|
||||
<Function name='set_from_cubic'/>
|
||||
</Class>
|
||||
<Class name='RageSound'>
|
||||
<Function name='get_length'/>
|
||||
<Function name='SetParam'/>
|
||||
|
||||
@@ -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.
|
||||
</Function>
|
||||
<Function name='create_bezier' return='RageBezier2D' arguments=''>
|
||||
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.
|
||||
</Function>
|
||||
<Function name='create_spline' return='CubicSplineN' arguments=''>
|
||||
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.
|
||||
</Function>
|
||||
@@ -4027,6 +4030,32 @@ save yourself some time, copy this for undocumented things:
|
||||
Returns the value of <code>rc</code> from <Link class='Steps' function='GetRadarValues' />.
|
||||
</Function>
|
||||
</Class>
|
||||
<Class name='RageBezier2D'>
|
||||
<Description>
|
||||
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.<br />
|
||||
A RageBezier2D is two RageQuadratics, one for the x coordinate and one for the y.<br />
|
||||
This class is provided as a tool for designers working with bezier tweens who need a tool that displays the tween curve visually.<br />
|
||||
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.
|
||||
</Description>
|
||||
<Function name='destroy' return='' arguments=''>
|
||||
Destroys the RageBezier2D. Do not attempt to use it after it has been destroyed.
|
||||
</Function>
|
||||
<Function name='evaluate' return='float,float' arguments='float t'>
|
||||
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.
|
||||
</Function>
|
||||
<Function name='evaluate_y_from_x' return='float' arguments='float x'>
|
||||
Takes the x given and converts it to a t value, then evaluates the y quadratic with the t value and returns the result.
|
||||
</Function>
|
||||
<Function name='get_x' return='RageQuadratic' arguments=''>
|
||||
Returns the RageQuadratic used for the x component.
|
||||
</Function>
|
||||
<Function name='get_y' return='RageQuadratic' arguments=''>
|
||||
Returns the RageQuadratic used for the y component.
|
||||
</Function>
|
||||
<Function name='set_from_bezier' return='' arguments='float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd'>
|
||||
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.
|
||||
</Function>
|
||||
</Class>
|
||||
<Class name='RageDisplay'>
|
||||
<Function name='GetDisplayHeight' return='int' arguments=''>
|
||||
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.
|
||||
</Function>
|
||||
</Class>
|
||||
<Class name='RageQuadratic'>
|
||||
<Description>
|
||||
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.
|
||||
</Description>
|
||||
<Function name='evaluate' return='float' arguments='float t'>
|
||||
Evaluates the quadratic at the given t value and returns the result.
|
||||
</Function>
|
||||
<Function name='get_bezier' return='float,float,float,float' arguments=''>
|
||||
Returns the four values that form the quadratic equation. This function returns multiple values, so you must do something like this to get them:<br />
|
||||
a, b, c, d= quadratic:get_bezier()
|
||||
</Function>
|
||||
<Function name='get_bezier_end' return='float' arguments=''>
|
||||
Equivalent to evaluate(1), but faster.
|
||||
</Function>
|
||||
<Function name='get_bezier_start' return='float' arguments=''>
|
||||
Equivalent to evaluate(0), but faster.
|
||||
</Function>
|
||||
<Function name='get_slope' return='float' arguments='float t'>
|
||||
Returns the slope of the curve at the given t value.
|
||||
</Function>
|
||||
<Function name='set_from_bezier' return='' arguments='float a, float b, float c, float d'>
|
||||
Sets the four values that form the quadratic equation.
|
||||
</Function>
|
||||
<Function name='set_from_cubic' return='' arguments='float a, float b, float c, float d'>
|
||||
Sets the four values that form the quadratic equation, treating the arguments as from a cubic equation instead of as from a bezier curve.
|
||||
</Function>
|
||||
</Class>
|
||||
<Class name='RageSound'>
|
||||
<Description>
|
||||
See <Link class='ActorSound' /> for loading a sound.
|
||||
|
||||
@@ -729,6 +729,119 @@ void RageBezier2D::SetFromBezier(
|
||||
m_Y.SetFromBezier( fC1Y, fC2Y, fC3Y, fC4Y );
|
||||
}
|
||||
|
||||
#include "LuaBinding.h"
|
||||
|
||||
struct LunaRageQuadratic : Luna<RageQuadratic>
|
||||
{
|
||||
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<RageBezier2D>
|
||||
{
|
||||
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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user