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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -5
- data/CHANGELOG.md +4 -0
- data/README.md +6 -6
- data/docs/.gitignore +6 -0
- data/docs/_classes/pbox2d.md +375 -0
- data/docs/_classes/world_builder.md +7 -0
- data/docs/_config.yml +32 -0
- data/docs/_includes/footer.html +55 -0
- data/docs/_includes/head.html +18 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/menu.html +8 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_methods/init_options.md +28 -0
- data/docs/_methods/processing_to_world.md +29 -0
- data/docs/_methods/scale_to_processing.md +24 -0
- data/docs/_methods/scale_to_world.md +29 -0
- data/docs/_methods/step_options.md +25 -0
- data/docs/_methods/world_to_processing.md +30 -0
- data/docs/_modules/pb.md +25 -0
- data/docs/_modules/world_builder.md +26 -0
- data/docs/_posts/2016-10-14-welcome.md +183 -0
- data/docs/_sass/_base.scss +204 -0
- data/docs/_sass/_layout.scss +236 -0
- data/docs/_sass/_syntax-highlighting.scss +67 -0
- data/docs/about.md +20 -0
- data/docs/classes.html +9 -0
- data/docs/css/main.scss +52 -0
- data/docs/favicon.ico +0 -0
- data/docs/index.html +38 -0
- data/docs/methods.html +9 -0
- data/docs/modules.html +12 -0
- data/lib/pbox2d/version.rb +1 -1
- data/pbox2d.gemspec +4 -7
- data/pom.rb +8 -6
- data/pom.xml +3 -3
- data/src/org/jbox2d/collision/AABB.java +2 -2
- data/src/org/jbox2d/collision/Manifold.java +2 -2
- data/src/org/jbox2d/collision/ManifoldPoint.java +2 -2
- data/src/org/jbox2d/collision/shapes/MassData.java +1 -1
- data/src/org/jbox2d/common/Mat22.java +6 -13
- data/src/org/jbox2d/common/Mat33.java +253 -233
- data/src/org/jbox2d/common/MathUtils.java +5 -5
- data/src/org/jbox2d/common/Rot.java +16 -19
- data/src/org/jbox2d/common/Transform.java +4 -4
- data/src/org/jbox2d/common/Vec2.java +6 -12
- data/src/org/jbox2d/common/Vec3.java +147 -142
- data/src/org/jbox2d/dynamics/joints/DistanceJoint.java +4 -2
- metadata +62 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0aed216a0450186a793eb195a8e9c5ec017e63a
|
4
|
+
data.tar.gz: f00273168b47d8cfce2601ac2956525497aa8f66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68efe632c0ea5cca8e9e01a3176ef1cae1e43462bd3b7dce965fde7b6cd20dcc40ba525609d3198e9fd6613f92020eabf1d91a62536580b43fec1a5fdc903ca6
|
7
|
+
data.tar.gz: 4074f71a4a852abd9eeb3a8bcce7047a48c4b3ebb86719a7d89b27d3a9fdf5f23c9145cc83bec3f4d66b33c1b99a8ebcc1aaa6d506ab7e80344912aae83e1906
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,11 @@
|
|
3
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
|
![liquidy](http://4.bp.blogspot.com/-dwnDQZVugwo/VFXrDxGOy4I/AAAAAAAAEgo/irsZxW_WLOA/s400/liquidy.png)
|
5
5
|
|
6
|
-
|
6
|
+
![Travis CI](https://travis-ci.org/ruby-processing/jbox2d.svg)
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/pbox2d.svg)](http://badge.fury.io/rb/pbox2d)
|
8
8
|
|
9
|
+
Build fails because latest processing is not available from maven central.
|
10
|
+
|
9
11
|
### Web Links
|
10
12
|
|
11
13
|
[JBox2D Home][]
|
@@ -14,8 +16,7 @@ Here we demonstrate how to use JBox2D library as a rubygem. This approach could
|
|
14
16
|
|
15
17
|
[Box2D for processing on github][]
|
16
18
|
|
17
|
-
Downloads including examples [zip][]
|
18
|
-
|
19
|
+
Downloads including examples [zip][]
|
19
20
|
[Wiki][]
|
20
21
|
|
21
22
|
### Licensing
|
@@ -30,7 +31,7 @@ Copyright (c) 2014 Daniel Shiffman
|
|
30
31
|
|
31
32
|
This gem was created by Martin Prout
|
32
33
|
|
33
|
-
Copyright (c) 2015/
|
34
|
+
Copyright (c) 2015/17 Martin Prout
|
34
35
|
|
35
36
|
### To compile
|
36
37
|
|
@@ -60,6 +61,5 @@ The other thing you should know is there is a mismatch between the physics world
|
|
60
61
|
[Nature of Code book]:http://natureofcode.com/
|
61
62
|
[Sandi Metz]:http://www.poodr.com/
|
62
63
|
[this book]:http://www.crcpress.com/product/isbn/9781466565760
|
63
|
-
[zip]:https://github.com/ruby-processing/jbox2d/archive/
|
64
|
-
[tar]:https://github.com/ruby-processing/jbox2d/archive/0.9.1.tar.gz
|
64
|
+
[zip]:https://github.com/ruby-processing/jbox2d/archive/master.zip
|
65
65
|
[Wiki]:https://github.com/ruby-processing/jbox2d/wiki
|
data/docs/.gitignore
ADDED
@@ -0,0 +1,375 @@
|
|
1
|
+
---
|
2
|
+
layout: page
|
3
|
+
title: "PBox2D"
|
4
|
+
permalink: /classes/pbox2d/
|
5
|
+
---
|
6
|
+
|
7
|
+
The PBox2D class is a simple wrapper to help integrate the JBox2D world with ruby implementations of processing (_JRubyArt and propane_). Use the [WorldBuilder][world_builder] in your sketch setup to create an instance of this class.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# Ruby version of java wrapper allows us to have more
|
11
|
+
# rubified interface, also needed for add_listener
|
12
|
+
class Box2D < Java::ProcessingBox2d::Box2DProcessing
|
13
|
+
field_accessor :world # allow access to protected variable
|
14
|
+
|
15
|
+
def init_options(args = {})
|
16
|
+
args = defaults.merge(args)
|
17
|
+
set_options(args[:scale],
|
18
|
+
args[:gravity].to_java(Java::float),
|
19
|
+
args[:warm],
|
20
|
+
args[:continuous]
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def step_options(args = {})
|
25
|
+
default_step.merge(args)
|
26
|
+
set_step(args[:time_step], args[:velocity_iter], args[:position_iter])
|
27
|
+
end
|
28
|
+
|
29
|
+
def defaults
|
30
|
+
{ scale: 10.0, gravity: [0, -10], warm: true, continuous: true }
|
31
|
+
end
|
32
|
+
|
33
|
+
def default_step
|
34
|
+
{ time_step: 1.0 / 60, velocity_iter: 8, position_iter: 10 }
|
35
|
+
end
|
36
|
+
|
37
|
+
def gravity(args)
|
38
|
+
change_gravity(args.to_java(Java::float))
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_listener(listener)
|
42
|
+
# in combination with field accessor we can access protected world
|
43
|
+
world.setContactListener(listener)
|
44
|
+
end
|
45
|
+
|
46
|
+
def version
|
47
|
+
format('pbox2d version %s', Pbox2d::VERSION)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
The java class
|
53
|
+
```java
|
54
|
+
|
55
|
+
package processing.box2d;
|
56
|
+
|
57
|
+
import org.jbox2d.common.Transform;
|
58
|
+
import org.jbox2d.common.Vec2;
|
59
|
+
import org.jbox2d.dynamics.Body;
|
60
|
+
import org.jbox2d.dynamics.BodyDef;
|
61
|
+
import org.jbox2d.dynamics.World;
|
62
|
+
import org.jbox2d.dynamics.joints.Joint;
|
63
|
+
import org.jbox2d.dynamics.joints.JointDef;
|
64
|
+
|
65
|
+
import processing.core.PApplet;
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Loosely based on Box2D-for-processing by Dan Shiffman
|
69
|
+
*
|
70
|
+
* @author Martin Prout
|
71
|
+
*/
|
72
|
+
public abstract class Box2DProcessing {
|
73
|
+
|
74
|
+
private final PApplet parent;
|
75
|
+
private Options options;
|
76
|
+
private Step stepO;
|
77
|
+
private final float height;
|
78
|
+
private final float width;
|
79
|
+
/**
|
80
|
+
* The Box2D world (we might need public access for our ContactListener)
|
81
|
+
*/
|
82
|
+
protected World world;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Scale between processing sketch and physics world
|
86
|
+
*/
|
87
|
+
private float scaleFactor;// = 10.0f;
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Adjust for processing.org unfathomable choice of y-axis direction
|
91
|
+
*/
|
92
|
+
private final float yFlip;// = -1.0f; //flip y coordinate
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Controls access to processing pre loop (via reflection)
|
96
|
+
*/
|
97
|
+
private boolean isActive = false;
|
98
|
+
|
99
|
+
private Body groundBody;
|
100
|
+
|
101
|
+
/**
|
102
|
+
*
|
103
|
+
* @param p PApplet
|
104
|
+
*/
|
105
|
+
public Box2DProcessing(PApplet p) {
|
106
|
+
parent = p;
|
107
|
+
height = p.height;
|
108
|
+
width = p.width;
|
109
|
+
yFlip = -1;
|
110
|
+
setActive(true);
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Abstract method implement on ruby side
|
115
|
+
*
|
116
|
+
* @param listener Custom Listener, Sketch?
|
117
|
+
*/
|
118
|
+
public abstract void addListener(org.jbox2d.callbacks.ContactListener listener);
|
119
|
+
|
120
|
+
/**
|
121
|
+
*
|
122
|
+
* @param scale float
|
123
|
+
* @param gravity float[]
|
124
|
+
* @param warmStart boolean
|
125
|
+
* @param continuous boolean
|
126
|
+
*/
|
127
|
+
protected void setOptions(float scale, float[] gravity, boolean warmStart, boolean continuous) {
|
128
|
+
options = new Options(scale, gravity, warmStart, continuous);
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
*
|
133
|
+
* @param timeStep float
|
134
|
+
* @param velocity int
|
135
|
+
* @param position int
|
136
|
+
*/
|
137
|
+
protected void setStep(float timeStep, int velocity, int position) {
|
138
|
+
stepO = new Step(timeStep, velocity, position);
|
139
|
+
}
|
140
|
+
|
141
|
+
/**
|
142
|
+
* This is the all important physics "step" function Says to move ahead one
|
143
|
+
* unit in time Default
|
144
|
+
*/
|
145
|
+
protected void step() {
|
146
|
+
if (stepO == null) {
|
147
|
+
stepO = new Step();
|
148
|
+
}
|
149
|
+
world.step(stepO.timeStep, stepO.velIters, stepO.posIters);
|
150
|
+
world.clearForces();
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Create a world
|
155
|
+
*/
|
156
|
+
public void createWorld() {
|
157
|
+
if (options == null) {
|
158
|
+
options = new Options();
|
159
|
+
}
|
160
|
+
Vec2 gravity = new Vec2(options.gravity[0], options.gravity[1]);
|
161
|
+
scaleFactor = options.scaleFactor;
|
162
|
+
world = new World(gravity);
|
163
|
+
world.setWarmStarting(options.warm);
|
164
|
+
world.setContinuousPhysics(options.continuous);
|
165
|
+
BodyDef bodyDef = new BodyDef();
|
166
|
+
groundBody = world.createBody(bodyDef);
|
167
|
+
}
|
168
|
+
|
169
|
+
/**
|
170
|
+
*
|
171
|
+
* @return Body
|
172
|
+
*/
|
173
|
+
public Body groundBody() {
|
174
|
+
return groundBody;
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Set the gravity (this can change in real-time)
|
179
|
+
*
|
180
|
+
* @param gravity float[]
|
181
|
+
*/
|
182
|
+
protected void changeGravity(float[] gravity) {
|
183
|
+
world.setGravity(new Vec2(gravity[0], gravity[1]));
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Box2d has its own coordinate system and we have to move back and forth
|
188
|
+
* between them to convert from Box2d world to processing pixel space
|
189
|
+
*
|
190
|
+
* @param world Vec2
|
191
|
+
* @return Vec2
|
192
|
+
*/
|
193
|
+
public Vec2 worldToProcessing(Vec2 world) {
|
194
|
+
return worldToProcessing(world.x, world.y);
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Box2d has its own coordinate system and we have to move back and forth
|
199
|
+
* between them to convert from Box2d world to processing pixel space
|
200
|
+
* Note reverse Y mapping (processing poxy coord system again)
|
201
|
+
* @param worldX float
|
202
|
+
* @param worldY float
|
203
|
+
* @return Vec2
|
204
|
+
*/
|
205
|
+
public Vec2 worldToProcessing(float worldX, float worldY) {
|
206
|
+
float pixelX = map(worldX, 0f, 1f, parent.width / 2, parent.width / 2 + scaleFactor);
|
207
|
+
float pixelY = map(worldY, 1f, 0f, parent.height / 2, parent.height / 2 + scaleFactor);
|
208
|
+
return new Vec2(pixelX, pixelY);
|
209
|
+
}
|
210
|
+
|
211
|
+
/**
|
212
|
+
* convert Coordinate from pixel space to box2d world
|
213
|
+
*
|
214
|
+
* @param screen Vec2
|
215
|
+
* @return Vec2
|
216
|
+
*/
|
217
|
+
public Vec2 processingToWorld(Vec2 screen) {
|
218
|
+
return processingToWorld(screen.x, screen.y);
|
219
|
+
}
|
220
|
+
|
221
|
+
/**
|
222
|
+
* Note reverse Y mapping (processing poxy coord system again)
|
223
|
+
* @param pixelX float
|
224
|
+
* @param pixelY float
|
225
|
+
* @return Vec2
|
226
|
+
*/
|
227
|
+
public Vec2 processingToWorld(float pixelX, float pixelY) {
|
228
|
+
float worldX = map(pixelX, parent.width / 2, parent.width / 2 + scaleFactor, 0f, 1f);
|
229
|
+
float worldY = map(pixelY, parent.height / 2, parent.height / 2 + scaleFactor, 1f, 0f);
|
230
|
+
return new Vec2(worldX, worldY);
|
231
|
+
}
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Scale from processing to world
|
235
|
+
*
|
236
|
+
* @param val float
|
237
|
+
* @return float
|
238
|
+
*/
|
239
|
+
public float scaleToWorld(float val) {
|
240
|
+
return val / scaleFactor;
|
241
|
+
}
|
242
|
+
|
243
|
+
/**
|
244
|
+
* Scale from world to processing
|
245
|
+
*
|
246
|
+
* @param val float
|
247
|
+
* @return float
|
248
|
+
*/
|
249
|
+
public float scaleToProcessing(float val) {
|
250
|
+
return val * scaleFactor;
|
251
|
+
}
|
252
|
+
|
253
|
+
/**
|
254
|
+
* Vector scale between two worlds
|
255
|
+
*
|
256
|
+
* @param v Vec2
|
257
|
+
* @return Vec2
|
258
|
+
*/
|
259
|
+
public Vec2 vectorToWorld(Vec2 v) {
|
260
|
+
Vec2 u = new Vec2(v.x / scaleFactor, v.y / scaleFactor);
|
261
|
+
u.y *= yFlip;
|
262
|
+
return u;
|
263
|
+
}
|
264
|
+
|
265
|
+
/**
|
266
|
+
* Translate from world coords to processing as a Vec2
|
267
|
+
*
|
268
|
+
* @param x float
|
269
|
+
* @param y float
|
270
|
+
* @return Vec
|
271
|
+
*/
|
272
|
+
public Vec2 vectorToWorld(float x, float y) {
|
273
|
+
Vec2 u = new Vec2(x / scaleFactor, y / scaleFactor);
|
274
|
+
u.y *= yFlip;
|
275
|
+
return u;
|
276
|
+
}
|
277
|
+
|
278
|
+
/**
|
279
|
+
* Translate from world to processing as a Vec2
|
280
|
+
*
|
281
|
+
* @param v Vec
|
282
|
+
* @return Vec
|
283
|
+
*/
|
284
|
+
public Vec2 vectorToProcessing(Vec2 v) {
|
285
|
+
Vec2 u = new Vec2(v.x * scaleFactor, v.y * scaleFactor);
|
286
|
+
u.y *= yFlip;
|
287
|
+
return u;
|
288
|
+
}
|
289
|
+
|
290
|
+
/**
|
291
|
+
* A common task we have to do a lot
|
292
|
+
*
|
293
|
+
* @param bd BodyDef
|
294
|
+
* @return Body
|
295
|
+
*/
|
296
|
+
public Body createBody(BodyDef bd) {
|
297
|
+
return world.createBody(bd);
|
298
|
+
}
|
299
|
+
|
300
|
+
/**
|
301
|
+
* A common task we have to do a lot
|
302
|
+
*
|
303
|
+
* @param jd JointDef
|
304
|
+
* @return World
|
305
|
+
*/
|
306
|
+
public Joint createJoint(JointDef jd) {
|
307
|
+
return world.createJoint(jd);
|
308
|
+
}
|
309
|
+
|
310
|
+
/**
|
311
|
+
*
|
312
|
+
* @param b Body
|
313
|
+
* @return body coord as Vec2
|
314
|
+
*/
|
315
|
+
public Vec2 bodyCoord(Body b) {
|
316
|
+
Transform xf = b.getTransform();
|
317
|
+
return worldToProcessing(xf.p);
|
318
|
+
}
|
319
|
+
|
320
|
+
/**
|
321
|
+
*
|
322
|
+
* @param b Body
|
323
|
+
*/
|
324
|
+
public void destroyBody(Body b) {
|
325
|
+
world.destroyBody(b);
|
326
|
+
}
|
327
|
+
|
328
|
+
/**
|
329
|
+
* Access the processing pre loop by java reflection
|
330
|
+
*/
|
331
|
+
public void pre() {
|
332
|
+
step();
|
333
|
+
}
|
334
|
+
|
335
|
+
/**
|
336
|
+
* Recommended inclusion in a processing library
|
337
|
+
*/
|
338
|
+
public void dispose() {
|
339
|
+
setActive(false);
|
340
|
+
}
|
341
|
+
|
342
|
+
/**
|
343
|
+
*
|
344
|
+
* @return height float
|
345
|
+
*/
|
346
|
+
public float height() {
|
347
|
+
return height;
|
348
|
+
}
|
349
|
+
|
350
|
+
/**
|
351
|
+
*
|
352
|
+
* @return width float
|
353
|
+
*/
|
354
|
+
public float width() {
|
355
|
+
return width;
|
356
|
+
}
|
357
|
+
|
358
|
+
private float map(float val, float startIn, float endIn, float startOut, float endOut) {
|
359
|
+
return startOut + (endOut - startOut) * ((val - startIn) / (endIn - startIn));
|
360
|
+
}
|
361
|
+
|
362
|
+
private void setActive(boolean active) {
|
363
|
+
if (active != isActive) {
|
364
|
+
isActive = active;
|
365
|
+
if (active) {
|
366
|
+
parent.registerMethod("dispose", this);
|
367
|
+
parent.registerMethod("pre", this);
|
368
|
+
} else {
|
369
|
+
parent.unregisterMethod("pre", this);
|
370
|
+
}
|
371
|
+
}
|
372
|
+
}
|
373
|
+
}
|
374
|
+
|
375
|
+
```
|