For my 3D context free application/library, I would like to be able to zoom using the mouse wheel, I had vaguely thought about using peasycam or proscene to provide that, and other functionality. In the first instance I wanted to create it myself. After a bit of research, this the sort of implementation I would do using the java classes/interfaces in ruby:-
# mouse_listener.rb
class JWheelListener
include java.awt.event.MouseWheelListener
attr_reader :zoom
def initialize(zoom)
@zoom = zoom
end
def mouse_wheel_moved(e)
@zoom += e.get_wheel_rotation * 10
end
end
class Mouse < Processing::App
attr_reader :wheel
def setup
size(1000, 1000)
@wheel = JWheelListener.new(10)
self.add_mouse_wheel_listener(@wheel)
end
def draw
background 0
fill 255, 0, 0
ellipse(width/2, height/2, wheel.zoom, wheel.zoom)
end
end
Mouse.new :title => "Mouse Wheel Listener"
No comments:
Post a Comment