Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid object implementation is incomplete #130

Open
jo3w4rd opened this issue Dec 16, 2013 · 0 comments
Open

Invalid object implementation is incomplete #130

jo3w4rd opened this issue Dec 16, 2013 · 0 comments
Assignees

Comments

@jo3w4rd
Copy link
Contributor

jo3w4rd commented Dec 16, 2013

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:

 if(controller.frame(f).pointable(pointableID).valid) Leap.vec3.add(averageVelocity, velocity, averageVelocity);

(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.

@ghost ghost assigned bingomanatee Jan 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants