# Request: interpolation

Discussion and feedback on Construct 2

### » Sun Feb 24, 2013 8:24 pm

Lerp , ain't it ?
B
43
S
18
G
17
Posts: 2,247
Reputation: 17,556

### » Mon Feb 25, 2013 4:21 pm

Thanks for the help guys, I'll look into the alternatives you posted if it doesn't get implemented.
Moderator
B
96
S
34
G
33
Posts: 3,007
Reputation: 27,911

### » Wed Jul 17, 2013 10:29 am

These would still be great to have, especially since Classic had them!
B
162
S
80
G
22
Posts: 1,808
Reputation: 24,585

### » Fri May 16, 2014 3:09 am

R0J0hound wrote: 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

thanks @R0J0hound

When I've use lerp to move sprites it seems to have built in "slow down" toward the end which is great. If I wanted this "slow down" at the beginning and the ending would I use qarp? (or your lerp(lerp(a,b,t), lerp(b,c,t), t)). I tried it when zooming out the layout and it doesn't seem to work like I expected...still feels like a regular old lerp.. since it starts zooming fast then gradually slows.

Code: Select all
`Set Layout scale to lerp(lerp(LayoutScale,1,0.5*dt), lerp(1,4,0.5*dt), 0.5*dt)           `

a=LayoutScale (which starts at 1.3)
b=1
c=4 (wasn't sure how steep to make the curve)
t=0.5*dt
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Fri May 16, 2014 2:21 pm

jobel wrote:
R0J0hound wrote: 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

thanks @R0J0hound

When I've use lerp to move sprites it seems to have built in "slow down" toward the end which is great. If I wanted this "slow down" at the beginning and the ending would I use qarp? (or your lerp(lerp(a,b,t), lerp(b,c,t), t)). I tried it when zooming out the layout and it doesn't seem to work like I expected...still feels like a regular old lerp.. since it starts zooming fast then gradually slows.

Code: Select all
`Set Layout scale to lerp(lerp(LayoutScale,1,0.5*dt), lerp(1,4,0.5*dt), 0.5*dt)           `

a=LayoutScale (which starts at 1.3)
b=1
c=4 (wasn't sure how steep to make the curve)
t=0.5*dt

The "built in slowdown" comes from the use of lerp you are using, a is the variant in your case, so you have a "suite arithmétique" (not sure of the english term for that), that will go slower and slower towards the point. (it shouldn't even reach it, I never understood why people are using lerp like this)

To be exact, lerp(a, b, x) return the value between a and b, corresponding to the percentage (reminder of math: 1 = 100%) x, from a to b

lerp(a,b, 0) will return a, lerp(a, b, 1) will return b, lerp(a, b, 0.5) will return (a+b)/2.

The intended use is to make x varie (generally from 0 to 1, but it can go over that), for your zoom, you can have lerp(min value, max value, zoom percentage), and make the zoom percentage varying from 0 to 1 or 1 to 0 as you want it.

The qarp will be the same logic, but applied not in a linear fashion (a quadratic one, which I think means that a and c will be min and max, but b will be affecting the way it evolves with each values of t)

qarp (a, b, c, 0) will return a, qarp(a, b, c, 1) will return c, qarp (a, b, c, 0.5) will return ((a+b)/2+(b+c)/2)/2 = ((a+c)/2+b)/2 I think
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Previous