66# Use Face Struct triangle 'mesh'.
77Face = Struct . new ( :a , :b , :c ) # triangle mesh face
88
9- # Monkey patch the Vec3D class to support rotations
10- Vec3D . class_eval do # re-open the Vec3D class to add the rotate methods
11- def rotate_y! ( theta )
9+ Vec3D . class_eval do # re-open the Vec3D class to add rotation functionality
10+ def rotate_y ( theta )
1211 co = Math . cos ( theta )
1312 si = Math . sin ( theta )
1413 xx = co * x - si * z
@@ -17,7 +16,7 @@ def rotate_y!(theta)
1716 self
1817 end
1918
20- def rotate_x! ( theta )
19+ def rotate_x ( theta )
2120 co = Math . cos ( theta )
2221 si = Math . sin ( theta )
2322 zz = co * z - si * y
@@ -27,8 +26,12 @@ def rotate_x!(theta)
2726 end
2827end
2928
30- # After a toxiclibs "MeshDoodle" sketch by Karsten Schmidt
3129class Doodle < Processing ::App
30+ # After a toxiclibs "MeshDoodle" sketch by Karsten Schmidt
31+ # Adapted to use JRubyArt Vec2D and Vec3D classes by Martin Prout
32+ # Note: The extension of Vec3D class to support rotations, and the ruby Struct
33+ # Face for triangle 'mesh'. Also an example of AppRenderer for Vec3D => vertex
34+
3235 attr_reader :prev , :p , :q , :rotation , :faces , :pos , :weight
3336
3437 def settings
@@ -68,8 +71,8 @@ def draw
6871 def mouse_moved
6972 # get 3D rotated mouse position
7073 @pos = Vec3D . new ( mouse_x - width / 2 , mouse_y - height / 2 , 0 )
71- pos . rotate_x! ( rotation . x )
72- pos . rotate_y! ( rotation . y )
74+ pos . rotate_x ( rotation . x )
75+ pos . rotate_y ( rotation . y )
7376 # use distance to previous point as target stroke weight
7477 @weight += ( sqrt ( pos . dist ( prev ) ) * 2 - weight ) * 0.1
7578 # define offset points for the triangle strip
@@ -84,10 +87,9 @@ def mouse_moved
8487 @q = b
8588 end
8689
87- # An example of GfxRenderer usage for Vec3D => vertex conversion
8890 def renderer
89- @renderer ||= Processing :: Render :: GfxRender . new ( self . g )
90- end
91+ @renderer ||= GfxRender . new ( self . g )
92+ end
9193end
9294
9395Doodle . new
0 commit comments