# TexturedCube # by Dave Bollinger. # # Drag mouse to rotate cube. Demonstrates use of u/v coords in # vertex and effect on texture(). def setup size 649, 360, P3D @rotx = PI/4 @roty = PI/4 @tex = load_image "berlin-1.jpg" texture_mode NORMAL # Changed for processing 2.0 fill 255 stroke 44, 48, 32 end def draw background 0 no_stroke translate width/2, height/2, -100 rotate_x @rotx rotate_y @roty scale 90 texture_cube end def texture_cube # Given one texture and six faces, we can easily set up the uv coordinates # such that four of the faces tile "perfectly" along either u or v, but the other # two faces cannot be so aligned. This code tiles "along" u, "around" the X/Z faces # and fudges the Y faces - the Y faces are arbitrarily aligned such that a # rotation along the X axis will put the "top" of either texture at the "top" # of the screen, but is not otherwised aligned with the X/Z faces. (This # just affects what type of symmetry is required if you need seamless # tiling all the way around the cube) 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 def mouse_dragged rate = 0.01 @rotx += ( pmouse_y - mouse_y ) * rate @roty += ( mouse_x - pmouse_x ) * rate end
Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0
Tuesday, 4 December 2012
A 3D-texture example with my hacked ruby-processing
To get ruby-processing working with processing-2.0b6 core (and the associated opengl/jogl) required a number of hacks. One of which seemed to lose the ability to run sketches that were explicitly sub-classed from Processing::App, but that is probably no bad thing. Here is the modified textured_cube example, note NORMALIZED is replace by NORMAL in processing-2.0 syntax:-
Labels:
jruby-1.7.0,
processing-2.0,
ruby processing,
textured_cube
Subscribe to:
Post Comments (Atom)
Followers
Blog Archive
-
▼
2012
(26)
-
▼
December
(17)
- Bezier Patch as a VBO (PShape)
- Bezier Patch in ruby-processing
- Rotating Arcs Sketch in Ruby Processing
- Context free sketch in regular ruby processing
- Exporting cf3ruby directly to 'large' pdf
- Context Free Tree in cf3ruby
- New context_free.rb (cf3ruby)
- MeshToVBO conversion ruby-processing
- Fix for ruby-processing context free
- What works what does not and may not
- Retained Shape (FBO) in Ruby Processing
- Creating a Mock Vanilla Processing Distribution
- Landscape shader in ruby-processing
- Fish-eye shader revisited with ruby-processing and...
- PShader Example in ruby-processing
- A 3D-texture example with my hacked ruby-processing
- Testing ruby-processing with processing-2.0
-
▼
December
(17)
About Me
- monkstone
- I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2
No comments:
Post a Comment