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)

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

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]


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

def fm
  @fm
end

#toObject

End point for line [FXGLPoint]


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

def to
  @to
end

Instance Method Details

#boundsObject

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


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

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


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

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

#hit(viewer) ⇒ Object

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


134
135
136
137
138
139
# File 'lib/fox16/glshapes.rb', line 134

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