Class: Box2D

Inherits:
Java::ProcessingBox2d::Box2DProcessing
  • Object
show all
Defined in:
lib/pbox2d/box2d.rb

Overview

rubified interface, also needed for add_listener

Instance Method Summary collapse

Instance Method Details

#add_listener(listener) ⇒ Object



31
32
33
34
# File 'lib/pbox2d/box2d.rb', line 31

def add_listener(listener)
  # in combination with field accessor we can access protected world
  self.world.setContactListener(listener)
end

#defaultsObject



16
17
18
# File 'lib/pbox2d/box2d.rb', line 16

def defaults
  {scale: 10.0, gravity: [0, -10], warm: true, continuous: true} 
end

#gravity(args) ⇒ Object



27
28
29
# File 'lib/pbox2d/box2d.rb', line 27

def gravity(args)
  change_gravity(args.to_java(Java::float))
end

#init_options(args = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/pbox2d/box2d.rb', line 7

def init_options(args = {})
  args = defaults.merge(args)
  set_options(args[:scale],
              args[:gravity].to_java(Java::float),
              args[:warm],
              args[:continuous]
             )
end

#step_options(args = {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/pbox2d/box2d.rb', line 20

def step_options(args = {})
  time_step = args.fetch(:time_step, 1.0 / 60)
  velocity = args.fetch(:velocity_iter, 8)
  position = args.fetch(:position_iter, 10)
  set_step(time_step, velocity, position)
end

#versionObject



36
37
38
# File 'lib/pbox2d/box2d.rb', line 36

def version
  format('pbox2d version %s', Pbox2D::VERSION)
end