Archive 17/01/2023.

Trouble with Spline

TheComet

How would you create a spline that does the following?

After I saw this topic: Splines in Urho I wanted to try and create a spline which describes a foot setting down and lifting off of the ground. Basically, something that looks like this:

I determined these key times by looking at a walk animation in the editor. I figure I could spline between Vector2’s, so I created the spline like this:

Spline sp;
sp.AddKnot(Variant(Vector2(0.29, 0.0))); // foot down
sp.AddKnot(Variant(Vector2(0.39, 1.0))); // foot on ground
sp.AddKnot(Variant(Vector2(0.81, 1.0))); // foot still on ground
sp.AddKnot(Variant(Vector2(0.91, 0.0))); // foot lift

Then I use this code to calculate the weight:

float norm = animState_.time / animState_.length;
float weight = sp.GetPoint(norm).GetVector2().y;

When I look at the weight value I’m getting something that looks like a sine wave and not the expected figure. What am I doing wrong?

Lumak

I think by definition, you will not get a square wave function out of spline. You may just have to clamp the y output:

float weight = Clamp(sp.GetPoint(norm).GetVector2().y, 0.0f, 1.0f);

slapin

Yep, you can’t get square wave form. You can use more knots to get closer though,
and use Clamp as proposed above.

TheComet

Alright, got it to work with clamp by adding more points. Thanks!

johnnycable

Have you tried this? http://cubic-bezier.com/