Class: Fox::FXGLCylinder

Inherits:
FXGLShape show all
Includes:
GLU, OpenGL
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.


375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/fox16/glshapes.rb', line 375

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]


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

def height
  @height
end

#loopsObject

Number of loops (default is 4) [Integer]


356
357
358
# File 'lib/fox16/glshapes.rb', line 356

def loops
  @loops
end

#radiusObject

Cylinder radius [Float]


347
348
349
# File 'lib/fox16/glshapes.rb', line 347

def radius
  @radius
end

#slicesObject

Number of slices (default is 20) [Integer]


350
351
352
# File 'lib/fox16/glshapes.rb', line 350

def slices
  @slices
end

#stacksObject

Number of stacks (default is 20) [Integer]


353
354
355
# File 'lib/fox16/glshapes.rb', line 353

def stacks
  @stacks
end

Instance Method Details

#drawshape(viewer) ⇒ Object

Draw this cylinder into viewer (an FXGLViewer instance).


393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/fox16/glshapes.rb', line 393

def drawshape(viewer)
  quad = gluNewQuadric()
  gluQuadricDrawStyle(quad, GLU_FILL)
  glPushMatrix()
  glRotated(-90, 1, 0, 0)
  gluCylinder(quad, @radius, @radius, @height, @slices, @stacks)
  gluQuadricOrientation(quad, GLU_INSIDE)
  gluDisk(quad, 0, @radius, @slices, @loops)
  glTranslated(0, 0, @height)
  gluQuadricOrientation(quad, GLU_OUTSIDE)
  gluDisk(quad, 0, @radius, @slices, @loops)
  glPopMatrix()
  gluDeleteQuadric(quad)
end