Class: Fox::FXGLLine

Inherits:
FXGLObject show all
Includes:
OpenGL
Defined in:
lib/fox16/glshapes.rb

Overview

OpenGL line object

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FXGLObject

#canDelete, #canDrag, #copy, #drag, #identify

Methods inherited from FXObject

#bind, #handle, #load, #save, subclasses

Constructor Details

#initialize(*args) ⇒ FXGLLine

Return an initialized FXGLLine instance.

If no arguments are passed to #new, the initial starting and ending points for the line are (-0.5, 0.0, 0.0) and (0.5, 0.0, 0.0), respectively. You can specify different initial start and end points by passing in another FXGLLine instance from which to copy the start and end point values, e.g.

aLine = FXGLLine.new(anotherLine)

or by passing in the x, y and z coordinates individually:

aLine = FXGLLine.new(x0, y0, z0, x1, y1, z1)

95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/fox16/glshapes.rb', line 95

def initialize(*args)
  super()
  if args.length == 0
    @fm = FXGLPoint.new(-0.5, 0.0, 0.0)
    @to = FXGLPoint.new( 0.5, 0.0, 0.0)
  elsif args.length == 1
    @fm = args[0].fm
    @to = args[0].to
  else
    @fm = FXGLPoint.new(args[0], args[1], args[2])
    @to = FXGLPoint.new(args[3], args[4], args[5])
  end
end

Instance Attribute Details

#fmObject

Starting point for line [FXGLPoint]


75
76
77
# File 'lib/fox16/glshapes.rb', line 75

def fm
  @fm
end

#toObject

End point for line [FXGLPoint]


78
79
80
# File 'lib/fox16/glshapes.rb', line 78

def to
  @to
end

Instance Method Details

#boundsObject

Return the bounding box (an FXRangef instance) for this line.


112
113
114
115
116
117
118
119
# File 'lib/fox16/glshapes.rb', line 112

def bounds
  FXRangef.new([@fm.pos[0], @to.pos[0]].min,
              [@fm.pos[0], @to.pos[0]].max,
              [@fm.pos[1], @to.pos[1]].min,
              [@fm.pos[1], @to.pos[1]].max,
              [@fm.pos[2], @to.pos[2]].min,
              [@fm.pos[2], @to.pos[2]].max)
end

#draw(viewer) ⇒ Object

Draw this line into viewer (an FXGLViewer instance).


124
125
126
127
128
129
130
131
# File 'lib/fox16/glshapes.rb', line 124

def draw(viewer)
  glColor3d(1.0, 0.0, 0.0)
  glPointSize(HANDLE_SIZE)
  glBegin(GL_LINES)
  glVertex3d(*@fm.pos)
  glVertex3d(*@to.pos)
  glEnd()
end

#hit(viewer) ⇒ Object

Perform hit-test for this line in viewer (an FXGLViewer instance).


136
137
138
139
140
141
# File 'lib/fox16/glshapes.rb', line 136

def hit(viewer)
  glBegin(GL_LINES)
  glVertex3d(*@fm.pos)
  glVertex3d(*@to.pos)
  glEnd()
end