This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Neurogami | |
module Leap | |
class BasicListener < LeapMotion::Listener | |
def onInit controller | |
puts "#{self.inspect} Initialized with #{controller.inspect}" | |
end | |
def onConnect controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This goes into the module Neurogami::Leap | |
class Controller < LeapMotion::Controller | |
end | |
class Vector < LeapMotion::Vector | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Java::ComLeapmotionLeap::Frame | |
alias_method :leap_hands, :hands | |
def hands | |
leap_hands.to_a | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example JRuby LeapMotion program based on the Java example included in the Leap Motion SDK. | |
# | |
$:.unshift './jleap-ng' | |
require 'jleap-ng' | |
include Neurogami::Leap | |
class ExampleListener < BasicListener | |
def onInit controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def onFrame controller | |
frame = controller.frame | |
puts "Frame id: #{ frame.id}, timestamp: #{frame.timestamp}, hands: #{frame.hands.count}, fingers: #{frame.fingers.count} , tools: #{frame.tools.count}" | |
if !frame.hands.empty? | |
hand = frame.hands[0] | |
fingers = hand.fingers | |
if !fingers.empty? | |
# Calculate the hand's average finger tip position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example | |
def initialize | |
listener = ExampleListener.new | |
controller = Controller.new | |
controller.add_listener listener | |
warn "Press Enter to quit..." | |
begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Thread.abort_on_exception = true # Might want to reserve this option for what code is using this library | |
require 'em-websocket' | |
require 'json' | |
class SocketServer | |
def initialize port = 8090, host = '127.0.0.1' | |
@port = port | |
@host = host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Java::ComLeapmotionLeap::Hand | |
alias_method :leap_fingers, :fingers | |
def fingers | |
leap_fingers.to_a | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adjust as needed to get the libraries loaded | |
$:.unshift '.' | |
$:.unshift './jleap-ng' | |
require 'jleap-ng' | |
require 'web-socket-server' | |
require 'game-demo-handlers' | |
require 'json' | |
require 'osc-ruby' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The idea is that you Listener class gets an array of ConditionHandler objects and | |
# in onFrame loops over them, invoking `run` on each one | |
class ConditionHandler | |
def initialize &contitions_block | |
@conditions = contitions_block | |
end | |
def run frame | |
@conditions.call frame | |
end |