• Create Account

### #ActualKhatharr

Posted 15 February 2013 - 10:02 PM

You could consider each frame to be 'destination - 4n' where n is the frame number, beginning at 8 and reducing to zero. I separated the operations in the code in order to calculate the offset first and then apply it to the correct axis in the correct direction.

The whole idea behind interpolation is:

now = start + (total_change * current_frame / total_frames)

start -> starting value
total_change -> 'start + total_change' would equal the end value
current_frame -> starts at zero and increases by 1 each frame
total_frames -> the number of frames over which the process should take place

I just did it 'backwards' by subtracting from the destination rather than adding to the origin. The result is the same either way, but I prefer the 'backwards' method for this case because it means that at the end of the process no correction is required and it allows the test 'if(pendingMotionFrames == 0)', which simplifies the logic a little bit.

The core idea behind the math is that you're multiplying the change by the fraction 'cur_frame/total_frames'. So if half the motion is done it would be:

now = start + (total_change * 1/2)

Half of the change is applied.

### #2Khatharr

Posted 15 February 2013 - 09:59 PM

You could consider each frame to be 'destination - 4n' where n is the frame number, beginning at 8 and reducing to zero. I separated the operations in the code in order to calculate the offset first and then apply it to the correct axis in the correct direction.

The whole idea behind interpolation is:

now = start + (total_change * current_frame / total_frames)

start -> starting value
total_change -> 'start + total_change' would equal the end value
current_frame -> starts at zero and increases by 1 each frame
total_frames -> the number of frames over which the process should take place

I just did it 'backwards' by subtracting from the destination rather than adding to the origin. The result is the same either way, but I prefer the 'backwards' method for this case because it means that at the end of the process no correction is required and it allows the test 'if(pendingMotionFrames == 0)', which simplifies the logic a little bit.

### #1Khatharr

Posted 15 February 2013 - 09:57 PM

You could consider each frame to be 'destination - 4n' where n is the frame number, beginning at 8 and reducing to zero. I separated the operations in the code in order to calculate the offset first and then apply it to the correct axis in the correct direction.

The whole idea behind interpolation is:

now = start + (finish * (current_frame/total_frames))

I just did it 'backwards' by subtracting from the destination rather than adding to the origin. The result is the same either way, but I prefer the 'backwards' method for this case because it means that at the end of the process no correction is required and it allows the test 'if(pendingMotionFrames == 0)', which simplifies the logic a little bit.

PARTNERS