Class: Disp3D::Picker

Inherits:
Object
  • Object
show all
Defined in:
lib/picker.rb

Constant Summary collapse

NONE =

pick modes

0
POINT_PICK =
1
LINE_PICK =
2
RECT_PICK =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ Picker

Returns a new instance of Picker.



14
15
16
17
18
# File 'lib/picker.rb', line 14

def initialize(view)
  @view = view
  @max_select_count = 100
  @pick_mode = NONE
end

Instance Attribute Details

#max_select_countObject

Returns the value of attribute max_select_count.



6
7
8
# File 'lib/picker.rb', line 6

def max_select_count
  @max_select_count
end

#pick_modeObject (readonly)

Returns the value of attribute pick_mode.



5
6
7
# File 'lib/picker.rb', line 5

def pick_mode
  @pick_mode
end

Instance Method Details

#end_pickObject



43
44
45
# File 'lib/picker.rb', line 43

def end_pick
  @pick_mode = NONE
end

#motion(x, y) ⇒ Object

users donot need to use this. return if picking process is in progress?



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/picker.rb', line 83

def motion(x,y)
  return false if(@pick_mode == NONE || @last_pos.nil?)
  if(@pick_mode == LINE_PICK)
    if(@rubber_band)
      draw_rubber_band([FiniteLine.new(@last_pos, @save_pos), FiniteLine.new(@last_pos, Vector3.new(x,y))])
    else
      draw_rubber_band(FiniteLine.new(@last_pos, Vector3.new(x,y)))
    end
  elsif(@pick_mode == RECT_PICK)
    if(@rubber_band)
      draw_rubber_band([Box.new(@last_pos, @save_pos), Box.new(@last_pos, Vector3.new(x,y))])
    else
      draw_rubber_band(Box.new(@last_pos, Vector3.new(x,y)))
    end
  end
  @save_pos = Vector3.new(x, y)
  @rubber_band=true
  return true
end

#mouse(button, state, x, y) ⇒ Object

users donot need to use this.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/picker.rb', line 48

def mouse(button,state,x,y)
  return if(@pick_mode == NONE)
  if(button == GLUT::GLUT_LEFT_BUTTON && state == GLUT::GLUT_DOWN)
    if(@pick_mode == POINT_PICK)
      picked_result = point_pick(x,y)
      @post_pick_process.call(picked_result) if(!@post_pick_process.nil?)
      return
    elsif(@pick_mode == LINE_PICK)
      @line_start_result = point_pick(x,y)
    end
    @last_pos = Vector3.new(x, y)
    @rubber_band = false
  elsif(button == GLUT::GLUT_LEFT_BUTTON && state == GLUT::GLUT_UP)
    if(@pick_mode == LINE_PICK)
      draw_rubber_band(FiniteLine.new(@last_pos, @save_pos)) # delete rubber band
      line_end_result =  pick(x, y)
      @post_pick_process.call(@line_start_result, line_end_result) if(!@post_pick_process.nil?)
      @line_start_result = nil
    elsif(@pick_mode == RECT_PICK)
      draw_rubber_band(Box.new(@last_pos, @save_pos)) # delete rubber band
      pick_x = (x + @last_pos.x)/2
      pick_y = (y + @last_pos.y)/2
      width  = (x - @last_pos.x).abs
      height = (y - @last_pos.y).abs
      picked_result = pick(pick_x, pick_y, width, height)
      @post_pick_process.call(picked_result) if(!@post_pick_process.nil?)
    end
    @save_pos = nil
    @last_pos = nil
    @rubber_band = false
  end
end

#point_pick(x, y) ⇒ Object



20
21
22
# File 'lib/picker.rb', line 20

def point_pick(x,y)
  pick(x, y)
end

#post_picked(&block) ⇒ Object



24
25
26
# File 'lib/picker.rb', line 24

def post_picked(&block)
  @post_pick_process = block
end

#start_line_pick(&block) ⇒ Object



33
34
35
36
# File 'lib/picker.rb', line 33

def start_line_pick(&block)
  @pick_mode = LINE_PICK
  post_picked(&block) if(block_given?)
end

#start_point_pick(&block) ⇒ Object



28
29
30
31
# File 'lib/picker.rb', line 28

def start_point_pick(&block)
  @pick_mode = POINT_PICK
  post_picked(&block) if(block_given?)
end

#start_rect_pick(&block) ⇒ Object



38
39
40
41
# File 'lib/picker.rb', line 38

def start_rect_pick(&block)
  @pick_mode = RECT_PICK
  post_picked(&block) if(block_given?)
end