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 177 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 195 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 glBegin(GL_TRIANGLE_STRIP) glNormal3d(0.0, 0.0, -1.0) glVertex3d(xmin, ymin, zmin) glVertex3d(xmin, ymax, zmin) glVertex3d(xmax, ymin, zmin) glVertex3d(xmax, ymax, zmin) glEnd() # Draw east face glBegin(GL_TRIANGLE_STRIP) glNormal3d(1.0, 0.0, 0.0) glVertex3d(xmax, ymin, zmin) glVertex3d(xmax, ymax, zmin) glVertex3d(xmax, ymin, zmax) glVertex3d(xmax, ymax, zmax) glEnd() # Draw high face glBegin(GL_TRIANGLE_STRIP) glNormal3d(0.0, 0.0, 1.0) glVertex3d(xmax, ymin, zmax) glVertex3d(xmax, ymax, zmax) glVertex3d(xmin, ymin, zmax) glVertex3d(xmin, ymax, zmax) glEnd() # Draw west face glBegin(GL_TRIANGLE_STRIP) glNormal3d(-1.0, 0.0, 0.0) glVertex3d(xmin, ymin, zmax) glVertex3d(xmin, ymax, zmax) glVertex3d(xmin, ymin, zmin) glVertex3d(xmin, ymax, zmin) glEnd() # Draw north face glBegin(GL_TRIANGLE_STRIP) glNormal3d(0.0, 1.0, 0.0) glVertex3d(xmin, ymax, zmin) glVertex3d(xmin, ymax, zmax) glVertex3d(xmax, ymax, zmin) glVertex3d(xmax, ymax, zmax) glEnd() # Draw south face glBegin(GL_TRIANGLE_STRIP) glNormal3d(0.0, -1.0, 0.0) glVertex3d(xmin, ymin, zmax) glVertex3d(xmin, ymin, zmin) glVertex3d(xmax, ymin, zmax) glVertex3d(xmax, ymin, zmin) glEnd() end