Request: interpolation

Discussion and feedback on Construct 2

» Sun Feb 24, 2013 12:38 am

@Ashley - something I've been missing a lot is the cosp, qarp and cubic expressions from CC. I had an idea though that could be even better, but I don't know if it would work - an expression like interp that would take is many parameters as you give it for as many points of interpolation wanted.

So interp(a,b,c) would be cosp, interp(a,b,c,d) would be qarp, interp(a,b,c,d,e) would be cubic, and anything past that would get you extra points, such as interp(a,b,c,d,e,f) would be five point interpolation.

Could this be done? There have been a bunch of times I've wanted interpolation past 4 points, and this would allow as many points as the user wants without needing a separate expression for each one.
Moderator
B
89
S
32
G
33
Posts: 3,005
Reputation: 27,467

» Sun Feb 24, 2013 12:51 am

I guess you're essentially asking for a spline algorithm. I suppose it would be possible.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,440

» Sun Feb 24, 2013 1:19 am

I asked this question waaaay back when CC was first started, and the answer was a no. The problem is that once you get past a third point it tends to complicate things almost exponentially.
I've been wondering why we didn't get a cosp. Could be that even that is a bit too much for the jscript.
B
163
S
48
G
99
Posts: 7,435
Reputation: 71,492

» Sun Feb 24, 2013 4:07 am

The real question would be do you need interpolation or is approximation sufficient? Interpolation would indeed be quite expensive for a large number of control points. With approximation, however, you'd be able to string together several cubic b-splines for as many points as you'd like with relative ease.
B
14
S
1
Posts: 10
Reputation: 1,375

» Sun Feb 24, 2013 5:17 am

It depends on the accuracy of the approximation, I suppose. I'm not familiar with approximation techniques in this circumstance so I don't know if they are sufficient or even if the level of fidelity of the approximation can be varied.

I'm trying to recreate the effects shown in this video of the bouncing and flying enemies as well as the trajectory of the boomerang, all of which I used cosp/qarp and cubic for originally.

Cosp at least can't be that intensive, as Mipey's extra expressions plugin has it and it works fine, even on mobile.Arima2013-02-24 05:19:02
Moderator
B
89
S
32
G
33
Posts: 3,005
Reputation: 27,467

» Sun Feb 24, 2013 11:40 am

Wow, people are still using the extra expressions plugin?

There is EaseTween behavior, which contains numerous interpolation methods, but it's more for tweening purposes. Figure you could use it for boomerang pathing, just keep the start and exit angles in mind.

Would be great if there was a way to insert such functions into a project, the plugin SDK is an awkward way. Not everyone can churn plugins out like a certain rex!
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

» Sun Feb 24, 2013 1:46 pm

After looking into lerp and playing with its parameters for a while I believe that you can get all the results that you need just from it.

For example for ease-out you use:
lerp(start, finish, time_counter ^ 2)

For ease-in you use:
lerp(start, finish, time_counter ^ 0.5)

You just need to make sure that:
1) your time_counter starts in 0
2) you increment it by some amount depending on how fast you want the movement to be (0.1 each tick its a fairly fast movement, so I normally use 0.05)
3) your end condition is always time_counter = 1 (or greater).

Finally, if you you you are looking for a higher-level solution you could always use the tween plugin as already suggested.

I really like the art style of your game. Hope this was helpful :)Alcemon2013-02-24 13:47:15
B
19
S
4
G
4
Posts: 71
Reputation: 3,898

» Sun Feb 24, 2013 3:31 pm

I'm sorry to cut you guys discussion off , but could I know how those commands could be used ?

B
35
S
16
G
16
Posts: 2,223
Reputation: 16,591

» Sun Feb 24, 2013 8:17 pm

You can implement them in events with the function object. Here are the formulas:
qarp(a, b, c, t) = lerp(lerp(a,b,t), lerp(b,c,t), t)
cubic(a, b, c, d, t) = lerp(qarp(a,b,c,t), qarp(b,c,d,t), t)
cosp(a, b, t) = (a+b+(a-b)*cos(t*180))/2

For interpolation with any number of parameters wikipedia has the math here:http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Generalization

@Whiteclaws
They are for smooth transitions from one value to another. Cubic and qarp can be used to define a curved path or to do ease in/out effects.
B
82
S
26
G
62
Posts: 4,824
Reputation: 45,188

» Sun Feb 24, 2013 8:24 pm

Lerp , ain't it ?
B
35
S
16
G
16
Posts: 2,223
Reputation: 16,591

Next