Skip to content

Commit f78784a

Browse files
committed
A bit more rubified
1 parent 04d9825 commit f78784a

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

external_library/java/PixelFlow/geometry_grid.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# key '1'-'7' ... subdivisions
1818
# key 's ... toggle stroke display
1919

20-
attr_reader :cam, :grid, :mesh, :shp_gizmo, :display_stroke
20+
attr_reader :grid, :mesh, :shp_gizmo, :display_stroke
2121
RADIUS = 200
2222

2323
def settings
@@ -26,8 +26,8 @@ def settings
2626
end
2727

2828
def setup
29-
@cam = PeasyCam.new(self, 1000)
30-
create_mesh(4)
29+
PeasyCam.new(self, 1000)
30+
create_mesh(4) # initial setting
3131
@display_stroke = true
3232
@shp_gizmo = nil
3333
end
@@ -42,7 +42,6 @@ def draw
4242
directionalLight(128, 96, 64, -500, -500, 1_000)
4343
background(64)
4444
display_gizmo(300)
45-
4645
scale(RADIUS)
4746
if(display_stroke)
4847
stroke_weight(0.5 / RADIUS)
@@ -52,31 +51,29 @@ def draw
5251
end
5352
fill(255)
5453
# display the IFS-mesh (Indexed Face set)
55-
pushMatrix
54+
push_matrix
5655
translate(-1.5, 0)
5756
display_mesh(grid)
58-
popMatrix
57+
pop_matrix
5958
# display the HalfEdge mesh
60-
pushMatrix
59+
push_matrix
6160
translate(1.5, 0)
6261
mesh.display(g)
63-
popMatrix
62+
pop_matrix
6463
# info
65-
num_faces = mesh.ifs.getFacesCount
66-
num_verts = mesh.ifs.getVertsCount
64+
num_faces = mesh.ifs.get_faces_count
65+
num_verts = mesh.ifs.get_verts_count
6766
num_edges = mesh.edges.length
68-
#String txt_fps = String.format(getClass().getName()+ " [Verts %d] [Faces %d] [HalfEdges %d] [fps %6.2f]", num_verts, num_faces, num_edges, frameRate)
69-
#surface.setTitle(txt_fps)
7067
format_string = 'Geometry Grid [Verts %d] [Faces %d] [Half Edges %d] [fps: (%6.2f)]'
7168
surface.set_title(format(format_string, num_verts, num_faces, num_edges, frame_rate))
7269
end
7370

7471
# this method can of course be optimized if we know in advance the number of
7572
# vertices per face
7673
def display_mesh(ifs)
77-
faces_count = ifs.getFacesCount
78-
faces = ifs.getFaces
79-
verts = ifs.getVerts
74+
faces_count = ifs.get_faces_count
75+
faces = ifs.get_faces
76+
verts = ifs.get_verts
8077
v = Array.new(3)
8178
faces.each do |face|
8279
case(face.length)
@@ -111,22 +108,25 @@ def display_mesh(ifs)
111108
end
112109
end
113110

111+
def create_gizmo(s)
112+
stroke_weight(1)
113+
shp_gizmo = create_shape
114+
shp_gizmo.begin_shape(LINES)
115+
shp_gizmo.stroke(255, 0, 0)
116+
shp_gizmo.vertex(0, 0, 0)
117+
shp_gizmo.vertex(s, 0, 0)
118+
shp_gizmo.stroke(0, 255, 0)
119+
shp_gizmo.vertex(0, 0, 0)
120+
shp_gizmo.vertex(0, s, 0)
121+
shp_gizmo.stroke(0, 0, 255)
122+
shp_gizmo.vertex(0, 0, 0)
123+
shp_gizmo.vertex(0, 0, s)
124+
shp_gizmo.end_shape
125+
shp_gizmo
126+
end
127+
114128
def display_gizmo(s)
115-
if shp_gizmo.nil?
116-
strokeWeight(1)
117-
@shp_gizmo = create_shape
118-
shp_gizmo.begin_shape(LINES)
119-
shp_gizmo.stroke(255,0,0)
120-
shp_gizmo.vertex(0,0,0)
121-
shp_gizmo.vertex(s,0,0)
122-
shp_gizmo.stroke(0,255,0)
123-
shp_gizmo.vertex(0,0,0)
124-
shp_gizmo.vertex(0,s,0)
125-
shp_gizmo.stroke(0,0,255)
126-
shp_gizmo.vertex(0,0,0)
127-
shp_gizmo.vertex(0,0,s)
128-
shp_gizmo.end_shape
129-
end
129+
@shp_gizmo = create_gizmo(s) unless shp_gizmo
130130
shape(shp_gizmo)
131131
end
132132

0 commit comments

Comments
 (0)