nature-of-code / The-Nature-of-Code-archive

The very first build system for The Nature of Code

Home Page:http://natureofcode.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ch5: no mentioning of how to import JBox2D library. when someone follows book code, it won't compile.

dimkir opened this issue · comments

When reading Chapter 5 (Physics libraries) and trying to follow the book and type in the code examples
eg. how to define body:

void setup(){
    BodyDef bd = new BodyDef();
}
void draw(){
}

the code wouldn't compile, throwing the following error:

Cannot find class or type named BodyDef

the reason behind it is missing import of JBox2D library, namely:

import org.jbox2d.collision.shapes.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;

If someone decides to follow their intuition and "import library" and will go to PDE \\ Sketch \\ ImportLibrary \\ PBox2D it will only add import for

import pbox2d.*;

but not the jbox2d imports, which have to be added manually. This may create confusion and reader may get stuck with question

"I have imported PBox2D already and it still doesn't work? What's wrong with Processing? I need to file another bug to the processing github :)"

I believe that some clear instructions on manual import of those jbox2d packages should be mentioned in the chapter. Maybe in the beginning of the chapter, in a way similar to:

So that processing can work with Box2D we have to put those lines to the top of your sketch. Those lines will make processing aware of the PBox2D and(!) JBox2D libraries. To save paper trees and ink, I will not be mentioning this in every example in this chapter, but we know that this should be added to each your Box2D sketch.

import pbox2d.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;

this is a very good point, will definitely try to add something in for the next edition. thank you,

Agree, this is the problem I was running into. Only after some attempts did I make things right. Thanks for the post.

Thanks again for this great feedback. I added this to the very first example code and there is a code comment that explains (which will be highlighted next to this code area.)

//{!4} Note how in addition to the default important statement for 
// Box2D-for-Processing, I'm also importing packages from JBox2D itself.  
// This will be necessary for referencing certain objects that come from 
// JBox2D rather than Box2D-for-Processing.
import shiffman.box2d.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;