Perl meets Leap Motion

7a8922191c1fa60728589a3def4c179f?s=47 akiym
August 31, 2013

Perl meets Leap Motion

Hokkaido.pm #10

7a8922191c1fa60728589a3def4c179f?s=128

akiym

August 31, 2013
Tweet

Transcript

  1. 1FSMNFFUT -FBQ.PUJPO !BLJZN )PLLBJEPQN

  2. NF w!BLJZN wେֶੜ wઌ೔ηΩϡϦςΟΩϟϯϓʹࢀՃ ͖ͯ͠·ͨ͠ w:"1$"TJBͰ͸ʮ)FSPLVͰֶͿɺॳΊ ͯͷ1FSMʯͱ͍͏࿩Λ͠·͢

  3. ࠷ۙ͸͜Μͳ΋ͷΛ ࡞ͬͯ·͢

  4. DUGLBUTVEPOPSH

  5. -FBQ.PUJPO w࣍ੈ୅σόΠε wखͷͻΒɺࢦΛࡉ͔͘ೝࣝ w8FC4PDLFUͰσʔλΛऔͬͯ͘Δ͜ͱ ͕Ͱ͖Δ

  6. 1FSM͔Β-FBQ.PUJPOΛѻ͏

  7. %FWJDF-FBQ wIUUQTNFUBDQBOPSHNPEVMF %FWJDF-FBQ wͱΓ͋͑ͣॻ͍ͨײ wδΣενϟʔ͕औΕͳ͍

  8. my($LEAP_HANDLE); # After connection, this contains our websocket handle my($SEND);

    # Data to send, when other end is ready for it my($BUFF)=''; # Buffer in case calling script misses a few events sub Leap { my $ret; if($BUFF eq '') { # Nothing in the buffer - try to get some more unless($LEAP_HANDLE) { # Establish a new connection # Make the socket socket($LEAP_HANDLE, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || return (\{'error' => "socket: $!"}); # Don't let stuff like UTF-style characters get screwed up binmode($LEAP_HANDLE) || return (\{'error' =>,"binmode(socket handle): $!"}); # Allow more than one connection setsockopt($LEAP_HANDLE, SOL_SOCKET, SO_REUSEADDR, 1) || return (\{'error' =>,"SO_REUSEADDR: $!"}); # Don't block on close (Remember not to close it until we've sent everything we want):- if($^O =~/Win32/i) { setsockopt($LEAP_HANDLE, SOL_SOCKET, SO_DONTLINGER, 1) || return (\{'error' =>,"SO_DONTLINGER: $!"}); } vec($bitsr,fileno($LEAP_HANDLE),1)=1; # This tells select() which socket we want to query vec($null,fileno($LEAP_HANDLE),1)=0; if(defined $SEND) {$bitsw=$bitsr} else {$bitsw=$null} # We only care about write-status if we've got data to write
  9. use Device::Leap; while(1) { $d=&Leap(); next unless(ref $d); # no

    new data print $d->{hands}->[0]->{sphereRadius} . "\n"; # print some }
  10. 

  11. wॻ͖௚ͨ͠ w"OZ&WFOU-FBQ.PUJPO wͨͩ8FC4PDLFUͰ௨৴͍ͯ͠Δ͚ͩ

  12. my $leap = AnyEvent::LeapMotion->new( enable_gesture => 1, on_frame => sub

    { my $frame = shift; ... }, ); $leap->run; AE::cv->recv;
  13.  BJSQPJOUFS

  14. wϚ΢ε w049ͰϚ΢εΛίϯτϩʔϧ͢Δํ๏ w8JOEPXTͳΒ8JO(VJ5FTU w049ͳΒʜʁ

  15. ॻ͍ͨ ͪΐͬͱ͚ͩ

  16. $PDPB(VJ5FTU wΈΜͳେ޷͖$PDPBϞδϡʔϧ wϚ΢εΛಈ͔͢ɺΩʔೖྗ wෆ҆ఆ

  17. $PDPB(VJ5FTUͷσϞ wςΩετΤσΟλ Ωʔૢ࡞ w೾ wάϧάϧඳ͘

  18. ·ͱΊ w1FSM͔Β-FBQ.PUJPOΛѻͬͯΈ·ͨ͠ wເɺ޿͕ͬͯ·͢ w$PDPBϞδϡʔϧ͕·ͩ·ͩগͳ͍