From f1a8992ed75dfea79bbcb2bc9f6d44b7f6543e9a Mon Sep 17 00:00:00 2001 From: mshaub Date: Thu, 4 Jan 2018 10:37:34 -0600 Subject: [PATCH 1/4] Boid.pde The original file wouldn't run in Processing3 (3.3.2) throwing an error that vairable pos didn't exist. Added the creation of the variable and modified the line throwing the error under display() --- chp06_agents/box2d/Flocking_box2d/Boid.pde | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chp06_agents/box2d/Flocking_box2d/Boid.pde b/chp06_agents/box2d/Flocking_box2d/Boid.pde index cb001acc..df9e0f7a 100644 --- a/chp06_agents/box2d/Flocking_box2d/Boid.pde +++ b/chp06_agents/box2d/Flocking_box2d/Boid.pde @@ -16,6 +16,8 @@ class Boid { float maxforce; // Maximum steering force float maxspeed; // Maximum speed + + Vec2 pos = new Vec2(0,0); //create the "pos" variable, seems req. for Processing3 Boid(PVector pos) { w = 12; @@ -84,7 +86,8 @@ class Boid { // Drawing the box void display() { // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); + //Vec2 pos = box2d.getBodyPixelCoord(body); //caused an error in Processing3 + pos = box2d.getBodyPixelCoord(body); //assumes variable "pos" already exists // Get its angle of rotation float a = body.getAngle(); From 6ec47930fbbce227a83e8f9fd16b012c50431c38 Mon Sep 17 00:00:00 2001 From: mshaub Date: Fri, 5 Jan 2018 08:40:19 -0600 Subject: [PATCH 2/4] Boid.pde a variable "loc" was used in some locations that should be "pos." All instances of "loc" have been changed to "pos" --- chp06_agents/box2d/Flocking_box2d/Boid.pde | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/chp06_agents/box2d/Flocking_box2d/Boid.pde b/chp06_agents/box2d/Flocking_box2d/Boid.pde index df9e0f7a..554e44d5 100644 --- a/chp06_agents/box2d/Flocking_box2d/Boid.pde +++ b/chp06_agents/box2d/Flocking_box2d/Boid.pde @@ -16,8 +16,6 @@ class Boid { float maxforce; // Maximum steering force float maxspeed; // Maximum speed - - Vec2 pos = new Vec2(0,0); //create the "pos" variable, seems req. for Processing3 Boid(PVector pos) { w = 12; @@ -49,17 +47,17 @@ class Boid { ali.mulLocal(1); coh.mulLocal(1); // Add the force vectors to acceleration - Vec2 loc = body.getWorldCenter(); - body.applyForce(sep,loc); - body.applyForce(ali,loc); - body.applyForce(coh,loc); + Vec2 pos = body.getWorldCenter(); + body.applyForce(sep,pos); + body.applyForce(ali,pos); + body.applyForce(coh,pos); } // A method that calculates and applies a steering force towards a target // STEER = DESIRED MINUS VELOCITY Vec2 seek(Vec2 target) { - Vec2 loc = body.getWorldCenter(); - Vec2 desired = target.sub(loc); // A vector pointing from the position to the target + Vec2 pos = body.getWorldCenter(); + Vec2 desired = target.sub(pos); // A vector pointing from the position to the target // If the magnitude of desired equals 0, skip out of here // (We could optimize this to check if x and y are 0 to avoid mag() square root @@ -86,8 +84,8 @@ class Boid { // Drawing the box void display() { // We look at each body and get its screen position - //Vec2 pos = box2d.getBodyPixelCoord(body); //caused an error in Processing3 - pos = box2d.getBodyPixelCoord(body); //assumes variable "pos" already exists + + Vec2 pos = box2d.getBodyPixelCoord(body); // Get its angle of rotation float a = body.getAngle(); @@ -105,7 +103,7 @@ class Boid { // Wraparound void borders() { - Vec2 loc = box2d.getBodyPixelCoord(body); + Vec2 pos = box2d.getBodyPixelCoord(body); Vec2 vel = body.getLinearVelocity(); float a = body.getAngularVelocity(); if (pos.x < -w) { @@ -257,4 +255,3 @@ class Boid { } - From bf544697a6d3f18a395a23b73c482f9d57715c0c Mon Sep 17 00:00:00 2001 From: mshaub Date: Fri, 5 Jan 2018 08:41:52 -0600 Subject: [PATCH 3/4] Boid all instances of variable "loc" have been changed to "pos" --- chp06_agents/box2d/Flocking_box2d/Boid.pde | 1 - 1 file changed, 1 deletion(-) diff --git a/chp06_agents/box2d/Flocking_box2d/Boid.pde b/chp06_agents/box2d/Flocking_box2d/Boid.pde index 554e44d5..e5428932 100644 --- a/chp06_agents/box2d/Flocking_box2d/Boid.pde +++ b/chp06_agents/box2d/Flocking_box2d/Boid.pde @@ -84,7 +84,6 @@ class Boid { // Drawing the box void display() { // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); // Get its angle of rotation From 0fe24f12df2a4f493656f9c409c811876155e130 Mon Sep 17 00:00:00 2001 From: mshaub Date: Fri, 5 Jan 2018 08:42:45 -0600 Subject: [PATCH 4/4] Boid.pde All instances of the variable "loc" have been changed to "pos" --- chp06_agents/box2d/Flocking_box2d/Boid.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chp06_agents/box2d/Flocking_box2d/Boid.pde b/chp06_agents/box2d/Flocking_box2d/Boid.pde index e5428932..b2d06fa9 100644 --- a/chp06_agents/box2d/Flocking_box2d/Boid.pde +++ b/chp06_agents/box2d/Flocking_box2d/Boid.pde @@ -84,7 +84,7 @@ class Boid { // Drawing the box void display() { // We look at each body and get its screen position - Vec2 pos = box2d.getBodyPixelCoord(body); + Vec2 pos = box2d.getBodyPixelCoord(body); // Get its angle of rotation float a = body.getAngle();