Class: Fox::FXGLCube

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

Overview

OpenGL cube object

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

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.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/fox16/glshapes.rb', line 171

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

Instance Attribute Details

#depthObject

Cube depth [Float]



151
152
153
# File 'lib/fox16/glshapes.rb', line 151

def depth
  @depth
end

#heightObject

Cube height [Float]



148
149
150
# File 'lib/fox16/glshapes.rb', line 148

def height
  @height
end

#widthObject

Cube width [Float]



145
146
147
# File 'lib/fox16/glshapes.rb', line 145

def width
  @width
end

Instance Method Details

#drawshape(viewer) ⇒ Object

Draws this cube into viewer (an FXGLViewer instance).



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/fox16/glshapes.rb', line 189

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.Normal3d(0.0, 0.0, -1.0)
    GL.Vertex3d(xmin, ymin, zmin)
    GL.Vertex3d(xmin, ymax, zmin)
    GL.Vertex3d(xmax, ymin, zmin)
    GL.Vertex3d(xmax, ymax, zmin)
  GL.End()

  # Draw east face
  GL.Begin(GL::TRIANGLE_STRIP)
    GL.Normal3d(1.0, 0.0, 0.0)
    GL.Vertex3d(xmax, ymin, zmin)
    GL.Vertex3d(xmax, ymax, zmin)
    GL.Vertex3d(xmax, ymin, zmax)
    GL.Vertex3d(xmax, ymax, zmax)
  GL.End()

  # Draw high face
  GL.Begin(GL::TRIANGLE_STRIP)
    GL.Normal3d(0.0, 0.0, 1.0)
    GL.Vertex3d(xmax, ymin, zmax)
    GL.Vertex3d(xmax, ymax, zmax)
    GL.Vertex3d(xmin, ymin, zmax)
    GL.Vertex3d(xmin, ymax, zmax)
  GL.End()

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

  # Draw north face
  GL.Begin(GL::TRIANGLE_STRIP)
    GL.Normal3d(0.0, 1.0, 0.0)
    GL.Vertex3d(xmin, ymax, zmin)
    GL.Vertex3d(xmin, ymax, zmax)
    GL.Vertex3d(xmax, ymax, zmin)
    GL.Vertex3d(xmax, ymax, zmax)
  GL.End()

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