Module: DefaultScene
- Included in:
- Scene
- Defined in:
- lib/scene/default_scene.rb
Instance Method Summary collapse
- #display ⇒ Object
- #keyboard(key, x, y) ⇒ Object
- #mouse(button, state, x, y) ⇒ Object
- #reshape(width, height) ⇒ Object
- #timer(elapsed) ⇒ Object
Instance Method Details
#display ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/scene/default_scene.rb', line 3 def display right, left = -1, 1 bottom, top = -1, 1 front, back = -1, 1 lbf = [left, bottom, front] lbb = [left, bottom, back] ltf = [left, top, front] ltb = [left, top, back] rbf = [right, bottom, front] rbb = [right, bottom, back] rtf = [right, top, front] rtb = [right, top, back] right = [rbf, rbb, rtb, rtf] left = [lbf, ltf, ltb, lbb] bottom = [lbf, lbb, rbb, rbf] top = [ltf, rtf, rtb, ltb] front = [lbf, rbf, rtf, ltf] back = [lbb, ltb, rtb, rbb] glLineWidth(5) [right, left, bottom, top, front, back].each do |face| glBegin(GL_POLYGON) face.each do |vertex| color = vertex glColor3f(*color) glVertex3f(*vertex) end glEnd if @show_outline @outline ||= [rand, rand, rand] glColor3f(*@outline) glBegin(GL_LINE_LOOP) face.each { |v| glVertex3f(*v) } glEnd end end end |
#keyboard(key, x, y) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/scene/default_scene.rb', line 57 def keyboard(key, x, y) case key when 'q' exit(0) when 'h' puts puts 'H : Display help' puts 'Q : Quit' puts 'O : Toggle outline' puts 'Left click : Inverse x-rotation' puts 'Middle click : Inverse y-rotation' puts 'Right click : Inverse z-rotation' puts puts 'Visit https://github.com/tuzz/scene for more information' when 'o' @show_outline = !@show_outline end end |
#mouse(button, state, x, y) ⇒ Object
76 77 78 79 |
# File 'lib/scene/default_scene.rb', line 76 def mouse(, state, x, y) return unless state == GLUT_DOWN @axes[] *= -1 end |
#reshape(width, height) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/scene/default_scene.rb', line 81 def reshape(width, height) min = [width, height].min x = (width - min) / 2 y = (height - min) / 2 glViewport(x, y, min, min) end |
#timer(elapsed) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/scene/default_scene.rb', line 44 def timer(elapsed) @show_outline = true if @show_outline.nil? @axes ||= [1, 1, 1] glRotatef(elapsed * 60, *@axes) @counter ||= 0 @counter += 1 if @counter == 100 @outline = [rand, rand, rand] @counter = 0 end end |