heh65532 said:
only call I know to work is the ToArcs() wish there was documentation for this thing somewhere ?
In case API restrictions gives you problems it's easy to do this spline stuff yourself.
Here's what i have for quadratic bezier (it's 1D, but just replace float s with 2D vectors):
inline void EvaluateBezier3 (float &pos, float &tang, float cp1, float cp2, float cp3, float t)
{
float u = 1.0f - t;
float vv = u*u;
float vu = u*t*2;
float uu = t*t;
pos = vv * cp1;
pos += vu * cp2;
pos += uu * cp3;
// tangent...
tang = 1-2*t, cp2;
tang += t, cp3;
tang += -u, cp1;
}
Not sure if i use this anywhere, so i hope it's not buggy.
Here's cubic bezier:
inline void EvaluateBezier4 (sVec3 &pos, sVec3 &tang, sVec3 cp1, sVec3 cp2, sVec3 cp3, sVec3 cp4, float t)
{
float u = 1.0f - t;
float vvv = u*u*u;
float vvu = u*u*t*3;
float vuu = u*t*t*3;
float uuu = t*t*t;
pos = vvv * cp1;
pos += vvu * cp2;
pos += vuu * cp3;
pos += uuu * cp4;
// tangent...
vvv = -3*u*u; // opt
vvu = -6*u*t + 3*u*u;
vuu = 6*u*t - 3*t*t;
uuu = 3*t*t;
tang = vvv * cp1;
tang += vvu * cp2;
tang += vuu * cp3;
tang += uuu * cp4;
}
And Catmull Rom:
inline sVec3 CatmullRom3D (const float t, const sVec3 k0, const sVec3 k1, const sVec3 k2, const sVec3 k3)
{
const float t2 = t * t;
const float t3 = t2 * t;
const float w0 = (2.f * t3 - 3.f * t2 + 1.f);
const float w1 = (t3 - 2.f * t2 + t) * -.5f;
const float w2 = (-2.f * t3 + 3.f * t2);
const float w3 = (t3 - t2) * .5f;
return (w0-w3) * k1 + (w2-w1) * k2 + w1 * k0 + w3 * k3;
}
inline sVec3 CatmullRom3DTangent (const float t, const sVec3 k0, const sVec3 k1, const sVec3 k2, const sVec3 k3)
{
const float t2 = t * t;
const float w0 = ( 6.f * t2 - 6.f * t);
const float w1 = ( 3.f * t2 - 4.f * t + 1.f) * -.5f;
const float w2 = (-6.f * t2 + 6.f * t);
const float w3 = ( 3.f * t2 - 2.f * t) * .5f;
return (w0-w3) * k1 + (w2-w1) * k2 + w1 * k0 + w3 * k3;
}
My proposal of automated interior control points setup for cubic bezier gives the exact same result as using Catmull Rom, i'm pretty sure.
So if you end up at that, being happy with the shapes, you could just use Catmull Rom where no interior control points are needed at all.
The tangent is very useful, as it gives the velocity on any point of the curve. It would help to orient an object following a spline path for example.