class Fox::FXGLCube

OpenGL cube object

Attributes

depth[RW]

Cube depth [Float]

height[RW]

Cube height [Float]

width[RW]

Cube width [Float]

Public Class Methods

new(*args) click to toggle source

Return an initialized FXGLCube instance.

One option is to initialize the cube with a specified origin, width, height and depth:

aCube = FXGLCube.new(x, y, z, w, h, d)

If left unspecified, the width (w), height (h) and depth (d) default to 1.0.

Another option is to initialize the cube with a specified origin, width, height, depth and material:

aCube = FXGLCube.new(x, y, z, w, h, d, material)

where the material is an FXMaterial instance.

Calls superclass method Fox::FXGLShape::new
# File lib/fox16/glshapes.rb, line 174
def initialize(*args)
  if args.length == 7
    super(args[0], args[1], args[2], SHADING_SMOOTH|STYLE_SURFACE,
          args[6], args[6])
  else
    super(args[0], args[1], args[2], SHADING_SMOOTH|STYLE_SURFACE)
  end
  @width = args[3] ? args[3] : 1.0
  @height = args[4] ? args[4] : 1.0
  @depth = args[5] ? args[5] : 1.0
  setRange(FXRangef.new(-0.5*@width, 0.5*@width,
                       -0.5*@height, 0.5*@height,
                       -0.5*@depth, 0.5*@depth))
end

Public Instance Methods

drawshape(viewer) click to toggle source

Draws this cube into viewer (an FXGLViewer instance).

# File lib/fox16/glshapes.rb, line 192
def drawshape(viewer)
  xmin, xmax = -0.5*@width, 0.5*@width
  ymin, ymax = -0.5*@height, 0.5*@height
  zmin, zmax = -0.5*@depth, 0.5*@depth

  # Draw low face
  GL::Begin(GL::TRIANGLE_STRIP)
    GL::Normal(0.0, 0.0, -1.0)
    GL::Vertex(xmin, ymin, zmin)
    GL::Vertex(xmin, ymax, zmin)
    GL::Vertex(xmax, ymin, zmin)
    GL::Vertex(xmax, ymax, zmin)
  GL::End()

  # Draw east face
  GL::Begin(GL::TRIANGLE_STRIP)
    GL::Normal(1.0, 0.0, 0.0)
    GL::Vertex(xmax, ymin, zmin)
    GL::Vertex(xmax, ymax, zmin)
    GL::Vertex(xmax, ymin, zmax)
    GL::Vertex(xmax, ymax, zmax)
  GL::End()

  # Draw high face
  GL::Begin(GL::TRIANGLE_STRIP)
    GL::Normal(0.0, 0.0, 1.0)
    GL::Vertex(xmax, ymin, zmax)
    GL::Vertex(xmax, ymax, zmax)
    GL::Vertex(xmin, ymin, zmax)
    GL::Vertex(xmin, ymax, zmax)
  GL::End()

  # Draw west face
  GL::Begin(GL::TRIANGLE_STRIP)
    GL::Normal(-1.0, 0.0, 0.0)
    GL::Vertex(xmin, ymin, zmax)
    GL::Vertex(xmin, ymax, zmax)
    GL::Vertex(xmin, ymin, zmin)
    GL::Vertex(xmin, ymax, zmin)
  GL::End()

  # Draw north face
  GL::Begin(GL::TRIANGLE_STRIP)
    GL::Normal(0.0, 1.0, 0.0)
    GL::Vertex(xmin, ymax, zmin)
    GL::Vertex(xmin, ymax, zmax)
    GL::Vertex(xmax, ymax, zmin)
    GL::Vertex(xmax, ymax, zmax)
  GL::End()

  # Draw south face
  GL::Begin(GL::TRIANGLE_STRIP)
    GL::Normal(0.0, -1.0, 0.0)
    GL::Vertex(xmin, ymin, zmax)
    GL::Vertex(xmin, ymin, zmin)
    GL::Vertex(xmax, ymin, zmax)
    GL::Vertex(xmax, ymin, zmin)
  GL::End()
end