pbox2d 0.9.1-java → 1.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -5
  3. data/CHANGELOG.md +4 -0
  4. data/README.md +6 -6
  5. data/docs/.gitignore +6 -0
  6. data/docs/_classes/pbox2d.md +375 -0
  7. data/docs/_classes/world_builder.md +7 -0
  8. data/docs/_config.yml +32 -0
  9. data/docs/_includes/footer.html +55 -0
  10. data/docs/_includes/head.html +18 -0
  11. data/docs/_includes/header.html +27 -0
  12. data/docs/_includes/menu.html +8 -0
  13. data/docs/_includes/navigation.html +24 -0
  14. data/docs/_layouts/default.html +20 -0
  15. data/docs/_layouts/page.html +14 -0
  16. data/docs/_layouts/post.html +15 -0
  17. data/docs/_methods/init_options.md +28 -0
  18. data/docs/_methods/processing_to_world.md +29 -0
  19. data/docs/_methods/scale_to_processing.md +24 -0
  20. data/docs/_methods/scale_to_world.md +29 -0
  21. data/docs/_methods/step_options.md +25 -0
  22. data/docs/_methods/world_to_processing.md +30 -0
  23. data/docs/_modules/pb.md +25 -0
  24. data/docs/_modules/world_builder.md +26 -0
  25. data/docs/_posts/2016-10-14-welcome.md +183 -0
  26. data/docs/_sass/_base.scss +204 -0
  27. data/docs/_sass/_layout.scss +236 -0
  28. data/docs/_sass/_syntax-highlighting.scss +67 -0
  29. data/docs/about.md +20 -0
  30. data/docs/classes.html +9 -0
  31. data/docs/css/main.scss +52 -0
  32. data/docs/favicon.ico +0 -0
  33. data/docs/index.html +38 -0
  34. data/docs/methods.html +9 -0
  35. data/docs/modules.html +12 -0
  36. data/lib/pbox2d/version.rb +1 -1
  37. data/pbox2d.gemspec +4 -7
  38. data/pom.rb +8 -6
  39. data/pom.xml +3 -3
  40. data/src/org/jbox2d/collision/AABB.java +2 -2
  41. data/src/org/jbox2d/collision/Manifold.java +2 -2
  42. data/src/org/jbox2d/collision/ManifoldPoint.java +2 -2
  43. data/src/org/jbox2d/collision/shapes/MassData.java +1 -1
  44. data/src/org/jbox2d/common/Mat22.java +6 -13
  45. data/src/org/jbox2d/common/Mat33.java +253 -233
  46. data/src/org/jbox2d/common/MathUtils.java +5 -5
  47. data/src/org/jbox2d/common/Rot.java +16 -19
  48. data/src/org/jbox2d/common/Transform.java +4 -4
  49. data/src/org/jbox2d/common/Vec2.java +6 -12
  50. data/src/org/jbox2d/common/Vec3.java +147 -142
  51. data/src/org/jbox2d/dynamics/joints/DistanceJoint.java +4 -2
  52. metadata +62 -25
@@ -0,0 +1,183 @@
1
+ ---
2
+ layout: post
3
+ title: "Using pbox2d gem"
4
+ date: 2016-10-14 06:00:13
5
+ categories: jruby_art update
6
+ ---
7
+
8
+ You should have JRubyArt (or propane) and the pbox2d gem installed, from your sketch `require` pbox2d
9
+ ```ruby
10
+ require 'pbox2d'
11
+
12
+ # A list we'll use to track fixed objects
13
+ attr_reader :box2d, :boundaries, :boxes
14
+ ```
15
+ You then need to create an instance of `Box2D` in the setup
16
+ ```ruby
17
+ def setup
18
+ size(400,300)
19
+ @box2d = WorldBuilder.build(app: self, gravity: [0, -20])
20
+ ```
21
+
22
+ ### From sketch to physics world and vice versa
23
+
24
+ Because of the peculiar choice by the processing guys down is up (dimensions in pixels) jbox2d doesn't like to live in the pixel world (where up is really up), and prefers meters or feet and inches (whatever). What this means is that there is a need to scale between the two worlds using `world_to_processing` and `processing_to_world` [methods provided][methods]. You should study the included [example sketches][examples].
25
+
26
+ ### Example Sketch ###
27
+
28
+ ```ruby
29
+ require 'pbox2d'
30
+ require_relative 'lib/boundary'
31
+
32
+ # A list we'll use to track fixed objects
33
+ attr_reader :box2d, :boundaries, :boxes
34
+
35
+ java_alias :background_int, :background, [Java::int]
36
+ java_alias :stroke_int, :stroke, [Java::int]
37
+
38
+ Vect = Struct.new(:x, :y)
39
+
40
+ def setup
41
+ sketch_title 'Quick Test'
42
+ stroke_int(0) # set stroke this way to avoid overload warnings
43
+ srand(5)
44
+ # Initialize box2d physics and create the world
45
+ @box2d = WorldBuilder.build(app: self, scale: 10, gravity: [0, -20.0])
46
+ puts box2d.version
47
+ # Set a custom gravity
48
+ # box2d.gravity(0, -20)
49
+ # Create ArrayLists
50
+ @boxes = []
51
+ @boundaries = [
52
+ Boundary.new(box2d, Vect.new(width / 4, height - 5), Vect.new(width / 2 - 50, 10)),
53
+ Boundary.new(box2d, Vect.new(3 * width / 4, height - 50), Vect.new(width / 2 - 50, 10))
54
+ ]
55
+ end
56
+
57
+ def draw
58
+ background_int(255) # set background this way to avoid overload warnings
59
+ # Boxes fall from the top every so often
60
+ boxes << Box.new(box2d, width / 2, 30) if rand < 0.99
61
+ boundaries.each(&:display)
62
+ boxes.each(&:display)
63
+ # Boxes that leave the screen, we delete them note they have to be deleted
64
+ # from both the box2d world and locally
65
+ boxes.reject!(&:done)
66
+ exit if frame_count >= 908
67
+ end
68
+
69
+ # A rectangular box
70
+ class Box
71
+ include Processing::Proxy
72
+ # We need to keep track of a Body and a width and height
73
+ attr_reader :box2d, :body, :w, :h
74
+
75
+ # Constructor
76
+ def initialize(b2d, x, y)
77
+ @w = rand(4..16)
78
+ @h = rand(4..16)
79
+ @box2d = b2d
80
+ # Add the box to the box2d world
81
+ make_body(Vec2.new(x, y), w, h)
82
+ end
83
+
84
+ def done
85
+ # Let's find the screen position of the particle
86
+ pos = box2d.body_coord(body)
87
+ # Is it off the bottom of the screen?
88
+ return false unless (pos.y > box2d.height + w * h)
89
+ box2d.destroy_body(body)
90
+ true
91
+ end
92
+
93
+ # Drawing the box
94
+ def display
95
+ # We look at each body and get its screen position
96
+ pos = box2d.body_coord(body)
97
+ # Get its angle of rotation
98
+ a = body.angle
99
+ rect_mode(CENTER)
100
+ push_matrix
101
+ translate(pos.x, pos.y)
102
+ rotate(-a)
103
+ fill(175)
104
+ rect(0, 0, w, h)
105
+ pop_matrix
106
+ end
107
+
108
+ # This function adds the rectangle to the box2d world
109
+ def make_body(center, w, h)
110
+ # Define a polygon (this is what we use for a rectangle)
111
+ sd = PolygonShape.new
112
+ box2d_w = box2d.scale_to_world(w / 2)
113
+ box2d_h = box2d.scale_to_world(h / 2)
114
+ sd.setAsBox(box2d_w, box2d_h)
115
+ # Define a fixture
116
+ fd = FixtureDef.new
117
+ fd.shape = sd
118
+ # Parameters that affect physics
119
+ fd.density = 1
120
+ fd.friction = 0.3
121
+ fd.restitution = 0.5
122
+ # Define the body and make it from the shape
123
+ bd = BodyDef.new
124
+ bd.type = BodyType::DYNAMIC
125
+ bd.position.set(box2d.processing_to_world(center))
126
+ cs = CircleShape.new
127
+ @body = box2d.create_body(bd)
128
+ body.create_fixture(fd)
129
+ # Give it some initial random velocity
130
+ body.setLinearVelocity(Vec2.new(rand(-5.0..5), rand(2.0..5)))
131
+ body.setAngularVelocity(rand(-5.0..5))
132
+ end
133
+ end
134
+
135
+ def settings
136
+ size(400,300)
137
+ end
138
+ ```
139
+ The boundary classes
140
+
141
+ ```ruby
142
+ class Boundary
143
+ include Processing::Proxy
144
+ attr_reader :box2d, :b, :pos, :size, :a
145
+
146
+ def initialize(b2d, pos, sz, a = 0)
147
+ @box2d, @pos, @size, @a = b2d, pos, sz, a
148
+ # Define the polygon
149
+ sd = PolygonShape.new
150
+ # Figure out the box2d coordinates
151
+ box2d_w = box2d.scale_to_world(size.x / 2)
152
+ box2d_h = box2d.scale_to_world(size.y / 2)
153
+ # We're just a box
154
+ sd.set_as_box(box2d_w, box2d_h)
155
+ # Create the body
156
+ bd = BodyDef.new
157
+ bd.type = BodyType::STATIC
158
+ bd.angle = a
159
+ bd.position.set(box2d.processing_to_world(pos.x, pos.y))
160
+ @b = box2d.create_body(bd)
161
+ # Attached the shape to the body using a Fixture
162
+ b.create_fixture(sd, 1)
163
+ end
164
+
165
+ # Draw the boundary, it doesn't move so we don't have to ask the Body for location
166
+ def display
167
+ fill(0)
168
+ stroke(0)
169
+ stroke_weight(1)
170
+ rect_mode(CENTER)
171
+ a = b.get_angle
172
+ push_matrix
173
+ translate(pos.x, pos.y)
174
+ rotate(-a)
175
+ rect(0, 0, size.x,size.y)
176
+ pop_matrix
177
+ end
178
+ end
179
+ ```
180
+
181
+ [examples]:https://github.com/ruby-processing/JRubyArt-examples/tree/master/external_library/gem/pbox2d/
182
+ [methods]:{{ site.github.url }}/methods/methods/
183
+ [classes]:{{ site.github.url }}/classes/classes/
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Reset some basic elements
3
+ */
4
+ body, h1, h2, h3, h4, h5, h6,
5
+ p, blockquote, pre, hr,
6
+ dl, dd, ol, ul, figure {
7
+ margin: 0;
8
+ padding: 0;
9
+ }
10
+
11
+
12
+
13
+ /**
14
+ * Basic styling
15
+ */
16
+ body {
17
+ font-family: $base-font-family;
18
+ font-size: $base-font-size;
19
+ line-height: $base-line-height;
20
+ font-weight: 300;
21
+ color: $text-color;
22
+ background-color: $background-color;
23
+ -webkit-text-size-adjust: 100%;
24
+ }
25
+
26
+
27
+
28
+ /**
29
+ * Set `margin-bottom` to maintain vertical rhythm
30
+ */
31
+ h1, h2, h3, h4, h5, h6,
32
+ p, blockquote, pre,
33
+ ul, ol, dl, figure,
34
+ %vertical-rhythm {
35
+ margin-bottom: $spacing-unit / 2;
36
+ }
37
+
38
+
39
+
40
+ /**
41
+ * Images
42
+ */
43
+ img {
44
+ max-width: 100%;
45
+ vertical-align: middle;
46
+ }
47
+
48
+
49
+
50
+ /**
51
+ * Figures
52
+ */
53
+ figure > img {
54
+ display: block;
55
+ }
56
+
57
+ figcaption {
58
+ font-size: $small-font-size;
59
+ }
60
+
61
+
62
+
63
+ /**
64
+ * Lists
65
+ */
66
+ ul, ol {
67
+ margin-left: $spacing-unit;
68
+ }
69
+
70
+ li {
71
+ > ul,
72
+ > ol {
73
+ margin-bottom: 0;
74
+ }
75
+ }
76
+
77
+
78
+
79
+ /**
80
+ * Headings
81
+ */
82
+ h1, h2, h3, h4, h5, h6 {
83
+ font-weight: 300;
84
+ }
85
+
86
+
87
+
88
+ /**
89
+ * Links
90
+ */
91
+ a {
92
+ color: $brand-color;
93
+ text-decoration: none;
94
+
95
+ &:visited {
96
+ color: darken($brand-color, 15%);
97
+ }
98
+
99
+ &:hover {
100
+ color: $text-color;
101
+ text-decoration: underline;
102
+ }
103
+ }
104
+
105
+
106
+
107
+ /**
108
+ * Blockquotes
109
+ */
110
+ blockquote {
111
+ color: $grey-color;
112
+ border-left: 4px solid $grey-color-light;
113
+ padding-left: $spacing-unit / 2;
114
+ font-size: 18px;
115
+ letter-spacing: -1px;
116
+ font-style: italic;
117
+
118
+ > :last-child {
119
+ margin-bottom: 0;
120
+ }
121
+ }
122
+
123
+
124
+
125
+ /**
126
+ * Code formatting
127
+ */
128
+ pre,
129
+ code {
130
+ font-size: 15px;
131
+ border: 1px solid $grey-color-light;
132
+ border-radius: 3px;
133
+ background-color: #eef;
134
+ }
135
+
136
+ code {
137
+ padding: 1px 5px;
138
+ }
139
+
140
+ pre {
141
+ padding: 8px 12px;
142
+ overflow-x: scroll;
143
+
144
+ > code {
145
+ border: 0;
146
+ padding-right: 0;
147
+ padding-left: 0;
148
+ }
149
+ }
150
+
151
+
152
+
153
+ /**
154
+ * Wrapper
155
+ */
156
+ .wrapper {
157
+ max-width: -webkit-calc(#{$content-width} - (#{$spacing-unit} * 2));
158
+ max-width: calc(#{$content-width} - (#{$spacing-unit} * 2));
159
+ margin-right: auto;
160
+ margin-left: auto;
161
+ padding-right: $spacing-unit;
162
+ padding-left: $spacing-unit;
163
+ @extend %clearfix;
164
+
165
+ @include media-query($on-laptop) {
166
+ max-width: -webkit-calc(#{$content-width} - (#{$spacing-unit}));
167
+ max-width: calc(#{$content-width} - (#{$spacing-unit}));
168
+ padding-right: $spacing-unit / 2;
169
+ padding-left: $spacing-unit / 2;
170
+ }
171
+ }
172
+
173
+
174
+
175
+ /**
176
+ * Clearfix
177
+ */
178
+ %clearfix {
179
+
180
+ &:after {
181
+ content: "";
182
+ display: table;
183
+ clear: both;
184
+ }
185
+ }
186
+
187
+
188
+
189
+ /**
190
+ * Icons
191
+ */
192
+ .icon {
193
+
194
+ > svg {
195
+ display: inline-block;
196
+ width: 16px;
197
+ height: 16px;
198
+ vertical-align: middle;
199
+
200
+ path {
201
+ fill: $grey-color;
202
+ }
203
+ }
204
+ }
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Site header
3
+ */
4
+ .site-header {
5
+ border-top: 5px solid $grey-color-dark;
6
+ border-bottom: 1px solid $grey-color-light;
7
+ min-height: 56px;
8
+
9
+ // Positioning context for the mobile navigation icon
10
+ position: relative;
11
+ }
12
+
13
+ .site-title {
14
+ font-size: 26px;
15
+ line-height: 56px;
16
+ letter-spacing: -1px;
17
+ margin-bottom: 0;
18
+ float: left;
19
+
20
+ &,
21
+ &:visited {
22
+ color: $grey-color-dark;
23
+ }
24
+ }
25
+
26
+ .site-nav {
27
+ float: right;
28
+ line-height: 56px;
29
+
30
+ .menu-icon {
31
+ display: none;
32
+ }
33
+
34
+ .page-link {
35
+ color: $text-color;
36
+ line-height: $base-line-height;
37
+
38
+ // Gaps between nav items, but not on the first one
39
+ &:not(:first-child) {
40
+ margin-left: 20px;
41
+ }
42
+ }
43
+
44
+ @include media-query($on-palm) {
45
+ position: absolute;
46
+ top: 9px;
47
+ right: 30px;
48
+ background-color: $background-color;
49
+ border: 1px solid $grey-color-light;
50
+ border-radius: 5px;
51
+ text-align: right;
52
+
53
+ .menu-icon {
54
+ display: block;
55
+ float: right;
56
+ width: 36px;
57
+ height: 26px;
58
+ line-height: 0;
59
+ padding-top: 10px;
60
+ text-align: center;
61
+
62
+ > svg {
63
+ width: 18px;
64
+ height: 15px;
65
+
66
+ path {
67
+ fill: $grey-color-dark;
68
+ }
69
+ }
70
+ }
71
+
72
+ .trigger {
73
+ clear: both;
74
+ display: none;
75
+ }
76
+
77
+ &:hover .trigger {
78
+ display: block;
79
+ padding-bottom: 5px;
80
+ }
81
+
82
+ .page-link {
83
+ display: block;
84
+ padding: 5px 10px;
85
+ }
86
+ }
87
+ }
88
+
89
+
90
+
91
+ /**
92
+ * Site footer
93
+ */
94
+ .site-footer {
95
+ border-top: 1px solid $grey-color-light;
96
+ padding: $spacing-unit 0;
97
+ }
98
+
99
+ .footer-heading {
100
+ font-size: 18px;
101
+ margin-bottom: $spacing-unit / 2;
102
+ }
103
+
104
+ .contact-list,
105
+ .social-media-list {
106
+ list-style: none;
107
+ margin-left: 0;
108
+ }
109
+
110
+ .footer-col-wrapper {
111
+ font-size: 15px;
112
+ color: $grey-color;
113
+ margin-left: -$spacing-unit / 2;
114
+ @extend %clearfix;
115
+ }
116
+
117
+ .footer-col {
118
+ float: left;
119
+ margin-bottom: $spacing-unit / 2;
120
+ padding-left: $spacing-unit / 2;
121
+ }
122
+
123
+ .footer-col-1 {
124
+ width: -webkit-calc(35% - (#{$spacing-unit} / 2));
125
+ width: calc(35% - (#{$spacing-unit} / 2));
126
+ }
127
+
128
+ .footer-col-2 {
129
+ width: -webkit-calc(20% - (#{$spacing-unit} / 2));
130
+ width: calc(20% - (#{$spacing-unit} / 2));
131
+ }
132
+
133
+ .footer-col-3 {
134
+ width: -webkit-calc(45% - (#{$spacing-unit} / 2));
135
+ width: calc(45% - (#{$spacing-unit} / 2));
136
+ }
137
+
138
+ @include media-query($on-laptop) {
139
+ .footer-col-1,
140
+ .footer-col-2 {
141
+ width: -webkit-calc(50% - (#{$spacing-unit} / 2));
142
+ width: calc(50% - (#{$spacing-unit} / 2));
143
+ }
144
+
145
+ .footer-col-3 {
146
+ width: -webkit-calc(100% - (#{$spacing-unit} / 2));
147
+ width: calc(100% - (#{$spacing-unit} / 2));
148
+ }
149
+ }
150
+
151
+ @include media-query($on-palm) {
152
+ .footer-col {
153
+ float: none;
154
+ width: -webkit-calc(100% - (#{$spacing-unit} / 2));
155
+ width: calc(100% - (#{$spacing-unit} / 2));
156
+ }
157
+ }
158
+
159
+
160
+
161
+ /**
162
+ * Page content
163
+ */
164
+ .page-content {
165
+ padding: $spacing-unit 0;
166
+ }
167
+
168
+ .page-heading {
169
+ font-size: 20px;
170
+ }
171
+
172
+ .post-list {
173
+ margin-left: 0;
174
+ list-style: none;
175
+
176
+ > li {
177
+ margin-bottom: $spacing-unit;
178
+ }
179
+ }
180
+
181
+ .post-meta {
182
+ font-size: $small-font-size;
183
+ color: $grey-color;
184
+ }
185
+
186
+ .post-link {
187
+ display: block;
188
+ font-size: 24px;
189
+ }
190
+
191
+
192
+
193
+ /**
194
+ * Posts
195
+ */
196
+ .post-header {
197
+ margin-bottom: $spacing-unit;
198
+ }
199
+
200
+ .post-title {
201
+ font-size: 42px;
202
+ letter-spacing: -1px;
203
+ line-height: 1;
204
+
205
+ @include media-query($on-laptop) {
206
+ font-size: 36px;
207
+ }
208
+ }
209
+
210
+ .post-content {
211
+ margin-bottom: $spacing-unit;
212
+
213
+ h2 {
214
+ font-size: 32px;
215
+
216
+ @include media-query($on-laptop) {
217
+ font-size: 28px;
218
+ }
219
+ }
220
+
221
+ h3 {
222
+ font-size: 26px;
223
+
224
+ @include media-query($on-laptop) {
225
+ font-size: 22px;
226
+ }
227
+ }
228
+
229
+ h4 {
230
+ font-size: 20px;
231
+
232
+ @include media-query($on-laptop) {
233
+ font-size: 18px;
234
+ }
235
+ }
236
+ }