Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Tuesday, 2 February 2010

The Best of Both Worlds (combining PeasyCam and control_panel

This ruby processing sketch shows how to get the best of both worlds; the smooth easily setup PeasyCam, that you can use the scroll-wheel to zoom, and mouse to drag, and the possible fine grain control of a control panel. In this example I have initially disabled mouse control; use the button to toggle mouse control on or off. Use the control panel slider to set off the rotation or the freeze! button (to stop the rotation). If you only want fine grain rotation (cf. continuous rotation with the slider) then you will need get the camera to remember state (I believe Quark has done this in vanilla processing). If you are really keen you could also implement a slider to control the zoom of the peasy cam (in place of the mouse-wheel).

load_libraries 'PeasyCam', 'control_panel'
import 'peasy'

attr_reader :cam, :x_rotate, :y_rotate, :z_rotate, :controlled

def setup()
  size(200, 200, P3D)
  @controlled = true

def configure_camera()    
  @cam = PeasyCam.new(self, 100)

def configure_panel()
  control_panel do |c|
    c.slider(:x_rotate, -1.0..1.0, 0.0)
    c.slider(:y_rotate, -1.0..1.0, 0.0)
    c.slider(:z_rotate, -1.0..1.0, 0.0)

def freeze!()
  @x_rotate = 0.0
  @y_rotate = 0.0
  @z_rotate = 0.0

def mouse_control()     # toggle mouse controlled camera
  @controlled = !controlled

def draw()
  fill(255, 0, 0)
  translate(0, 0, 20)
  fill(0, 0, 255)

No comments:

Post a Comment


About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby- and processing-3.2.2