Ruby-Processing Exemplo de Modelo 3D com Drag
O exemplo abaixo ilustra uma aplicação no modelo 3D com drag, usando Ruby-Processing.
Para esse exemplo funcionar você deve possuir o Ruby-Processing instalado, caso não possua siga os passos: http://blog.patrickespake.com/2009/08/23/ruby-processing.
Exemplo Modelo 3D com Drag
1 2 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | class Teste3d < Processing::App attr_accessor :rotx, :roty, :tex, :bg def setup size 800, 600, P3D self.bg = load_image "candy.jpg" self.tex = load_image "smile.jpg" texture_mode NORMALIZED fill 255 stroke(color(44, 48, 32)) self.rotx = PI/4 self.roty = PI/4 end def draw background self.bg no_stroke translate width/2.0, height/2.0, -100 rotate_x self.rotx rotate_y self.roty scale 90 texture_cube self.tex end def mouse_dragged rate = 0.01 self.rotx += (pmouse_y - mouse_y) * rate self.roty += (mouse_x - pmouse_x) * rate end private def texture_cube(tex) begin_shape QUADS texture tex # +Z "front" face vertex(-1, -1, 1, 0, 0) vertex( 1, -1, 1, 1, 0) vertex( 1, 1, 1, 1, 1) vertex(-1, 1, 1, 0, 1) # -Z "back" face vertex( 1, -1, -1, 0, 0) vertex(-1, -1, -1, 1, 0) vertex(-1, 1, -1, 1, 1) vertex( 1, 1, -1, 0, 1) # +Y "bottom" face vertex(-1, 1, 1, 0, 0) vertex( 1, 1, 1, 1, 0) vertex( 1, 1, -1, 1, 1) vertex(-1, 1, -1, 0, 1) # -Y "top" face vertex(-1, -1, -1, 0, 0) vertex( 1, -1, -1, 1, 0) vertex( 1, -1, 1, 1, 1) vertex(-1, -1, 1, 0, 1) # +X "right" face vertex( 1, -1, 1, 0, 0) vertex( 1, -1, -1, 1, 0) vertex( 1, 1, -1, 1, 1) vertex( 1, 1, 1, 0, 1) # -X "left" face vertex(-1, -1, -1, 0, 0) vertex(-1, -1, 1, 1, 0) vertex(-1, 1, 1, 1, 1) vertex(-1, 1, -1, 0, 1) end_shape end end Teste3d.new :title => "Teste 3D" |
Esse exemplo gera um cubo em 3D, quando você clica e faz drag o cubo se movimenta.
Executando
No terminal digite:
rp5 run teste_3d.rb
Resultado

Você pode ver esse exemplo em execução no endereço: http://lab.patrickespake.com/ruby-processing-examples/example_3d_drag/run/. Você precisa ter paciência para visualizar o modelo rodando, ele demora um certo tempo para carregar no browser.
Código fonte completo: http://github.com/patrickespake/ruby-processing-examples/tree/c80a080dd1e27a562b252fa01bc1030d924a9f47/example_3d_drag.
Se você gostou desse texto e acha que ajudou você, me recomende:
.