pbox2d 0.5.0-java → 0.6.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/CONTRIBUTING.md +0 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/examples/bumpy_surface_noise.rb +1 -3
- data/examples/collision_listening.rb +1 -2
- data/examples/distance_joint/boundary.rb +1 -1
- data/examples/distance_joint/distance_joint.rb +1 -2
- data/examples/distance_joint/particle_system.rb +2 -2
- data/examples/lib/boundary.rb +4 -3
- data/examples/lib/box.rb +2 -3
- data/examples/lib/custom_shape.rb +0 -2
- data/examples/lib/particle.rb +3 -3
- data/examples/lib/particle_system.rb +14 -13
- data/examples/lib/shape_system.rb +7 -7
- data/examples/lib/surface.rb +5 -5
- data/examples/liquid_fun_test.rb +5 -7
- data/examples/liquidy.rb +5 -7
- data/examples/mouse_joint/boundary.rb +2 -2
- data/examples/mouse_joint/box.rb +1 -1
- data/examples/mouse_joint/dummy_spring.rb +1 -1
- data/examples/mouse_joint/mouse_joint.rb +6 -3
- data/examples/polygons.rb +1 -3
- data/examples/quick_test.rb +32 -28
- data/examples/revolute_joint/box.rb +3 -3
- data/examples/revolute_joint/revolute_joint.rb +3 -3
- data/examples/revolute_joint/windmill.rb +8 -8
- data/examples/test_contact/lib/boundary.rb +2 -2
- data/examples/test_contact/test_contact.rb +6 -3
- data/lib/pbox2d.rb +34 -5
- data/lib/pbox2d/box2d.rb +2 -2
- data/lib/pbox2d/version.rb +2 -1
- data/pbox2d.gemspec +4 -4
- data/pom.xml +6 -48
- metadata +4 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b3b3f0c237c5cf38c10b625751a518d36d692f2
|
4
|
+
data.tar.gz: 28aa8334e4f84613d0743949cd4f67b031612c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2857f66b9284572a9259d40e75db177eebc48c722eaabb84cf7a4241f0f601b12e172f009482d5ea2c78df5927d2c259993461376a92da58415d94b4752cbb3d
|
7
|
+
data.tar.gz: 4fec10358a5a1b97cd0cda88523593a755f9a0fd44b2288cc15a1fe7de2106633c4db58c7be77e044de7c3295833a1d39cd1e78577fe3b363dd92380b9d7ed30
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
### v0.
|
1
|
+
### v0.6.0
|
2
|
+
|
3
|
+
Added import for jbox2d Particle, ParticleGroup etc (see PB module). Introduced WorldBuilder module to get rid of boilerplate code for the user. Reworked examples to use a common Boundary class.
|
4
|
+
|
5
|
+
### v0.5.0
|
2
6
|
|
3
7
|
Break compatability with ruby-processing. New build uses maven. Works with JRuby-9.0.3.0, processing-3.0.1 and jdk8.
|
4
8
|
|
data/CONTRIBUTING.md
CHANGED
@@ -17,7 +17,6 @@ already been submitted. When submitting a bug report, ideally include a [Gist][]
|
|
17
17
|
that includes a stack trace and any details that may be necessary to reproduce
|
18
18
|
the bug, including your gem version, Ruby version, and operating system.
|
19
19
|
|
20
|
-
|
21
20
|
## Submitting a Pull Request
|
22
21
|
1. [Fork the repository.][fork]
|
23
22
|
2. [Submit a pull request.][pr]
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### Using JBox2D in ruby-processing
|
2
2
|
|
3
|
-
Here we demonstrate how to use JBox2D library as a rubygem. This approach could be an exemplar of how to use other processing/java libraries with both ruby-processing and JRubyArt.
|
3
|
+
Here we demonstrate how to use JBox2D library as a rubygem. This approach could be an exemplar of how to use other processing/java libraries with both ruby-processing and JRubyArt (now using a maven build).
|
4
4
|

|
5
5
|
|
6
6
|
|
data/Rakefile
CHANGED
@@ -10,9 +10,7 @@ attr_reader :srface, :box2d, :particles
|
|
10
10
|
def setup
|
11
11
|
sketch_title 'Bumpy Surface Noise'
|
12
12
|
# Initialize box2d physics and create the world
|
13
|
-
@box2d =
|
14
|
-
box2d.init_options(gravity: [0, -20])
|
15
|
-
box2d.create_world
|
13
|
+
@box2d = WorldBuilder.build(app: self, gravity: [0, -20])
|
16
14
|
# to later set a custom gravity
|
17
15
|
# box2d.gravity([0, -20])
|
18
16
|
# Create the empty list
|
@@ -14,8 +14,7 @@ end
|
|
14
14
|
|
15
15
|
def setup
|
16
16
|
sketch_title 'Collision Listening'
|
17
|
-
@box2d =
|
18
|
-
box2d.create_world
|
17
|
+
@box2d = WorldBuilder.build(app: self)
|
19
18
|
box2d.add_listener(CustomListener.new)
|
20
19
|
@particles = []
|
21
20
|
@wall = Boundary.new(box2d, Vect.new(width / 2, height - 5), Vect.new(width, 10))
|
data/examples/lib/boundary.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# Re-usable Boundary class
|
1
2
|
class Boundary
|
2
3
|
include Processing::Proxy
|
3
4
|
attr_reader :box2d, :b, :pos, :size, :a
|
4
|
-
|
5
|
+
|
5
6
|
def initialize(b2d, pos, sz, a = 0)
|
6
7
|
@box2d, @pos, @size, @a = b2d, pos, sz, a
|
7
8
|
# Define the polygon
|
@@ -21,7 +22,7 @@ class Boundary
|
|
21
22
|
b.create_fixture(sd, 1)
|
22
23
|
end
|
23
24
|
|
24
|
-
# Draw the boundary, it doesn't move so we don't
|
25
|
+
# Draw the boundary, it doesn't move so we don't ask for location
|
25
26
|
def display
|
26
27
|
fill(0)
|
27
28
|
stroke(0)
|
@@ -31,7 +32,7 @@ class Boundary
|
|
31
32
|
push_matrix
|
32
33
|
translate(pos.x, pos.y)
|
33
34
|
rotate(-a)
|
34
|
-
rect(0, 0, size.x,size.y)
|
35
|
+
rect(0, 0, size.x, size.y)
|
35
36
|
pop_matrix
|
36
37
|
end
|
37
38
|
end
|
data/examples/lib/box.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# A Box class, note how to access class ParticleGroupDef in jruby
|
2
|
-
# which is imported
|
2
|
+
# which is imported to PB module to avoid namespace clashes
|
3
3
|
class Box
|
4
|
-
attr_accessor :pg
|
5
4
|
def initialize(b2d, x, y)
|
6
5
|
w = rand(1..3)
|
7
6
|
h = rand(1..3)
|
@@ -10,6 +9,6 @@ class Box
|
|
10
9
|
shape.setAsBox(w, h, pos, 0)
|
11
10
|
pd = PB::ParticleGroupDef.new
|
12
11
|
pd.shape = shape
|
13
|
-
|
12
|
+
b2d.world.create_particle_group(pd)
|
14
13
|
end
|
15
14
|
end
|
data/examples/lib/particle.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
# when two particles collide (no change just hitting boundary)
|
3
3
|
class Particle
|
4
4
|
extend Forwardable
|
5
|
-
def_delegators(:@app, :box2d, :begin_shape, :color, :end_shape, :line,
|
6
|
-
:ellipse, :translate, :rotate, :stroke,
|
7
|
-
:no_fill, :stroke_weight)
|
5
|
+
def_delegators(:@app, :box2d, :begin_shape, :color, :end_shape, :line,
|
6
|
+
:pop_matrix, :ellipse, :translate, :rotate, :stroke,
|
7
|
+
:push_matrix, :fill, :no_fill, :stroke_weight)
|
8
8
|
attr_accessor :body
|
9
9
|
attr_reader :radius, :col
|
10
10
|
|
@@ -2,11 +2,12 @@ require 'forwardable'
|
|
2
2
|
|
3
3
|
module Runnable
|
4
4
|
def run
|
5
|
-
reject!
|
6
|
-
each
|
5
|
+
reject!(&:done)
|
6
|
+
each(&:display)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
# Not be confused with the jbox2d ParticleSystem
|
10
11
|
class ParticleSystem
|
11
12
|
include Enumerable, Runnable
|
12
13
|
extend Forwardable
|
@@ -14,15 +15,15 @@ class ParticleSystem
|
|
14
15
|
def_delegator(:@particles, :empty?, :dead?)
|
15
16
|
|
16
17
|
attr_reader :x, :y
|
17
|
-
|
18
|
+
|
18
19
|
def initialize(bd, num, x, y)
|
19
20
|
@particles = [] # Initialize the Array
|
20
|
-
@x, @y = x, y # Store the origin point
|
21
|
+
@x, @y = x, y # Store the origin point
|
21
22
|
num.times do
|
22
23
|
self << Particle.new(bd, x, y)
|
23
24
|
end
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
def add_particles(bd, n)
|
27
28
|
n.times do
|
28
29
|
self << Particle.new(bd, x, y)
|
@@ -37,9 +38,9 @@ class Particle
|
|
37
38
|
include Processing::Proxy
|
38
39
|
TRAIL_SIZE = 6
|
39
40
|
# We need to keep track of a Body
|
40
|
-
|
41
|
+
|
41
42
|
attr_reader :trail, :body, :box2d
|
42
|
-
|
43
|
+
|
43
44
|
# Constructor
|
44
45
|
def initialize(b2d, x, y)
|
45
46
|
@box2d = b2d
|
@@ -49,22 +50,22 @@ class Particle
|
|
49
50
|
# This way we have collisions, but they don't overwhelm the system
|
50
51
|
make_body(x, y, 0.2)
|
51
52
|
end
|
52
|
-
|
53
|
+
|
53
54
|
# This function removes the particle from the box2d world
|
54
55
|
def kill_body
|
55
56
|
box2d.destroy_body(body)
|
56
57
|
end
|
57
|
-
|
58
|
+
|
58
59
|
# Is the particle ready for deletion?
|
59
60
|
def done
|
60
61
|
# Let's find the screen position of the particle
|
61
62
|
pos = box2d.body_coord(body)
|
62
63
|
# Is it off the bottom of the screen?
|
63
|
-
return false unless
|
64
|
+
return false unless pos.y > box2d.height + 20
|
64
65
|
kill_body
|
65
66
|
true
|
66
67
|
end
|
67
|
-
|
68
|
+
|
68
69
|
# Drawing the box
|
69
70
|
def display
|
70
71
|
# We look at each body and get its screen position
|
@@ -84,7 +85,7 @@ class Particle
|
|
84
85
|
end
|
85
86
|
end_shape
|
86
87
|
end
|
87
|
-
|
88
|
+
|
88
89
|
# This function adds the rectangle to the box2d world
|
89
90
|
def make_body(x, y, r)
|
90
91
|
# Define and create the body
|
@@ -100,7 +101,7 @@ class Particle
|
|
100
101
|
fd = FixtureDef.new
|
101
102
|
fd.shape = cs
|
102
103
|
fd.density = 1
|
103
|
-
fd.friction = 0
|
104
|
+
fd.friction = 0 # Slippery when wet!
|
104
105
|
fd.restitution = 0.5
|
105
106
|
# We could use this if we want to turn collisions off
|
106
107
|
# cd.filter.groupIndex = -10
|
@@ -1,25 +1,25 @@
|
|
1
|
+
# custom runnable module
|
1
2
|
module Runnable
|
2
3
|
def run
|
3
|
-
reject!
|
4
|
-
each
|
4
|
+
reject!(&:done)
|
5
|
+
each(&:display)
|
5
6
|
end
|
6
7
|
end
|
7
8
|
|
9
|
+
# using forwardable to make a custom enumerable
|
8
10
|
class ShapeSystem
|
9
11
|
include Enumerable, Runnable
|
10
12
|
extend Forwardable
|
11
13
|
def_delegators(:@polygons, :each, :reject!, :<<)
|
12
14
|
|
13
15
|
attr_reader :bd
|
14
|
-
|
16
|
+
|
15
17
|
def initialize(bd)
|
16
18
|
@bd = bd
|
17
|
-
@polygons = []
|
19
|
+
@polygons = [] # Initialize the Array
|
18
20
|
end
|
19
|
-
|
21
|
+
|
20
22
|
def add_polygon(x, y)
|
21
23
|
self << CustomShape.new(bd, x, y)
|
22
24
|
end
|
23
25
|
end
|
24
|
-
|
25
|
-
|
data/examples/lib/surface.rb
CHANGED
@@ -56,9 +56,9 @@ class Surface
|
|
56
56
|
stroke(0)
|
57
57
|
fill(135, 206, 250)
|
58
58
|
begin_shape
|
59
|
-
vertex(width, 0)
|
60
|
-
surface.map { |v| vertex(v.x, v.y) }
|
61
|
-
vertex(0, 0)
|
59
|
+
vertex(width, 0) # extra vertices so we can fill sky
|
60
|
+
surface.map { |v| vertex(v.x, v.y) } # the mountain range
|
61
|
+
vertex(0, 0) # extra vertices so we can fill sky
|
62
62
|
end_shape
|
63
63
|
end
|
64
64
|
end
|
@@ -100,7 +100,7 @@ class Particle
|
|
100
100
|
# Get its angle of rotation
|
101
101
|
a = body.get_angle
|
102
102
|
push_matrix
|
103
|
-
translate(pos.x,
|
103
|
+
translate(pos.x, pos.y)
|
104
104
|
rotate(-a)
|
105
105
|
fill(175)
|
106
106
|
stroke(0)
|
@@ -133,4 +133,4 @@ class Particle
|
|
133
133
|
body.set_linear_velocity(Vec2.new(rand(-10..10), rand(5..10)))
|
134
134
|
body.set_angular_velocity(rand(-10..10))
|
135
135
|
end
|
136
|
-
end
|
136
|
+
end
|
data/examples/liquid_fun_test.rb
CHANGED
@@ -11,11 +11,13 @@ attr_reader :boxes, :boundaries, :box2d
|
|
11
11
|
|
12
12
|
Vect = Struct.new(:x, :y)
|
13
13
|
|
14
|
+
def settings
|
15
|
+
size(640, 360, P2D)
|
16
|
+
end
|
17
|
+
|
14
18
|
def setup
|
15
19
|
sketch_title 'Liquid Fun Test'
|
16
|
-
@box2d =
|
17
|
-
box2d.init_options(gravity: [0, -10])
|
18
|
-
box2d.create_world
|
20
|
+
@box2d = WorldBuilder.build(app: self)
|
19
21
|
@boxes = []
|
20
22
|
box2d.world.set_particle_radius(0.15)
|
21
23
|
box2d.world.set_particle_damping(0.2)
|
@@ -43,7 +45,3 @@ def draw
|
|
43
45
|
fill(0)
|
44
46
|
text(format('f.p.s %d', frame_rate), 10, 60)
|
45
47
|
end
|
46
|
-
|
47
|
-
def settings
|
48
|
-
size(640, 360, P2D)
|
49
|
-
end
|
data/examples/liquidy.rb
CHANGED
@@ -5,11 +5,13 @@ attr_reader :box2d, :boundaries, :systems
|
|
5
5
|
|
6
6
|
Vect = Struct.new(:x, :y)
|
7
7
|
|
8
|
+
def settings
|
9
|
+
size(400, 300)
|
10
|
+
end
|
11
|
+
|
8
12
|
def setup
|
9
13
|
sketch_title 'Liquidy'
|
10
|
-
@box2d =
|
11
|
-
box2d.init_options(gravity: [0, -20])
|
12
|
-
box2d.create_world
|
14
|
+
@box2d = WorldBuilder.build(app: self, gravity: [0, -20])
|
13
15
|
@systems = []
|
14
16
|
@boundaries = [
|
15
17
|
Boundary.new(box2d, Vect.new(50, 100), Vect.new(300, 5), -0.3),
|
@@ -34,7 +36,3 @@ def mouse_pressed
|
|
34
36
|
# Add a new Particle System whenever the mouse is clicked
|
35
37
|
systems << ParticleSystem.new(box2d, 0, mouse_x, mouse_y)
|
36
38
|
end
|
37
|
-
|
38
|
-
def settings
|
39
|
-
size(400,300)
|
40
|
-
end
|
@@ -30,13 +30,13 @@ class Boundary
|
|
30
30
|
b.create_fixture(sd, 1)
|
31
31
|
end
|
32
32
|
|
33
|
-
# Draw the boundary, if it were at an angle we'd have to do something
|
33
|
+
# Draw the boundary, if it were at an angle we'd have to do something fancy
|
34
34
|
def display
|
35
35
|
no_fill
|
36
36
|
stroke(127)
|
37
37
|
fill(127)
|
38
38
|
stroke_weight(1)
|
39
|
-
rect_mode(Java::ProcessingCore::CENTER)
|
39
|
+
rect_mode(Java::ProcessingCore::PConstants::CENTER)
|
40
40
|
a = b.get_angle
|
41
41
|
push_matrix
|
42
42
|
translate(x, y)
|
data/examples/mouse_joint/box.rb
CHANGED
@@ -14,11 +14,14 @@ require 'forwardable'
|
|
14
14
|
# A reference to our box2d world
|
15
15
|
attr_reader :box2d, :boundaries, :box, :spring
|
16
16
|
|
17
|
-
def
|
17
|
+
def settings
|
18
18
|
size(640, 360)
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
sketch_title 'Mouse Joint'
|
19
23
|
# Initialize box2d physics and create the world
|
20
|
-
@box2d =
|
21
|
-
box2d.create_world
|
24
|
+
@box2d = WorldBuilder.build(app: self)
|
22
25
|
# Make the box
|
23
26
|
@box = Box.new(width / 2, height / 2)
|
24
27
|
# Make a dummy spring
|
data/examples/polygons.rb
CHANGED
@@ -11,9 +11,7 @@ Vect = Struct.new(:x, :y)
|
|
11
11
|
def setup
|
12
12
|
sketch_title 'Polygons'
|
13
13
|
smooth
|
14
|
-
@box2d =
|
15
|
-
box2d.init_options(gravity: [0, -20])
|
16
|
-
box2d.create_world
|
14
|
+
@box2d = WorldBuilder.build(app: self, gravity: [0, -20])
|
17
15
|
@system = ShapeSystem.new self
|
18
16
|
@boundaries = [
|
19
17
|
Boundary.new(box2d, Vect.new(width / 4, height - 5), Vect.new(width / 2 - 50, 10)),
|
data/examples/quick_test.rb
CHANGED
@@ -9,34 +9,42 @@ java_alias :stroke_int, :stroke, [Java::int]
|
|
9
9
|
|
10
10
|
Vect = Struct.new(:x, :y)
|
11
11
|
|
12
|
+
def settings
|
13
|
+
size(400, 300)
|
14
|
+
end
|
15
|
+
|
12
16
|
def setup
|
13
17
|
sketch_title 'Quick Test'
|
14
|
-
stroke_int(0)
|
18
|
+
stroke_int(0) # set stroke this way to avoid overload warnings
|
15
19
|
srand(5)
|
16
20
|
# Initialize box2d physics and create the world
|
17
|
-
@box2d =
|
21
|
+
@box2d = WorldBuilder.build(applet: self, scale: 10, gravity: [0, -20.0])
|
18
22
|
puts box2d.version # print out version of pbox2d gem in use
|
19
|
-
|
20
|
-
box2d.
|
21
|
-
#
|
22
|
-
# box2d.gravity(0, -20)
|
23
|
-
# Create ArrayLists
|
23
|
+
# To later set a custom gravity
|
24
|
+
# box2d.gravity(0, -20)
|
25
|
+
# Create ArrayLists
|
24
26
|
@boxes = []
|
25
27
|
@boundaries = [
|
26
|
-
Boundary.new(
|
27
|
-
|
28
|
+
Boundary.new(
|
29
|
+
box2d,
|
30
|
+
Vect.new(width / 4, height - 5),
|
31
|
+
Vect.new(width / 2 - 50, 10)),
|
32
|
+
Boundary.new(
|
33
|
+
box2d,
|
34
|
+
Vect.new(3 * width / 4, height - 50),
|
35
|
+
Vect.new(width / 2 - 50, 10))
|
28
36
|
]
|
29
37
|
end
|
30
38
|
|
31
39
|
def draw
|
32
|
-
background_int(255) # set background this way to avoid overload warnings
|
40
|
+
background_int(255) # set background this way to avoid overload warnings
|
33
41
|
# Boxes fall from the top every so often
|
34
42
|
boxes << Box.new(box2d, width / 2, 30) if rand < 0.99
|
35
|
-
boundaries.each(&:display)
|
36
|
-
boxes.each(&:display)
|
37
|
-
# Boxes that leave the screen, we delete them note they have to be deleted
|
38
|
-
# from both the box2d world and locally
|
39
|
-
boxes.reject!(&:done)
|
43
|
+
boundaries.each(&:display)
|
44
|
+
boxes.each(&:display)
|
45
|
+
# Boxes that leave the screen, we delete them note they have to be deleted
|
46
|
+
# from both the box2d world and locally
|
47
|
+
boxes.reject!(&:done)
|
40
48
|
exit if frame_count >= 908
|
41
49
|
end
|
42
50
|
|
@@ -45,7 +53,7 @@ class Box
|
|
45
53
|
include Processing::Proxy
|
46
54
|
# We need to keep track of a Body and a width and height
|
47
55
|
attr_reader :box2d, :body, :w, :h
|
48
|
-
|
56
|
+
|
49
57
|
# Constructor
|
50
58
|
def initialize(b2d, x, y)
|
51
59
|
@w = rand(4..16)
|
@@ -54,7 +62,7 @@ class Box
|
|
54
62
|
# Add the box to the box2d world
|
55
63
|
make_body(Vec2.new(x, y), w, h)
|
56
64
|
end
|
57
|
-
|
65
|
+
|
58
66
|
def done
|
59
67
|
# Let's find the screen position of the particle
|
60
68
|
pos = box2d.body_coord(body)
|
@@ -63,13 +71,13 @@ class Box
|
|
63
71
|
box2d.destroy_body(body)
|
64
72
|
true
|
65
73
|
end
|
66
|
-
|
74
|
+
|
67
75
|
# Drawing the box
|
68
76
|
def display
|
69
77
|
# We look at each body and get its screen position
|
70
78
|
pos = box2d.body_coord(body)
|
71
79
|
# Get its angle of rotation
|
72
|
-
a = body.angle
|
80
|
+
a = body.angle
|
73
81
|
rect_mode(CENTER)
|
74
82
|
push_matrix
|
75
83
|
translate(pos.x, pos.y)
|
@@ -78,25 +86,25 @@ class Box
|
|
78
86
|
rect(0, 0, w, h)
|
79
87
|
pop_matrix
|
80
88
|
end
|
81
|
-
|
89
|
+
|
82
90
|
# This function adds the rectangle to the box2d world
|
83
|
-
def make_body(center, w, h)
|
91
|
+
def make_body(center, w, h)
|
84
92
|
# Define a polygon (this is what we use for a rectangle)
|
85
93
|
sd = PolygonShape.new
|
86
94
|
box2d_w = box2d.scale_to_world(w / 2)
|
87
95
|
box2d_h = box2d.scale_to_world(h / 2)
|
88
|
-
sd.setAsBox(box2d_w, box2d_h)
|
96
|
+
sd.setAsBox(box2d_w, box2d_h)
|
89
97
|
# Define a fixture
|
90
98
|
fd = FixtureDef.new
|
91
99
|
fd.shape = sd
|
92
100
|
# Parameters that affect physics
|
93
101
|
fd.density = 1
|
94
102
|
fd.friction = 0.3
|
95
|
-
fd.restitution = 0.5
|
103
|
+
fd.restitution = 0.5
|
96
104
|
# Define the body and make it from the shape
|
97
105
|
bd = BodyDef.new
|
98
106
|
bd.type = BodyType::DYNAMIC
|
99
|
-
bd.position.set(box2d.processing_to_world(center))
|
107
|
+
bd.position.set(box2d.processing_to_world(center))
|
100
108
|
cs = CircleShape.new
|
101
109
|
@body = box2d.create_body(bd)
|
102
110
|
body.create_fixture(fd)
|
@@ -105,7 +113,3 @@ class Box
|
|
105
113
|
body.setAngularVelocity(rand(-5.0..5))
|
106
114
|
end
|
107
115
|
end
|
108
|
-
|
109
|
-
def settings
|
110
|
-
size(400,300)
|
111
|
-
end
|
@@ -39,7 +39,7 @@ class Box
|
|
39
39
|
body.createFixture(fd)
|
40
40
|
|
41
41
|
# Give it some initial random velocity
|
42
|
-
body.setLinearVelocity(Vec2.new(rand(-5..5),rand(2..5)))
|
42
|
+
body.setLinearVelocity(Vec2.new(rand(-5..5), rand(2..5)))
|
43
43
|
body.setAngularVelocity(rand(-5..5))
|
44
44
|
end
|
45
45
|
|
@@ -57,12 +57,12 @@ class Box
|
|
57
57
|
|
58
58
|
rect_mode(Java::ProcessingCore::PConstants::CENTER)
|
59
59
|
push_matrix
|
60
|
-
translate(pos.x,pos.y)
|
60
|
+
translate(pos.x, pos.y)
|
61
61
|
rotate(-a)
|
62
62
|
fill(127)
|
63
63
|
stroke(0)
|
64
64
|
stroke_weight(2)
|
65
|
-
rect(0,0,w,h)
|
65
|
+
rect(0, 0, w, h)
|
66
66
|
pop_matrix
|
67
67
|
end
|
68
68
|
end
|
@@ -11,13 +11,12 @@ require_relative 'particle_system'
|
|
11
11
|
attr_reader :box2d, :windmill, :system
|
12
12
|
|
13
13
|
def settings
|
14
|
-
size(640,360)
|
14
|
+
size(640, 360)
|
15
15
|
end
|
16
16
|
|
17
17
|
def setup
|
18
18
|
sketch_title 'Revolute Joint'
|
19
|
-
@box2d =
|
20
|
-
box2d.createWorld
|
19
|
+
@box2d = WorldBuilder.build(app: self)
|
21
20
|
@windmill = Windmill.new(width / 2, 175)
|
22
21
|
@system = ParticleSystem.new
|
23
22
|
end
|
@@ -37,3 +36,4 @@ def draw
|
|
37
36
|
fill(0)
|
38
37
|
text(format("Click mouse to toggle motor.\nMotor: %s", status), 10, height - 30)
|
39
38
|
end
|
39
|
+
|
@@ -11,7 +11,7 @@ class Windmill
|
|
11
11
|
# Our object is two boxes and one joint
|
12
12
|
# Consider making the fixed box much smaller and not drawing it
|
13
13
|
attr_reader :joint, :box1, :box2
|
14
|
-
|
14
|
+
|
15
15
|
def initialize(x, y)
|
16
16
|
@app = $app
|
17
17
|
# Initialize locations of two boxes
|
@@ -22,25 +22,25 @@ class Windmill
|
|
22
22
|
# NB: using java_send to access the unreachable 'initialize' method
|
23
23
|
rjd.java_send :initialize, [Body, Body, Vec2], box1.body, box2.body, box1.body.getWorldCenter
|
24
24
|
# Turning on a motor (optional)
|
25
|
-
rjd.motorSpeed = Math::PI * 2
|
25
|
+
rjd.motorSpeed = Math::PI * 2 # how fast?
|
26
26
|
rjd.maxMotorTorque = 1000.0 # how powerful?
|
27
|
-
rjd.enableMotor = false
|
27
|
+
rjd.enableMotor = false # is it on?
|
28
28
|
# There are many other properties you can set for a Revolute joint
|
29
29
|
# For example, you can limit its angle between a minimum and a maximum
|
30
|
-
# See box2d manual for more
|
30
|
+
# See box2d manual for more
|
31
31
|
# Create the joint
|
32
32
|
@joint = box2d.world.createJoint(rjd)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
# Turn the motor on or off
|
36
36
|
def toggle_motor
|
37
37
|
joint.enableMotor(!joint.isMotorEnabled)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def motor_on?
|
41
41
|
joint.isMotorEnabled
|
42
|
-
end
|
43
|
-
|
42
|
+
end
|
43
|
+
|
44
44
|
def display
|
45
45
|
box2.display
|
46
46
|
box1.display
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
|
-
CENTER ||= Java::ProcessingCore::CENTER
|
3
|
+
CENTER ||= Java::ProcessingCore::PConstants::CENTER
|
4
4
|
# The boundary class is used to create a floor in this
|
5
5
|
# sketch. Note it does not have a change method
|
6
6
|
class Boundary
|
@@ -23,7 +23,7 @@ class Boundary
|
|
23
23
|
b.set_user_data(self)
|
24
24
|
end
|
25
25
|
|
26
|
-
# Draw the boundary, if it were at an angle we'd have to do something
|
26
|
+
# Draw the boundary, if it were at an angle we'd have to do something fancy
|
27
27
|
def display
|
28
28
|
fill(0)
|
29
29
|
stroke(0)
|
@@ -6,10 +6,13 @@ require_relative 'lib/boundary'
|
|
6
6
|
|
7
7
|
attr_reader :box2d, :particles, :wall
|
8
8
|
|
9
|
-
def
|
9
|
+
def settings
|
10
10
|
size 400, 400
|
11
|
-
|
12
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup
|
14
|
+
sketch_title 'Test Contact'
|
15
|
+
@box2d = WorldBuilder.build(app: self)
|
13
16
|
box2d.add_listener(CustomListener.new)
|
14
17
|
@particles = []
|
15
18
|
@wall = Boundary.new(self, width / 2, height - 5, width, 10)
|
data/lib/pbox2d.rb
CHANGED
@@ -7,7 +7,7 @@ end
|
|
7
7
|
ContactListener = Java::OrgJbox2dCallbacks::ContactListener
|
8
8
|
|
9
9
|
def import_class_list(list, string)
|
10
|
-
list.each { |
|
10
|
+
list.each { |d| java_import format(string, d) }
|
11
11
|
end
|
12
12
|
|
13
13
|
common = %w( Vec2 Transform )
|
@@ -19,15 +19,44 @@ import_class_list(shape, shape_format)
|
|
19
19
|
world = %w( Body BodyDef BodyType World FixtureDef )
|
20
20
|
world_format = 'org.jbox2d.dynamics.%s'
|
21
21
|
import_class_list(world, world_format)
|
22
|
-
joint = %w(
|
22
|
+
joint = %w(
|
23
|
+
Joint
|
24
|
+
JointDef
|
25
|
+
DistanceJointDef
|
26
|
+
RevoluteJoint
|
27
|
+
RevoluteJointDef
|
28
|
+
MouseJointDef
|
29
|
+
)
|
23
30
|
joint_format = 'org.jbox2d.dynamics.joints.%s'
|
24
31
|
import_class_list(joint, joint_format)
|
32
|
+
|
33
|
+
# Import into module namespace to avoid likely clashes
|
25
34
|
module PB
|
26
|
-
particle = %w(
|
27
|
-
|
28
|
-
|
35
|
+
particle = %w(
|
36
|
+
ParticleColor
|
37
|
+
ParticleContact
|
38
|
+
ParticleGroupDef
|
39
|
+
ParticleBodyContact
|
40
|
+
ParticleGroup
|
41
|
+
ParticleType
|
42
|
+
ParticleGroupType
|
43
|
+
ParticleGroupDef
|
44
|
+
ParticleSystem
|
45
|
+
StackQueue
|
46
|
+
VoronoiDiagram
|
47
|
+
)
|
29
48
|
particle_format = 'org.jbox2d.particle.%s'
|
30
49
|
import_class_list(particle, particle_format)
|
31
50
|
end
|
32
51
|
|
33
52
|
require_relative 'pbox2d/box2d.rb'
|
53
|
+
|
54
|
+
# Box2D factory
|
55
|
+
module WorldBuilder
|
56
|
+
def self.build(app:, **opts)
|
57
|
+
b2d = Box2D.new(app)
|
58
|
+
b2d.init_options(opts)
|
59
|
+
b2d.create_world
|
60
|
+
b2d
|
61
|
+
end
|
62
|
+
end
|
data/lib/pbox2d/box2d.rb
CHANGED
@@ -23,7 +23,7 @@ class Box2D < Java::ProcessingBox2d::Box2DProcessing
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def default_step
|
26
|
-
{ time_step: 1.0 / 60, velocity_iter: 8, position_iter: 10
|
26
|
+
{ time_step: 1.0 / 60, velocity_iter: 8, position_iter: 10 }
|
27
27
|
end
|
28
28
|
|
29
29
|
def gravity(args)
|
@@ -32,7 +32,7 @@ class Box2D < Java::ProcessingBox2d::Box2DProcessing
|
|
32
32
|
|
33
33
|
def add_listener(listener)
|
34
34
|
# in combination with field accessor we can access protected world
|
35
|
-
|
35
|
+
world.setContactListener(listener)
|
36
36
|
end
|
37
37
|
|
38
38
|
def version
|
data/lib/pbox2d/version.rb
CHANGED
data/pbox2d.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'pbox2d/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'pbox2d'
|
8
8
|
spec.version = Pbox2d::VERSION
|
9
|
-
spec.license = '
|
9
|
+
spec.license = 'BSD-2-Clause'
|
10
10
|
spec.has_rdoc = true
|
11
11
|
spec.extra_rdoc_files = ['README.md', 'LICENSE.md']
|
12
12
|
spec.authors = ['Martin Prout']
|
@@ -26,8 +26,8 @@ EOF
|
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency "minitest", "~> 5.8"
|
28
28
|
spec.platform='java'
|
29
|
-
spec.requirements << 'A decent graphics card'
|
30
|
-
spec.requirements << 'java runtime >= 1.8+'
|
31
|
-
spec.requirements << 'processing = 3.0.1+'
|
29
|
+
# spec.requirements << 'A decent graphics card'
|
30
|
+
# spec.requirements << 'java runtime >= 1.8+'
|
31
|
+
# spec.requirements << 'processing = 3.0.1+'
|
32
32
|
spec.requirements << 'maven = 3.3.3'
|
33
33
|
end
|
data/pom.xml
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
<modelVersion>4.0.0</modelVersion>
|
4
4
|
<groupId>org.ruby-processing</groupId>
|
5
5
|
<artifactId>box2d</artifactId>
|
6
|
-
<version>0.
|
6
|
+
<version>0.6.0</version>
|
7
7
|
<packaging>jar</packaging>
|
8
8
|
<description>
|
9
9
|
jbox2d-library for JRubyArt
|
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
<licenses>
|
30
30
|
<license>
|
31
|
-
<name>
|
31
|
+
<name>BSD-2-clause</name>
|
32
32
|
<url>http://www.opensource.org/licenses/bsd-license.php</url>
|
33
33
|
</license>
|
34
34
|
</licenses>
|
@@ -46,6 +46,8 @@
|
|
46
46
|
<groupId>org.jbox2d</groupId>
|
47
47
|
<artifactId>jbox2d-library</artifactId>
|
48
48
|
<version>2.3.1-SNAPSHOT</version>
|
49
|
+
<scope>system</scope>
|
50
|
+
<systemPath>${jbox2d.home}/jbox2d-library-2.3.1-SNAPSHOT.jar</systemPath>
|
49
51
|
</dependency>
|
50
52
|
<dependency>
|
51
53
|
<groupId>org.processing</groupId>
|
@@ -60,9 +62,10 @@
|
|
60
62
|
<maven.compiler.source>1.8</maven.compiler.source>
|
61
63
|
<maven.compiler.target>1.8</maven.compiler.target>
|
62
64
|
<!-- for Mac developers, non Archlinux and Windows can probably figure it out
|
63
|
-
<processing.home>/Applications/Processing.app/Contents/Java</processing.home>
|
65
|
+
<processing.home>/Applications/Processing.app/Contents/Java</processing.home>
|
64
66
|
-->
|
65
67
|
<processing.home>/usr/share/processing</processing.home>
|
68
|
+
<jbox2d.home>${user.home}/jbox2d/jbox2d-library/target</jbox2d.home>
|
66
69
|
</properties>
|
67
70
|
<build>
|
68
71
|
<sourceDirectory>src</sourceDirectory>
|
@@ -75,30 +78,6 @@
|
|
75
78
|
</extension>
|
76
79
|
</extensions>
|
77
80
|
<plugins>
|
78
|
-
<plugin>
|
79
|
-
<artifactId>maven-source-plugin</artifactId>
|
80
|
-
<version>2.2.1</version>
|
81
|
-
<executions>
|
82
|
-
<execution>
|
83
|
-
<id>attach-sources</id>
|
84
|
-
<goals>
|
85
|
-
<goal>jar</goal>
|
86
|
-
</goals>
|
87
|
-
</execution>
|
88
|
-
</executions>
|
89
|
-
</plugin>
|
90
|
-
<plugin>
|
91
|
-
<artifactId>maven-javadoc-plugin</artifactId>
|
92
|
-
<version>2.9</version>
|
93
|
-
<executions>
|
94
|
-
<execution>
|
95
|
-
<id>attach-javadocs</id>
|
96
|
-
<goals>
|
97
|
-
<goal>jar</goal>
|
98
|
-
</goals>
|
99
|
-
</execution>
|
100
|
-
</executions>
|
101
|
-
</plugin>
|
102
81
|
<plugin>
|
103
82
|
<artifactId>maven-compiler-plugin</artifactId>
|
104
83
|
<version>3.1</version>
|
@@ -120,27 +99,6 @@
|
|
120
99
|
<artifactId>maven-resources-plugin</artifactId>
|
121
100
|
<version>2.6</version>
|
122
101
|
</plugin>
|
123
|
-
<plugin>
|
124
|
-
<groupId>org.apache.maven.plugins</groupId>
|
125
|
-
<artifactId>maven-dependency-plugin</artifactId>
|
126
|
-
<version>2.10</version>
|
127
|
-
<executions>
|
128
|
-
<execution>
|
129
|
-
<id>default-cli</id>
|
130
|
-
<configuration>
|
131
|
-
<artifactItems>
|
132
|
-
<artifactItem>
|
133
|
-
<groupId>org.jbox2d</groupId>
|
134
|
-
<artifactId>jbox2d-library</artifactId>
|
135
|
-
<version>2.3.1-SNAPSHOT</version>
|
136
|
-
<type>jar</type>
|
137
|
-
<outputDirectory>lib</outputDirectory>
|
138
|
-
</artifactItem>
|
139
|
-
</artifactItems>
|
140
|
-
</configuration>
|
141
|
-
</execution>
|
142
|
-
</executions>
|
143
|
-
</plugin>
|
144
102
|
</plugins>
|
145
103
|
</build>
|
146
104
|
</project>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pbox2d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Martin Prout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jruby_art
|
@@ -119,7 +119,7 @@ files:
|
|
119
119
|
- src/processing/box2d/Step.java
|
120
120
|
homepage: https://github.com/ruby-processing/jbox2d
|
121
121
|
licenses:
|
122
|
-
-
|
122
|
+
- BSD-2-Clause
|
123
123
|
metadata: {}
|
124
124
|
post_install_message:
|
125
125
|
rdoc_options: []
|
@@ -136,12 +136,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
138
|
requirements:
|
139
|
-
- A decent graphics card
|
140
|
-
- java runtime >= 1.8+
|
141
|
-
- processing = 3.0.1+
|
142
139
|
- maven = 3.3.3
|
143
140
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.5.0
|
145
142
|
signing_key:
|
146
143
|
specification_version: 4
|
147
144
|
summary: jbox2d wrapped in a gem for JRubyArt
|