Class: Budgie::Draw

Inherits:
Object
  • Object
show all
Includes:
GL
Defined in:
lib/budgie/draw.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Draw

Returns a new instance of Draw.



8
9
10
11
12
# File 'lib/budgie/draw.rb', line 8

def initialize(app)
  @app = app
  @cube = DrawCube.new
  @picker_cube = DrawPickerCube.new
end

Instance Method Details

#crosshair(size = 10, width = 4) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/budgie/draw.rb', line 40

def crosshair(size = 10, width = 4)
  glLineWidth width
  cx = @app.width / 2
  cy = @app.height / 2

  glBegin GL_LINES
  glVertex2f cx - size, cy
  glVertex2f cx + size, cy

  glVertex2f cx, cy - size
  glVertex2f cx, cy + size
  glEnd
end

#crosshair_with_outlineObject



33
34
35
36
37
38
# File 'lib/budgie/draw.rb', line 33

def crosshair_with_outline
  glColor3ub 0, 0, 0
  crosshair 12, 8
  glColor3ub 0xff, 0xff, 0xff
  crosshair
end

#cube_at(x, y, z) ⇒ Object



73
74
75
76
77
78
# File 'lib/budgie/draw.rb', line 73

def cube_at(x, y, z)
  glPushMatrix
  glTranslatef x, y, z
  @cube.full
  glPopMatrix
end

#guidesObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/budgie/draw.rb', line 54

def guides
  glLineWidth 10
  glBegin GL_LINES

  glColor3f 1, 0, 0
  glVertex3f 0, 0, 0
  glVertex3f 1, 0, 0

  glColor3f 0, 1, 0
  glVertex3f 0, 0, 0
  glVertex3f 0, 1, 0

  glColor3f 0, 0, 1
  glVertex3f 0, 0, 0
  glVertex3f 0, 0, 1

  glEnd
end

#ortho(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/budgie/draw.rb', line 14

def ortho(&block)
  glMatrixMode GL_PROJECTION
  glPushMatrix
  glLoadIdentity
  glOrtho 0, @app.width, 0, @app.height, -1, 1

  glMatrixMode GL_MODELVIEW
  glPushMatrix
  glLoadIdentity

  yield

  glMatrixMode GL_PROJECTION
  glPopMatrix

  glMatrixMode GL_MODELVIEW
  glPopMatrix
end

#picker_cube_at(x, y, z) ⇒ Object



80
81
82
83
84
85
# File 'lib/budgie/draw.rb', line 80

def picker_cube_at(x, y, z)
  glPushMatrix
  glTranslatef x, y, z
  @picker_cube.full
  glPopMatrix
end

#selection(selection) ⇒ Object



92
93
94
95
96
# File 'lib/budgie/draw.rb', line 92

def selection(selection)
  return unless selection.selected
  glColor3ub selection.r, selection.g, selection.b
  selection_cube_at selection.x, selection.y, selection.z
end

#selection_cube_at(x, y, z) ⇒ Object



87
88
89
90
# File 'lib/budgie/draw.rb', line 87

def selection_cube_at(x, y, z)
  glPolygonOffset -1, -1
  cube_at x, y, z
end