Moved note column splines into tween state. Renamed size/dimension spline lua functions to get/set convention. Added make_camel_aliases to 01 alias.lua to make the CamelCase aliases required by shakesoda for consistency.
This commit is contained in:
+115
-10
@@ -494,7 +494,7 @@ void CubicSpline::set_coefficients(size_t i, float b, float c, float d)
|
||||
m_points[i].d= d;
|
||||
}
|
||||
|
||||
void CubicSpline::get_coefficients(size_t i, float& b, float& c, float& d)
|
||||
void CubicSpline::get_coefficients(size_t i, float& b, float& c, float& d) const
|
||||
{
|
||||
ASSERT_M(i < m_points.size(), "CubicSpline: point index must be less than the number of points.");
|
||||
b= m_points[i].b;
|
||||
@@ -502,6 +502,20 @@ void CubicSpline::get_coefficients(size_t i, float& b, float& c, float& d)
|
||||
d= m_points[i].d;
|
||||
}
|
||||
|
||||
void CubicSpline::set_point_and_coefficients(size_t i, float a, float b,
|
||||
float c, float d)
|
||||
{
|
||||
set_coefficients(i, b, c, d);
|
||||
m_points[i].a= a;
|
||||
}
|
||||
|
||||
void CubicSpline::get_point_and_coefficients(size_t i, float& a, float& b,
|
||||
float& c, float& d) const
|
||||
{
|
||||
get_coefficients(i, b, c, d);
|
||||
a= m_points[i].a;
|
||||
}
|
||||
|
||||
void CubicSpline::resize(size_t s)
|
||||
{
|
||||
m_points.resize(s);
|
||||
@@ -517,6 +531,96 @@ bool CubicSpline::empty() const
|
||||
return m_points.empty();
|
||||
}
|
||||
|
||||
void CubicSplineN::weighted_average(CubicSplineN& out,
|
||||
CubicSplineN const& from, CubicSplineN const& to, float between)
|
||||
{
|
||||
ASSERT_M(out.dimension() == from.dimension() &&
|
||||
to.dimension() == from.dimension(),
|
||||
"Cannot tween splines of different dimensions.");
|
||||
#define BOOLS_FROM_CLOSEST(closest) \
|
||||
out.set_loop(closest.get_loop()); \
|
||||
out.set_polygonal(closest.get_polygonal());
|
||||
if(between >= 0.5f)
|
||||
{
|
||||
BOOLS_FROM_CLOSEST(to);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOLS_FROM_CLOSEST(from);
|
||||
}
|
||||
#undef BOOLS_FROM_CLOSEST
|
||||
// Behavior for splines of different sizes: Use a size between the two.
|
||||
// Points that exist in both will be averaged.
|
||||
// Points that only exist in one will come only from that one.
|
||||
size_t const from_size= from.size();
|
||||
size_t const to_size= to.size();
|
||||
size_t out_size= to_size;
|
||||
size_t limit= to_size;
|
||||
if(from_size < to_size)
|
||||
{
|
||||
out_size= from_size + static_cast<size_t>(
|
||||
static_cast<float>(to_size - from_size) * between);
|
||||
}
|
||||
else if(to_size < from_size)
|
||||
{
|
||||
limit= from_size;
|
||||
out_size= to_size + static_cast<size_t>(
|
||||
static_cast<float>(from_size - to_size) * between);
|
||||
}
|
||||
CLAMP(out_size, 0, limit);
|
||||
out.resize(out_size);
|
||||
|
||||
for(size_t spli= 0; spli < out.m_splines.size(); ++spli)
|
||||
{
|
||||
for(size_t p= 0; p < out_size; ++p)
|
||||
{
|
||||
float fc[4]= {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
float tc[4]= {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
if(p < from_size)
|
||||
{
|
||||
from.m_splines[spli].get_point_and_coefficients(p, fc[0], fc[1],
|
||||
fc[2], fc[3]);
|
||||
}
|
||||
if(p < to_size)
|
||||
{
|
||||
to.m_splines[spli].get_point_and_coefficients(p, tc[0], tc[1],
|
||||
tc[2], tc[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i= 0; i < 4; ++i)
|
||||
{
|
||||
tc[i]= fc[i];
|
||||
}
|
||||
}
|
||||
if(p >= from_size)
|
||||
{
|
||||
for(int i= 0; i < 4; ++i)
|
||||
{
|
||||
fc[i]= tc[i];
|
||||
}
|
||||
}
|
||||
float oc[4]= {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
for(int i= 0; i < 4; ++i)
|
||||
{
|
||||
oc[i]= lerp(between, fc[i], tc[i]);
|
||||
}
|
||||
out.m_splines[spli].set_point_and_coefficients(p, oc[0], oc[1], oc[2],
|
||||
oc[3]);
|
||||
}
|
||||
}
|
||||
// The spline is not solved after averaging because my testing showed that
|
||||
// it is unnecessary.
|
||||
// My testing method was this:
|
||||
// Spline A is generated by lerping all points and coefficients.
|
||||
// Spline B is generated by lerping all points then solving.
|
||||
// The coefficients for Spline A and Spline B are identical to 5 to 9
|
||||
// significant digits. Thus, solving is unnecessary.
|
||||
// Additionally, solving would require a mechanism to disable solving for
|
||||
// the people that wish to set their own coefficients instead of solving.
|
||||
// -Kyz
|
||||
}
|
||||
|
||||
void CubicSplineN::solve()
|
||||
{
|
||||
if(!m_dirty) { return; }
|
||||
@@ -655,7 +759,7 @@ void CubicSplineN::set_##name(bool b) \
|
||||
m_dirty= true; \
|
||||
member= b; \
|
||||
} \
|
||||
bool CubicSplineN::get_##name() \
|
||||
bool CubicSplineN::get_##name() const \
|
||||
{ \
|
||||
return member; \
|
||||
}
|
||||
@@ -728,6 +832,7 @@ struct LunaCubicSplineN : Luna<CubicSplineN>
|
||||
{
|
||||
ret.push_back(0.0f);
|
||||
}
|
||||
ret.resize(limit);
|
||||
}
|
||||
static void set_point_from_stack(T* p, lua_State* L, size_t i, int s)
|
||||
{
|
||||
@@ -802,7 +907,7 @@ struct LunaCubicSplineN : Luna<CubicSplineN>
|
||||
lua_pushnumber(L, p->size() - 1 + p->get_loop());
|
||||
return 1;
|
||||
}
|
||||
static int resize(T* p, lua_State* L)
|
||||
static int set_size(T* p, lua_State* L)
|
||||
{
|
||||
int siz= IArg(1);
|
||||
if(siz < 0)
|
||||
@@ -812,12 +917,12 @@ struct LunaCubicSplineN : Luna<CubicSplineN>
|
||||
p->resize(static_cast<size_t>(siz));
|
||||
COMMON_RETURN_SELF;
|
||||
}
|
||||
static int size(T* p, lua_State* L)
|
||||
static int get_size(T* p, lua_State* L)
|
||||
{
|
||||
lua_pushnumber(L, p->size());
|
||||
return 1;
|
||||
}
|
||||
static int redimension(T* p, lua_State* L)
|
||||
static int set_dimension(T* p, lua_State* L)
|
||||
{
|
||||
if(p->m_owned_by_actor)
|
||||
{
|
||||
@@ -832,7 +937,7 @@ struct LunaCubicSplineN : Luna<CubicSplineN>
|
||||
p->redimension(static_cast<size_t>(dim));
|
||||
COMMON_RETURN_SELF;
|
||||
}
|
||||
static int dimension(T* p, lua_State* L)
|
||||
static int get_dimension(T* p, lua_State* L)
|
||||
{
|
||||
lua_pushnumber(L, p->dimension());
|
||||
return 1;
|
||||
@@ -880,10 +985,10 @@ struct LunaCubicSplineN : Luna<CubicSplineN>
|
||||
ADD_METHOD(set_spatial_extent);
|
||||
ADD_METHOD(get_spatial_extent);
|
||||
ADD_METHOD(get_max_t);
|
||||
ADD_METHOD(resize);
|
||||
ADD_METHOD(size);
|
||||
ADD_METHOD(redimension);
|
||||
ADD_METHOD(dimension);
|
||||
ADD_METHOD(set_size);
|
||||
ADD_METHOD(get_size);
|
||||
ADD_METHOD(set_dimension);
|
||||
ADD_METHOD(get_dimension);
|
||||
ADD_METHOD(empty);
|
||||
ADD_METHOD(set_loop);
|
||||
ADD_METHOD(get_loop);
|
||||
|
||||
Reference in New Issue
Block a user