But then I had brainwave!!!
# The planetarium library is designed to create real-time projections on # spherical domes. It is based on the FullDome project by Christopher # Warnow (ch.warnow@gmx.de): # https://github.com/mphasize/FullDome # # A brief descrition on how it works: a 360° view of the scene is generated # by rendering the scene 6 times from each direction: positive x, negative x, # positive y, and so on. The output of each rendering is stored inside a cube map # texture, which is then applied on a sphere representing the dome. # Hence, the library calls the draw method 6 times per frame in order to update # the corresponding side of the cube map texture (in reality, only 5 times since # the bottom side of the cube map is not invisible on the dome). # I can't get 'pre' to work correctly on ruby processing (reflection in reverse) # so here we use mouse_released instead load_library :planetarium include_package 'codeanticode.planetarium' attr_reader :cube_x, :cube_y, :cube_z def setup # For the time being, only use square windows size(600, 600, Dome::RENDERER) @cube_x, @cube_y, @cube_z = width/2, height/2, -width/4 end # Called one time per frame when pre, or to order via mouse. def mouse_released # The dome projection is centered at (0, 0), so the mouse coordinates # need to be offset by (width/2, height/2) @cube_x += ((mouse_x - width * 0.5) - cube_x) * 0.2 @cube_y += ((mouse_y - height * 0.5) - cube_y) * 0.2 end # Called five times per frame. def draw background(0) push_matrix translate(width/2, height/2, 300) lights stroke(0) fill(150) push_matrix translate(cube_x, cube_y, cube_z) box(50) pop_matrix stroke(255) lines_amount = 10 (0 ... lines_amount).each do |i| ratio = i/(lines_amount - 1.0) line(0, 0, cos(ratio * TWO_PI) * 50, sin(ratio * TWO_PI) * 50) end pop_matrix end def key_pressed if (key == CODED) @cube_z -= 5 if (key_code == UP) @cube_z += 5 if (key_code == DOWN) end end
No comments:
Post a Comment