Class: Sokoban1::Render
- Inherits:
-
Object
- Object
- Sokoban1::Render
- Defined in:
- lib/sokoban/render.rb
Class Attribute Summary collapse
-
.game ⇒ Object
Returns the value of attribute game.
Class Method Summary collapse
- .convert(args) ⇒ Object
- .display2 ⇒ Object
- .enable_light_soko ⇒ Object
- .init_soko ⇒ Object
- .keyboard_ffi(key, x, y) ⇒ Object
- .keyboard_not_ffi(key, x, y) ⇒ Object
- .register_glut_with_soko ⇒ Object
- .render_crate ⇒ Object
- .render_man ⇒ Object
- .render_open_floor ⇒ Object
- .render_storage ⇒ Object
- .render_stored_crate ⇒ Object
- .render_wall ⇒ Object
-
.reshape_soko(width, height) ⇒ Object
New window size or exposure.
- .solid_cylinder(radius, height, slices, stacks) ⇒ Object
Class Attribute Details
.game ⇒ Object
Returns the value of attribute game.
8 9 10 |
# File 'lib/sokoban/render.rb', line 8 def game @game end |
Class Method Details
.convert(args) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/sokoban/render.rb', line 170 def convert args #puts args.class if SHOW_FFI MemoryPointer.new(:float, 4).put_array_of_float(0, args) else args end end |
.display2 ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/sokoban/render.rb', line 293 def display2 #= lambda do puts 'render::display2() glClear (..)' glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT #GLUT.InitDisplayMode GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH screen = @game.display #puts screen.class screen = screen.split("\n") #puts screen.class puts screen screen.each_with_index do |row, y| row.chomp! first = row =~ /^(\s+)/ ? $1.length : 0 (first...row.length).each do |x| glPushMatrix glTranslatef 1.0 + x, 17.5 - y, 0.0 if row[x, 1] == "." or row[x, 1] == "*" or row[x, 1] == "+" render_storage else render_open_floor end if row[x, 1] == "@" or row[x, 1] == "+" render_man elsif row[x, 1] == "o" render_crate elsif row[x, 1] == "*" render_stored_crate elsif row[x, 1] == "#" render_wall end glPopMatrix end end glFlush glutSwapBuffers end |
.enable_light_soko ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/sokoban/render.rb', line 356 def enable_light_soko unless SHOW_FFI puts 'Render::senable_light_soko() how ffi' glLight GL_LIGHT0, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0] glLight GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0] glLight GL_LIGHT0, GL_POSITION, [0.0, 3.0, 3.0, 0.0] glLightModel GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0] glLightModel GL_LIGHT_MODEL_LOCAL_VIEWER, [0.0] end #GL.FrontFace GL::CW #GL.Enable GL::LIGHTING #GL.Enable GL::LIGHT0 #GL.Enable GL::AUTO_NORMAL #GL.Enable GL::NORMALIZE #GL.Enable GL::DEPTH_TEST #GL.DepthFunc GL::LESS glFrontFace GL_CW glEnable GL_LIGHTING glEnable GL_LIGHT0 glEnable GL_AUTO_NORMAL glEnable GL_NORMALIZE glEnable GL_DEPTH_TEST glDepthFunc GL_LESS end |
.init_soko ⇒ Object
349 350 351 352 353 354 355 |
# File 'lib/sokoban/render.rb', line 349 def init_soko puts 'render think: SHOW_FFI is:' puts SHOW_FFI @game = Sokoban.new end |
.keyboard_ffi(key, x, y) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/sokoban/render.rb', line 247 def keyboard_ffi key , x , y #= lambda do |key, x, y| puts key puts x puts y case key when ?c exit 0 when ?s @game.save #when ?l #if test ?e, File.join(PATH, "[email protected]") #@game = Sokoban.load #end when ?r @game.restart_level when ?n @game.load_level when ?u @game.undo when 104 @game.move_left when 107 @game.move_right when 106 @game.move_down when 117 #?i, ?I @game.move_up #puts 'move up' when 27 exit end if @game.level_solved? @game.load_level exit 0 if @game.over? end glutPostRedisplay end |
.keyboard_not_ffi(key, x, y) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/sokoban/render.rb', line 203 def keyboard_not_ffi key , x , y #= lambda do |key, x, y| puts key puts x puts y case key when ?c exit 0 when ?s @game.save #when ?l #if test ?e, File.join(PATH, "[email protected]") #@game = Sokoban.load #end when ?r @game.restart_level when ?n @game.load_level when ?u @game.undo when ?j @game.move_left when ?l @game.move_right when ?k @game.move_down when ?i #?i, ?I @game.move_up #puts 'move up' when ?q exit end if @game.level_solved? @game.load_level exit 0 if @game.over? end glutPostRedisplay end |
.register_glut_with_soko ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/sokoban/render.rb', line 333 def register_glut_with_soko glutDisplayFunc (method(:display2).to_proc) #glutIdleFunc(method(:idle).to_proc) glutReshapeFunc (method(:reshape_soko).to_proc) if SHOW_FFI glutKeyboardFunc(method(:keyboard_ffi).to_proc) else glutKeyboardFunc(method(:keyboard_not_ffi).to_proc) end end |
.render_crate ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sokoban/render.rb', line 27 def render_crate unless @render_crate @render_crate = glGenLists 1 glNewList(@render_crate , GL_COMPILE) glMaterialfv GL_FRONT, GL_AMBIENT,convert( [0.19125, 0.0735, 0.0225, 1.0] ) glMaterialfv GL_FRONT, GL_DIFFUSE,convert( [0.7038, 0.27048, 0.0828, 1.0] ) glMaterialfv GL_FRONT, GL_SPECULAR,convert( [0.256777, 0.137622, 0.086014, 1.0] ) #glMaterialfv GL_FRONT, GL_SHININESS, 0.1 * 128.0 unless SHOW_FFI glPushMatrix glScalef 0.9, 0.9, 0.9 glTranslatef 0.0, 0.0, 0.45 glutSolidCube 1.0 glPopMatrix glEndList end glCallList @render_crate end |
.render_man ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sokoban/render.rb', line 10 def render_man unless @render_man @render_man = glGenLists 1 glNewList(@render_man , GL_COMPILE) glMaterialfv GL_FRONT, GL_AMBIENT,convert( [0.0, 0.0, 0.0, 1.0] ) glMaterialfv GL_FRONT, GL_DIFFUSE,convert( [0.5, 0.0, 0.0, 1.0] ) glMaterialfv GL_FRONT, GL_SPECULAR,convert( [0.7, 0.6, 0.6, 1.0] ) #glMaterialfv GL_FRONT, GL_SHININESS, 0.25 * 128.0 unless SHOW_FFI glutSolidSphere 0.5, 16, 16 glEndList end glCallList @render_man end |
.render_open_floor ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sokoban/render.rb', line 70 def render_open_floor unless @render_open_floor @render_open_floor = glGenLists 1 glNewList(@render_open_floor, GL_COMPILE) glMaterialfv GL_FRONT, GL_AMBIENT,convert( [0.05, 0.05, 0.05, 1.0] ) glMaterialfv GL_FRONT, GL_DIFFUSE,convert( [0.5, 0.5, 0.5, 1.0] ) glMaterialfv GL_FRONT, GL_SPECULAR,convert( [0.7, 0.7, 0.7, 1.0] ) #glMaterialfv GL_FRONT, GL_SHININESS, 0.078125 * 128.0 glPushMatrix glScalef 0.9, 0.9, 0.1 glTranslatef 0.0, 0.0, -0.05 glutSolidCube 1.0 glPopMatrix glMaterialfv GL_FRONT, GL_AMBIENT, convert( [0.05375, 0.05, 0.06625, 1.0] ) glMaterialfv GL_FRONT, GL_DIFFUSE, convert( [0.18275, 0.17, 0.22525, 1.0] ) glMaterialfv GL_FRONT, GL_SPECULAR, convert( [0.332741, 0.328634, 0.346435, 1.0] ) #glMaterialfv GL_FRONT, GL_SHININESS, 0.3 * 128.0 unless SHOW_FFI glPushMatrix glScalef 1.0, 1.0, 0.1 glTranslatef 0.0, 0.0, -0.1 glutSolidCube 1.0 glPopMatrix glEndList end glCallList @render_open_floor end |
.render_storage ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/sokoban/render.rb', line 107 def render_storage #glGenLists(1) # Make the gears unless @render_storage puts 'REGISTER IN DISPLAY LIST' @render_storage = glGenLists 1 glNewList(@render_storage, GL_COMPILE) #glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE,@mRED) #gear(1.0, 4.0, 1.0, 20, 0.7) glMaterialfv GL_FRONT, GL_AMBIENT, convert( [0.05, 0.05, 0.0, 1.0] ) glMaterialfv GL_FRONT, GL_DIFFUSE, convert( [0.5, 0.5, 0.4, 1.0] ) glMaterialfv GL_FRONT, GL_SPECULAR, convert( [0.7, 0.7, 0.04, 1.0] ) #glMaterialfv GL_FRONT, GL_SHININESS, 0.078125 * 128.0 unless SHOW_FFI glPushMatrix glScalef 0.9, 0.9, 0.1 glTranslatef 0.0, 0.0, -0.05 glutSolidCube 1.0 glPopMatrix glMaterialfv GL_FRONT, GL_AMBIENT, convert([0.05375, 0.05, 0.06625, 1.0]) glMaterialfv GL_FRONT, GL_DIFFUSE, convert([0.18275, 0.17, 0.22525, 1.0]) glMaterialfv GL_FRONT, GL_SPECULAR, convert([0.332741, 0.328634, 0.346435, 1.0]) #glMaterialfv GL_FRONT, GL_SHININESS, 0.3 * 128.0 unless SHOW_FFI glPushMatrix glScalef 1.0, 1.0, 0.1 glTranslatef 0.0, 0.0, -0.1 glutSolidCube 1.0 glPopMatrix glEndList() end #glPushMatrix() #glTranslatef(-3.0, -2.0, 0.0) #glRotatef(@angle, 0.0, 0.0, 1.0) glCallList(@render_storage) #glPopMatrix() end |
.render_stored_crate ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sokoban/render.rb', line 48 def render_stored_crate unless @render_stored_crate @render_stored_crate = glGenLists 1 glNewList(@render_stored_crate , GL_COMPILE) glMaterialfv GL_FRONT, GL_AMBIENT,convert( [0.25, 0.20725, 0.20725, 1.0] ) glMaterialfv GL_FRONT, GL_DIFFUSE,convert( [1.0, 0.829, 0.829, 1.0] ) glMaterialfv GL_FRONT, GL_SPECULAR,convert( [0.296648, 0.296648, 0.296648, 1.0] ) #glMaterialfv GL_FRONT, GL_SHININESS, 0.088 * 128.0 unless SHOW_FFI glPushMatrix glScalef 0.9, 0.9, 0.9 glTranslatef 0.0, 0.0, 0.45 glutSolidCube 1.0 glPopMatrix glEndList end glCallList @render_stored_crate end |
.render_wall ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/sokoban/render.rb', line 181 def render_wall unless @render_wall @render_wall = glGenLists 1 glNewList(@render_wall , GL_COMPILE) glMaterialfv GL_FRONT, GL_AMBIENT, convert( [0.0, 0.0, 0.0, 1.0]) glMaterialfv GL_FRONT, GL_DIFFUSE, convert( [0.1, 0.35, 0.1, 1.0]) glMaterialfv GL_FRONT, GL_SPECULAR, convert( [0.45, 0.55, 0.45, 1.0]) #glMaterialfv GL_FRONT, GL_SHININESS, 0.25 * 128.0 unless SHOW_FFI glPushMatrix glTranslatef 0.0, 0.0, 0.5 solid_cylinder 0.45, 1.0, 16, 4 glPopMatrix glEndList end glCallList @render_wall end |
.reshape_soko(width, height) ⇒ Object
New window size or exposure
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/sokoban/render.rb', line 383 def reshape_soko(width, height) h = height.to_f / width.to_f glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() glFrustum(-1.0, 1.0, -h, h, 1.5, 20.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() gluLookAt 10.0, 10.0, 17.5, 10.0, 10.0, 0.0, 0.0, 1.0, 0.0 #glTranslatef(0.0, 0.0, -40.0) # glutPostRedisplay end |
.solid_cylinder(radius, height, slices, stacks) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/sokoban/render.rb', line 155 def solid_cylinder(radius, height, slices, stacks) glPushAttrib GL_POLYGON_BIT glPolygonMode GL_FRONT_AND_BACK, GL_FILL obj = gluNewQuadric gluCylinder obj, radius, radius, height, slices, stacks glPushMatrix glTranslatef 0.0, 0.0, height gluDisk obj, 0.0, radius, slices, stacks glPopMatrix gluDeleteQuadric obj glPopAttrib end |