0
$\begingroup$

I am reverse-engineering two classes from a game. The two classes are responsible for generating sets of t values for interpolating / blending between two points through the formula:

P = P0 * (1 - t) + P1 * t

Both classes have the same interface, that is:

class CalcRatio:
    start(blend_duration)  # In frames
    calc()                 # Called once every frame

The first class is implemented as follows:

start(blend_duration):
    t = 0
    counter = 0
    inv_duration = 1 / blend_duration

calc():
    if t == 1:
        return

    counter += inv_duration
    if counter >= 1:
        t = 1
        counter = 1
        inv_duration = 0
        return

    t += inv_duration

This is very clearly plain linear interpolation where P = P0 * (1 - t) + P1 * t, t = frame / duration and frame is the current frame number since calling start(). (I do not even know why the game even needed this class.)

However, I do not understand the second class. It is implemented as follows:

start(blend_duration):
    t = 0
    counter = 0
    unk = 1
    inv_duration = 1 / blend_duration

calc():
    if unk == 0:
        return

    counter += inv_duration
    if counter >= 1:
        t = 1
        counter = 1
        unk = 0
        return

    prev_unk = unk
    unk -= prev_unk * counter * counter
    unk2 = 1 / (unk / prev_unk + (1 - unk))
    t = (1 - unk) * unk2
    # Interesting fact: 1 - t == (unk / prev_unk) * unk2

I do not understand what this is doing. The new point is still calculated as P = P0 * (1 - t) + P1 * t, but any idea what t is in terms of frame? What are unk and unk2 supposed to represent?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.