*With the sample size set to 50, motion is super fluid…but ridiculously laggy :)*

Here is a really hacky function i put together to test out the lag i was experiencing with the Z axis, but i thought i would apply it to all the currently tracked fingers.

There are 3 public variables:

previosFrame

Has all the data from the leap motion controller

rawFrameData

Is a FILO Stack of finger data from each previous frame

stableFrameData

Is an array of [x,y,z] data for each finger. This is used as the stabilized tracking data **instead of** fingers[xx].stabilizedTipPosition[x,y,z]

By setting the

numberOfSamples

Variable you can set the super sampling size. 5-8 is pretty smooth. 10-20 is laggy but very smooth. 50 is ridiculously fun! as demonstrated in the video.

function stabilize()
{
if(previousFrame.hands.length)
{
var numberOfSamples = 8;
if(rawFrameData.length<numberOfSamples)
{
rawFrameData.push( previousFrame.hands[0].fingers );
}
else
{
rawFrameData.splice(0,1);
rawFrameData.push( previousFrame.hands[0].fingers );
}
stableFrameData = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]];
for(rawFrameCnt=0; rawFrameCnt<rawFrameData.length; rawFrameCnt++)
{
stableFrameData[0][0]+=rawFrameData[rawFrameCnt][0].tipPosition[0];
stableFrameData[0][1]+=rawFrameData[rawFrameCnt][0].tipPosition[1];
stableFrameData[0][2]+=rawFrameData[rawFrameCnt][0].tipPosition[2];
stableFrameData[1][0]+=rawFrameData[rawFrameCnt][1].tipPosition[0];
stableFrameData[1][1]+=rawFrameData[rawFrameCnt][1].tipPosition[1];
stableFrameData[1][2]+=rawFrameData[rawFrameCnt][1].tipPosition[2];
stableFrameData[2][0]+=rawFrameData[rawFrameCnt][2].tipPosition[0];
stableFrameData[2][1]+=rawFrameData[rawFrameCnt][2].tipPosition[1];
stableFrameData[2][2]+=rawFrameData[rawFrameCnt][2].tipPosition[2];
stableFrameData[3][0]+=rawFrameData[rawFrameCnt][3].tipPosition[0];
stableFrameData[3][1]+=rawFrameData[rawFrameCnt][3].tipPosition[1];
stableFrameData[3][2]+=rawFrameData[rawFrameCnt][3].tipPosition[2];
stableFrameData[4][0]+=rawFrameData[rawFrameCnt][4].tipPosition[0];
stableFrameData[4][1]+=rawFrameData[rawFrameCnt][4].tipPosition[1];
stableFrameData[4][2]+=rawFrameData[rawFrameCnt][4].tipPosition[2];
}
for(rawFrameCnt=0; rawFrameCnt<stableFrameData.length; rawFrameCnt++)
{
stableFrameData[rawFrameCnt][0]=stableFrameData[rawFrameCnt][0]/rawFrameData.length;
stableFrameData[rawFrameCnt][1]=stableFrameData[rawFrameCnt][1]/rawFrameData.length;
stableFrameData[rawFrameCnt][2]=stableFrameData[rawFrameCnt][2]/rawFrameData.length;
}
}
}