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

The very first build system for The Nature of Code
http://natureofcode.com
913 stars 151 forks source link

In Box2D chapter, when explaining ChainShape there's errorneous refrence to ChainLoop class which doesn't seem to exist in Box2D #330

Closed dimkir closed 10 years ago

dimkir commented 11 years ago

In the paragraph about ChainShape (see excerpt below)

The ChainShape object is a series of connected vertices. To create the chain, we must first specify an array of vertices (each as a Vec2 object). For example, if we wanted a straight line from the left-hand side of our window to the right-hand side, we would just need an array of two vertices: (0,150) and (width,150). (Note that if you want to create a loop where the first vertex connects to the last vertex in a loop, you can use the ChainLoop class instead.)

There's a reference to this ChainLoop class. It seems like this class doesn't really exist in PBox2D. But rather chain may be looped using call to

ChainShape chain;
chain.createLoop(verticesArray, verticeCount);

// instead of this call, which just creates "unlooped" chain shape

chain.createChain(verticesArray, verticeCount);

ps. I am new to Box2D, and thus I may be wrong. However when I tried to declare ChainLoop class in PDE it was throwing error. And also tutorial on Box2D http://www.box2d.org/manual.html (search for string "ChainShape") doesn't mention any ChainLoop classes, but offers following code to create looped shapes:

// Create a loop. The first and last vertices are connected.

b2ChainShape chain;

chain.CreateLoop(vs, 4);

// as opposed to this code, which creates "unlooped" shapes
b2ChainShape chain;

chain.CreateChain(vs, 4);
shiffman commented 11 years ago

ah, yes, thanks for catching this. chainloop was from a previous version of box2d and i missed updating that part of the text

dimkir commented 11 years ago

It's my pleasure to be able to help! :) Thank you for writing the most amazing book on processing! :)

mr-nano commented 10 years ago

Hey guys I have jbox2d-library-2.1.2 jar and it doesn't seem to have ChainShape either!

mr-nano commented 10 years ago

I think I got rid of the problem, updated my jar to be of 2.2.1.1 version and it found the ChainShape :D

shiffman commented 10 years ago

Finally fixed this in new repo https://github.com/shiffman/The-Nature-of-Code/commit/bee4022396f850648945391debcfc075950eb21b