();
20 | }
21 |
22 | void draw() {
23 | background(255);
24 |
25 | // We must always step through time!
26 | box2d.step();
27 |
28 | // When the mouse is clicked, add a new Box object
29 | if (mousePressed) {
30 | Box p = new Box(mouseX,mouseY);
31 | boxes.add(p);
32 | }
33 |
34 | // Display all the boxes
35 | for (Box b: boxes) {
36 | b.display();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/dist/box2d_processing/library.properties:
--------------------------------------------------------------------------------
1 | # More on this file here: https://github.com/processing/processing/wiki/Library-Basics
# UTF-8 supported.
# The name of your library as you want it formatted.
name = Box2D for Processing
# List of authors. Links can be provided using the syntax [author name](url).
authorList = [Daniel Shiffman](http://www.shiffman.net/)
# A web page for your library, NOT a direct link to where to download it.
url = https://github.com/shiffman/Box2D-for-Processing
# The category of your library, must be one (or many) of the following:
# "3D" "Animation" "Compilations" "Data"
# "Fabrication" "Geometry" "GUI" "Hardware"
# "I/O" "Language" "Math" "Simulation"
# "Sound" "Utilities" "Typography" "Video & Vision"
#
# If a value other than those listed is used, your library will listed as
# "Other".
category = Simulation
# A short sentence (or fragment) to summarize the library's function. This will
# be shown from inside the PDE when the library is being installed. Avoid
# repeating the name of your library here. Also, avoid saying anything redundant
# like mentioning that it's a library. This should start with a capitalized
# letter, and end with a period.
sentence = A library and set of examples for 2D physics simulation wrapping some aspects of [JBox2D](http://www.jbox2d.org/), a Java implementation of [Box2D](http://box2d.org/).
# Additional information suitable for the Processing website. The value of
# 'sentence' always will be prepended, so you should start by writing the
# second sentence here. If your library only works on certain operating systems,
# mention it here.
paragraph =
# Links in the 'sentence' and 'paragraph' attributes can be inserted using the
# same syntax as for authors.
# That is, [here is a link to Processing](http://processing.org/)
# A version number that increments once with each release. This is used to
# compare different versions of the same library, and check if an update is
# available. You should think of it as a counter, counting the total number of
# releases you've had.
version = 4
# The version as the user will see it. If blank, the version attribute will be
# used here.
prettyVersion = 0.4
--------------------------------------------------------------------------------
/Box2D-for-Processing/dist/box2d_processing/library/box2d_processing.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/Box2D-for-Processing/43d58c546bf0b95c4dcda9f7a7d171c19477f120/Box2D-for-Processing/dist/box2d_processing/library/box2d_processing.jar
--------------------------------------------------------------------------------
/Box2D-for-Processing/dist/box2d_processing/library/jbox2d-library-2.3.1-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/Box2D-for-Processing/43d58c546bf0b95c4dcda9f7a7d171c19477f120/Box2D-for-Processing/dist/box2d_processing/library/jbox2d-library-2.3.1-SNAPSHOT.jar
--------------------------------------------------------------------------------
/Box2D-for-Processing/dist/box2d_processing/src/readme.txt:
--------------------------------------------------------------------------------
1 | See: https://github.com/shiffman/Box2D-for-Processing
--------------------------------------------------------------------------------
/Box2D-for-Processing/dist/box2d_processing/src/shiffman/box2d/Box2DContactListener.java:
--------------------------------------------------------------------------------
1 | package shiffman.box2d;
2 |
3 | import java.lang.reflect.Method;
4 |
5 |
6 | import org.jbox2d.callbacks.ContactImpulse;
7 | import org.jbox2d.callbacks.ContactListener;
8 | import org.jbox2d.collision.Manifold;
9 | import org.jbox2d.dynamics.contacts.Contact;
10 |
11 | import processing.core.PApplet;
12 |
13 | public class Box2DContactListener implements ContactListener {
14 | PApplet parent;
15 |
16 | Method beginMethod;
17 | Method endMethod;
18 | Method postMethod;
19 | Method preMethod;
20 |
21 | Box2DContactListener(PApplet p){
22 | parent = p;
23 |
24 | try {
25 | beginMethod = parent.getClass().getMethod("beginContact", new Class[] { Contact.class });
26 | } catch (Exception e) {
27 | System.out.println("You are missing the beginContact() method. " + e);
28 | }
29 |
30 | try {
31 | endMethod = parent.getClass().getMethod("endContact", new Class[] { Contact.class });
32 | } catch (Exception e) {
33 | System.out.println("You are missing the endContact() method. " + e);
34 | }
35 | try {
36 | postMethod = parent.getClass().getMethod("postSolve", new Class[] { Contact.class, ContactImpulse.class });
37 | } catch (Exception e) {
38 | //System.out.println("You are missing the postSolve() method. " + e);
39 | }
40 | try {
41 | preMethod = parent.getClass().getMethod("preSolve", new Class[] { Contact.class, Manifold.class });
42 | } catch (Exception e) {
43 | //System.out.println("You are missing the preSolve() method. " + e);
44 | }
45 | }
46 |
47 |
48 |
49 |
50 |
51 | public void beginContact(Contact c) {
52 | if (beginMethod != null) {
53 | try {
54 | beginMethod.invoke(parent, new Object[] { c });
55 | } catch (Exception e) {
56 | System.out.println("Could not invoke the \"beginContact()\" method for some reason.");
57 | e.printStackTrace();
58 | beginMethod = null;
59 | }
60 | }
61 |
62 | }
63 |
64 | public void endContact(Contact c) {
65 | if (endMethod != null) {
66 | try {
67 | endMethod.invoke(parent, new Object[] { c });
68 | } catch (Exception e) {
69 | System.out.println("Could not invoke the \"removeContact()\" method for some reason.");
70 | e.printStackTrace();
71 | endMethod = null;
72 | }
73 | }
74 |
75 | }
76 |
77 | public void postSolve(Contact c, ContactImpulse ci) {
78 | if (postMethod != null) {
79 | try {
80 | postMethod.invoke(parent, new Object[] { c,ci});
81 | } catch (Exception e) {
82 | System.out.println("Could not invoke the \"postSolve()\" method for some reason.");
83 | e.printStackTrace();
84 | postMethod = null;
85 | }
86 | }
87 | }
88 |
89 |
90 | public void preSolve(Contact c, Manifold m) {
91 | if (preMethod != null) {
92 | try {
93 | preMethod.invoke(parent, new Object[] { c,m});
94 | } catch (Exception e) {
95 | System.out.println("Could not invoke the \"preSolve()\" method for some reason.");
96 | e.printStackTrace();
97 | preMethod = null;
98 | }
99 | }
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 | All Classes
12 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/allclasses-noframe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 | All Classes
12 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/class-use/QuickTest.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class QuickTest
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
68 | No usage of QuickTest
69 |
70 |
86 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/constant-values.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Constant Field Values
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
69 |
70 |
86 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/deprecated-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Deprecated List
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
69 |
70 |
86 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Generated Documentation (Untitled)
7 |
59 |
60 |
74 |
75 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/overview-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Overview List
7 |
8 |
9 |
10 |
11 |
12 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/overview-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Overview
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
66 |
67 | Packages
68 |
69 | Package |
70 | Description |
71 |
72 |
73 |
74 | shiffman.box2d |
75 | |
76 |
77 |
78 |
79 |
80 |
81 |
97 |
98 |
99 | - Prev
100 | - Next
101 |
102 |
106 |
109 |
110 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/overview-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Class Hierarchy
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
72 |
73 |
Class Hierarchy
74 |
75 | - java.lang.Object
76 |
77 | - shiffman.box2d.Box2DContactListener (implements org.jbox2d.callbacks.ContactListener)
78 | - shiffman.box2d.Box2DProcessing
79 | - processing.core.PApplet (implements processing.core.PConstants)
80 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
105 |
106 |
107 | - Prev
108 | - Next
109 |
110 |
114 |
117 |
118 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | <Unnamed>
7 |
8 |
9 |
10 |
11 |
12 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/package-list:
--------------------------------------------------------------------------------
1 |
2 | shiffman.box2d
3 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
30 |
57 |
58 |
61 |
62 |
63 | -
64 |
65 | Class Summary
66 |
67 | Class |
68 | Description |
69 |
70 |
71 |
72 | QuickTest |
73 | |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
97 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Class Hierarchy
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
72 |
73 |
Class Hierarchy
74 |
75 | - java.lang.Object
76 |
77 | - processing.core.PApplet (implements processing.core.PConstants)
78 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
103 |
104 |
105 | - Prev
106 | - Next
107 |
108 |
112 |
115 |
116 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/package-use.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Package
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
68 | No usage of
69 |
70 |
86 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/resources/background.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/Box2D-for-Processing/43d58c546bf0b95c4dcda9f7a7d171c19477f120/Box2D-for-Processing/javadoc/resources/background.gif
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/resources/tab.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/Box2D-for-Processing/43d58c546bf0b95c4dcda9f7a7d171c19477f120/Box2D-for-Processing/javadoc/resources/tab.gif
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/resources/titlebar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/Box2D-for-Processing/43d58c546bf0b95c4dcda9f7a7d171c19477f120/Box2D-for-Processing/javadoc/resources/titlebar.gif
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/resources/titlebar_end.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/Box2D-for-Processing/43d58c546bf0b95c4dcda9f7a7d171c19477f120/Box2D-for-Processing/javadoc/resources/titlebar_end.gif
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/shiffman/box2d/class-use/Box2DContactListener.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class shiffman.box2d.Box2DContactListener
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
68 | No usage of shiffman.box2d.Box2DContactListener
69 |
70 |
86 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/shiffman/box2d/class-use/Box2DProcessing.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class shiffman.box2d.Box2DProcessing
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
68 | No usage of shiffman.box2d.Box2DProcessing
69 |
70 |
86 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/shiffman/box2d/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | shiffman.box2d
7 |
8 |
9 |
10 |
11 |
12 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/javadoc/shiffman/box2d/package-use.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Package shiffman.box2d
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
37 |
64 |
65 |
68 | No usage of shiffman.box2d
69 |
70 |
86 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/Box2D-for-Processing/lib/core.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/Box2D-for-Processing/43d58c546bf0b95c4dcda9f7a7d171c19477f120/Box2D-for-Processing/lib/core.jar
--------------------------------------------------------------------------------
/Box2D-for-Processing/lib/jbox2d-library-2.3.1-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shiffman/Box2D-for-Processing/43d58c546bf0b95c4dcda9f7a7d171c19477f120/Box2D-for-Processing/lib/jbox2d-library-2.3.1-SNAPSHOT.jar
--------------------------------------------------------------------------------
/Box2D-for-Processing/src/shiffman/box2d/Box2DContactListener.java:
--------------------------------------------------------------------------------
1 | package shiffman.box2d;
2 |
3 | import java.lang.reflect.Method;
4 |
5 |
6 | import org.jbox2d.callbacks.ContactImpulse;
7 | import org.jbox2d.callbacks.ContactListener;
8 | import org.jbox2d.collision.Manifold;
9 | import org.jbox2d.dynamics.contacts.Contact;
10 |
11 | import processing.core.PApplet;
12 |
13 | public class Box2DContactListener implements ContactListener {
14 | PApplet parent;
15 |
16 | Method beginMethod;
17 | Method endMethod;
18 | Method postMethod;
19 | Method preMethod;
20 |
21 | Box2DContactListener(PApplet p){
22 | parent = p;
23 |
24 | try {
25 | beginMethod = parent.getClass().getMethod("beginContact", new Class[] { Contact.class });
26 | } catch (Exception e) {
27 | System.out.println("You are missing the beginContact() method. " + e);
28 | }
29 |
30 | try {
31 | endMethod = parent.getClass().getMethod("endContact", new Class[] { Contact.class });
32 | } catch (Exception e) {
33 | System.out.println("You are missing the endContact() method. " + e);
34 | }
35 | try {
36 | postMethod = parent.getClass().getMethod("postSolve", new Class[] { Contact.class, ContactImpulse.class });
37 | } catch (Exception e) {
38 | //System.out.println("You are missing the postSolve() method. " + e);
39 | }
40 | try {
41 | preMethod = parent.getClass().getMethod("preSolve", new Class[] { Contact.class, Manifold.class });
42 | } catch (Exception e) {
43 | //System.out.println("You are missing the preSolve() method. " + e);
44 | }
45 | }
46 |
47 |
48 |
49 |
50 |
51 | public void beginContact(Contact c) {
52 | if (beginMethod != null) {
53 | try {
54 | beginMethod.invoke(parent, new Object[] { c });
55 | } catch (Exception e) {
56 | System.out.println("Could not invoke the \"beginContact()\" method for some reason.");
57 | e.printStackTrace();
58 | beginMethod = null;
59 | }
60 | }
61 |
62 | }
63 |
64 | public void endContact(Contact c) {
65 | if (endMethod != null) {
66 | try {
67 | endMethod.invoke(parent, new Object[] { c });
68 | } catch (Exception e) {
69 | System.out.println("Could not invoke the \"removeContact()\" method for some reason.");
70 | e.printStackTrace();
71 | endMethod = null;
72 | }
73 | }
74 |
75 | }
76 |
77 | public void postSolve(Contact c, ContactImpulse ci) {
78 | if (postMethod != null) {
79 | try {
80 | postMethod.invoke(parent, new Object[] { c,ci});
81 | } catch (Exception e) {
82 | System.out.println("Could not invoke the \"postSolve()\" method for some reason.");
83 | e.printStackTrace();
84 | postMethod = null;
85 | }
86 | }
87 | }
88 |
89 |
90 | public void preSolve(Contact c, Manifold m) {
91 | if (preMethod != null) {
92 | try {
93 | preMethod.invoke(parent, new Object[] { c,m});
94 | } catch (Exception e) {
95 | System.out.println("Could not invoke the \"preSolve()\" method for some reason.");
96 | e.printStackTrace();
97 | preMethod = null;
98 | }
99 | }
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Daniel Shiffman
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice, this
11 | list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Box2D for Processing
2 |
3 | A Processing library wrapping JBox2D (http://www.jbox2d.org/).
4 |
5 | Download library: http://shiffman-archive.netlify.app/p5/libraries/box2d_processing/box2d_processing.zip
6 |
7 | Tutorial and further examples for this library are available in The Nature of Code book: http://natureofcode.com.
8 |
--------------------------------------------------------------------------------