Class: Fox::FXGLLine

Inherits:
FXGLObject show all
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)


91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fox16/glshapes.rb', line 91

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]



71
72
73
# File 'lib/fox16/glshapes.rb', line 71

def fm
  @fm
end

#toObject

End point for line [FXGLPoint]



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

def to
  @to
end

Instance Method Details

#boundsObject

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



108
109
110
111
112
113
114
115
# File 'lib/fox16/glshapes.rb', line 108

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).



120
121
122
123
124
125
126
127
# File 'lib/fox16/glshapes.rb', line 120

def draw(viewer)
  GL.Color3d(1.0, 0.0, 0.0)
  GL.PointSize(HANDLE_SIZE)
  GL.Begin(GL::LINES)
  GL.Vertex3d(*@fm.pos)
  GL.Vertex3d(*@to.pos)
  GL.End()
end

#hit(viewer) ⇒ Object

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



132
133
134
135
136
137
# File 'lib/fox16/glshapes.rb', line 132

def hit(viewer)
  GL.Begin(GL::LINES)
  GL.Vertex3d(*@fm.pos)
  GL.Vertex3d(*@to.pos)
  GL.End()
end