Class: Bullet3::DebugDraw

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

Constant Summary collapse

NO_DEBUG =
0
DRAW_WIREFRAME =
1
DRAW_AABB =
2
DRAW_CONTACT_POINTS =
8
DRAW_CONSTRAINTS =
1 << 11
DRAW_CONSTRAINT_LIMITS =
1 << 12
DRAW_FRAMES =
1 << 15

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target = nil) ⇒ DebugDraw

Returns a new instance of DebugDraw.



16
17
18
19
20
# File 'lib/bullet3/debug_draw.rb', line 16

def initialize(target = nil)
  @target = target
  @debug_mode = DRAW_WIREFRAME | DRAW_AABB | DRAW_CONSTRAINTS | DRAW_CONSTRAINT_LIMITS
  clear
end

Instance Attribute Details

#contact_pointsObject (readonly)

Returns the value of attribute contact_points.



14
15
16
# File 'lib/bullet3/debug_draw.rb', line 14

def contact_points
  @contact_points
end

#debug_modeObject

Returns the value of attribute debug_mode.



13
14
15
# File 'lib/bullet3/debug_draw.rb', line 13

def debug_mode
  @debug_mode
end

#linesObject (readonly)

Returns the value of attribute lines.



14
15
16
# File 'lib/bullet3/debug_draw.rb', line 14

def lines
  @lines
end

#textsObject (readonly)

Returns the value of attribute texts.



14
15
16
# File 'lib/bullet3/debug_draw.rb', line 14

def texts
  @texts
end

#warningsObject (readonly)

Returns the value of attribute warnings.



14
15
16
# File 'lib/bullet3/debug_draw.rb', line 14

def warnings
  @warnings
end

Instance Method Details

#clearObject



22
23
24
25
26
27
28
# File 'lib/bullet3/debug_draw.rb', line 22

def clear
  @lines = []
  @contact_points = []
  @warnings = []
  @texts = []
  nil
end

#draw_3d_text(location, text) ⇒ Object



60
61
62
63
64
65
# File 'lib/bullet3/debug_draw.rb', line 60

def draw_3d_text(location, text)
  entry = { location: vector_array(location), text: text.to_s }
  texts << entry
  @target.draw_3d_text(entry[:location], entry[:text]) if @target&.respond_to?(:draw_3d_text)
  nil
end

#draw_contact_point(point, normal, distance = nil, life_time = nil, color = nil, **options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bullet3/debug_draw.rb', line 37

def draw_contact_point(point, normal, distance = nil, life_time = nil, color = nil, **options)
  distance = options.fetch(:distance, distance)
  life_time = options.fetch(:life_time, life_time)
  color = options.fetch(:color, color)
  entry = {
    point: vector_array(point),
    normal: vector_array(normal),
    distance: Float(distance),
    life_time: Integer(life_time),
    color: vector_array(color)
  }
  contact_points << entry
  @target.draw_contact_point(entry) if @target&.respond_to?(:draw_contact_point)
  nil
end

#draw_line(from, to, color) ⇒ Object



30
31
32
33
34
35
# File 'lib/bullet3/debug_draw.rb', line 30

def draw_line(from, to, color)
  entry = { from: vector_array(from), to: vector_array(to), color: vector_array(color) }
  lines << entry
  @target.draw_line(entry[:from], entry[:to], entry[:color]) if @target&.respond_to?(:draw_line)
  nil
end

#report_error_warning(message) ⇒ Object



53
54
55
56
57
58
# File 'lib/bullet3/debug_draw.rb', line 53

def report_error_warning(message)
  warning = message.to_s
  warnings << warning
  @target.report_error_warning(warning) if @target&.respond_to?(:report_error_warning)
  nil
end