Class: Fox::FXGLCylinder

Inherits:
FXGLShape show all
Defined in:
lib/fox16/glshapes.rb

Overview

OpenGL cylinder object

Constant Summary collapse

SLICES_NUMBER =

Cylinder fidelity

20
STACKS_NUMBER =
20
LOOPS =
4

Instance Attribute Summary collapse

Attributes inherited from FXGLShape

#position, #tipText

Instance Method Summary collapse

Methods inherited from FXGLShape

#getMaterial, #setMaterial, #setRange

Methods inherited from FXGLObject

#bounds, #canDelete, #canDrag, #copy, #drag, #draw, #hit, #identify

Methods inherited from FXObject

#bind, #handle, #load, #save, subclasses

Constructor Details

#initialize(*args) ⇒ FXGLCylinder

Returns an initialized FXGLCylinder instance.

One option is to initialize the cylinder with a specified origin, height and radius:

aCylinder = FXGLCylinder.new(x, y, z, h, r)

If left unspecified, the height (h) and radius (r) default to 1.0.

Another option is to initialize the cylinder with a specified origin, height, radius and material:

aCylinder = FXGLCylinder.new(x, y, z, h, r, material)

where the material is an FXMaterial instance.



363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/fox16/glshapes.rb', line 363

def initialize(*args)
  if args.length == 5
    super(args[0], args[1], args[2], SHADING_SMOOTH|STYLE_SURFACE)
  else
    super(args[0], args[1], args[2], SHADING_SMOOTH|STYLE_SURFACE,
          args[5], args[5])
  end
  @height = args[3] ? args[3] : 1.0
  @radius = args[4] ? args[4] : 1.0
  @slices = SLICES_NUMBER
  @stacks = STACKS_NUMBER
  @loops  = LOOPS
  setRange(FXRangef.new(-@radius, @radius, 0, @height, -@radius, @radius))
end

Instance Attribute Details

#heightObject

Cylinder height [Float]



332
333
334
# File 'lib/fox16/glshapes.rb', line 332

def height
  @height
end

#loopsObject

Number of loops (default is 4) [Integer]



344
345
346
# File 'lib/fox16/glshapes.rb', line 344

def loops
  @loops
end

#radiusObject

Cylinder radius [Float]



335
336
337
# File 'lib/fox16/glshapes.rb', line 335

def radius
  @radius
end

#slicesObject

Number of slices (default is 20) [Integer]



338
339
340
# File 'lib/fox16/glshapes.rb', line 338

def slices
  @slices
end

#stacksObject

Number of stacks (default is 20) [Integer]



341
342
343
# File 'lib/fox16/glshapes.rb', line 341

def stacks
  @stacks
end

Instance Method Details

#drawshape(viewer) ⇒ Object

Draw this cylinder into viewer (an FXGLViewer instance).



381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/fox16/glshapes.rb', line 381

def drawshape(viewer)
  quad = GLU.NewQuadric()
  GLU.QuadricDrawStyle(quad, GLU::FILL)
  GL.PushMatrix()
  GL.Rotated(-90, 1, 0, 0)
  GLU.Cylinder(quad, @radius, @radius, @height, @slices, @stacks)
  GLU.QuadricOrientation(quad, GLU::INSIDE)
  GLU.Disk(quad, 0, @radius, @slices, @loops)
  GL.Translated(0, 0, @height)
  GLU.QuadricOrientation(quad, GLU::OUTSIDE)
  GLU.Disk(quad, 0, @radius, @slices, @loops)
  GL.PopMatrix()
  GLU.DeleteQuadric(quad)
end