You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The concept of the Invalid object is that you can always access a property multiple steps down the model hierarchy without running into undefined object errors. Invalid objects are fully formed, but have 0 or identity property values (as appropriate).
For example, if I am averaging the velocity of a finger over the last 100 frames, the following should work, even if there aren't 100 frames in the history cache, or if some of those frames don't include a finger with the specified ID:
<p>Average V: <span id="av">…</span></p>
<script>
var outputDisplay = document.getElementById("av");
var controller = new Leap.Controller();
controller.on('frame', function(frame){
var averageVelocity = Leap.vec3.create();
var count = 0;
if(frame.pointables.length > 0)
{
var pointableID = frame.pointables[0].id;
for( f = 0; f < 100; f++)
{
var velocity = controller.frame(f).pointable(pointableID).tipVelocity;
Leap.vec3.add(averageVelocity, velocity, averageVelocity);
count++;
}
}
if(count > 0) Leap.vec3.scale(averageVelocity,averageVelocity, 1/count);
outputDisplay.innerText = "(" + averageVelocity[0].toFixed(2) + ", "
+ averageVelocity[1].toFixed(2) + ", "
+ averageVelocity[2].toFixed(2) + ")";
});
controller.connect();
However, I have to check whether the pointable is valid or the velocity is undefined:
The concept of the Invalid object is that you can always access a property multiple steps down the model hierarchy without running into undefined object errors. Invalid objects are fully formed, but have 0 or identity property values (as appropriate).
For example, if I am averaging the velocity of a finger over the last 100 frames, the following should work, even if there aren't 100 frames in the history cache, or if some of those frames don't include a finger with the specified ID:
However, I have to check whether the pointable is valid or the velocity is undefined:
(Yes, this is a contrived example, since I would only want to average valid pointables, but it does illustrate the issue.)
The incomplete implementation exists in the Pointables class, but may also be the case in other classes as well.
The text was updated successfully, but these errors were encountered: