Class: Fox::FXGLSphere

Inherits:
FXGLShape show all
Includes:
GLU, OpenGL
Defined in:
lib/fox16/glshapes.rb

Overview

OpenGL sphere object

Constant Summary collapse

SLICES_NUMBER =

Sphere fidelity

20
STACKS_NUMBER =
20

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) ⇒ FXGLSphere

Returns an initialized FXGLSphere instance.

One option is to initialize the sphere with a specified origin and radius:

aSphere = FXGLSphere.new(x, y, z, r)

If left unspecified, the radius (r) defaults to 1.0.

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

aSphere = FXGLSphere.new(x, y, z, r, material)

where the material is an FXMaterial instance.


446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/fox16/glshapes.rb', line 446

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

Instance Attribute Details

#radiusObject

Sphere radius [Float]


421
422
423
# File 'lib/fox16/glshapes.rb', line 421

def radius
  @radius
end

#slicesObject

Number of slices (default is 20) [Integer]


424
425
426
# File 'lib/fox16/glshapes.rb', line 424

def slices
  @slices
end

#stacksObject

Number of stacks (default is 20) [Integer]


427
428
429
# File 'lib/fox16/glshapes.rb', line 427

def stacks
  @stacks
end

Instance Method Details

#drawshape(viewer) ⇒ Object

Draw this sphere into viewer (an FXGLViewer instance).


462
463
464
465
466
467
# File 'lib/fox16/glshapes.rb', line 462

def drawshape(viewer)
  quad = gluNewQuadric()
  gluQuadricDrawStyle(quad, GLU_FILL)
  gluSphere(quad, @radius, @slices, @stacks)
  gluDeleteQuadric(quad)
end