From 8722922ec861951c9f3bd9eb0e2b5a4334cc7a25 Mon Sep 17 00:00:00 2001 From: JH159753 Date: Sun, 30 Oct 2022 23:49:09 -0700 Subject: [PATCH 1/6] add even smoother movement for boid --- Boid.pde | 85 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/Boid.pde b/Boid.pde index 9c55d06..aaba96e 100644 --- a/Boid.pde +++ b/Boid.pde @@ -133,7 +133,7 @@ class Boid dotProductOfTargets = (dotProductOfTargets + 1) / 2; //use an ideal speed for our boid, to tell it to either speed up or slow down whether it's going faster than this or not - float idealSpeed = dotProductOfTargets * 20 + 10; + float idealSpeed = dotProductOfTargets * 80 + 10; if (kinematic.getSpeed() < idealSpeed) { kinematic.increaseSpeed(1,0); @@ -141,36 +141,35 @@ class Boid kinematic.increaseSpeed(-1,0); } - /* - if (kinematic.getSpeed() < 40 && direction.mag() > 30) { - kinematic.increaseSpeed(1,0); - } else if (kinematic.getSpeed() < 20 && direction.mag() > 15) { - kinematic.increaseSpeed(.75,0); - } else if (kinematic.getSpeed() < 10 && direction.mag() > 5) { - kinematic.increaseSpeed(.5,0); - } else if (kinematic.getSpeed() < 5 && direction.mag() < 5) { - //This should ensure that the boid's speed can be dropped to exactly 0 so we don't have stuttering - kinematic.increaseSpeed(-kinematic.getSpeed(),0); - } else { - kinematic.increaseSpeed(-1,0); - } - */ } else { //if no more targets to check, do the normal calculation - if (kinematic.getSpeed() < 40 && direction.mag() > 30) { + + //kinematic.getSpeed() is how fast we're moving, direction.mag() is how far are we from target + //Ideal speed here should be 80 at dist 85, and reduce linearly from there, hitting 0 at 5 units? + //This can be changed later if it isn't good + + float idealSpeed = (1 * direction.mag() - 5); + + //if idealSpeed is "negative" we should just set it to 0 + if (idealSpeed < 0) { + idealSpeed = 0; + } + + //use this to know how off the target speed we are, and slow down accordingly + //This will be positive if the ideal speed is higher than current speed, negative if ideal speed is lower. + float speedOffset = (idealSpeed - kinematic.getSpeed()); + + if (abs(speedOffset) < 1) { + kinematic.increaseSpeed(speedOffset, 0); + } else if (idealSpeed < speedOffset) { kinematic.increaseSpeed(1,0); - } else if (kinematic.getSpeed() < 20 && direction.mag() > 15) { - kinematic.increaseSpeed(.75,0); - } else if (kinematic.getSpeed() < 10 && direction.mag() > 5) { - kinematic.increaseSpeed(.5,0); - } else if (kinematic.getSpeed() < 5 && direction.mag() < 5) { - //This should ensure that the boid's speed can be dropped to exactly 0 so we don't have stuttering - kinematic.increaseSpeed(-kinematic.getSpeed(),0); - } else { + } else if (idealSpeed > speedOffset) { kinematic.increaseSpeed(-1,0); } + + } @@ -178,19 +177,33 @@ class Boid //if waypoints is null, do normal things println("waypoints is null"); + //This code should trigger if there's only one target left - if (kinematic.getSpeed() < 40 && direction.mag() > 30) { - kinematic.increaseSpeed(1,0); - } else if (kinematic.getSpeed() < 20 && direction.mag() > 15) { - kinematic.increaseSpeed(.75,0); - } else if (kinematic.getSpeed() < 10 && direction.mag() > 5) { - kinematic.increaseSpeed(.5,0); - } else if (kinematic.getSpeed() < 5 && direction.mag() < 5) { - //This should ensure that the boid's speed can be dropped to exactly 0 so we don't have stuttering - kinematic.increaseSpeed(-kinematic.getSpeed(),0); - } else { - kinematic.increaseSpeed(-1,0); - } + + //kinematic.getSpeed() is how fast we're moving, direction.mag() is how far are we from target + //Ideal speed here should be 80 at dist 85, and reduce linearly from there, hitting 0 at 5 units? + //This can be changed later if it isn't good + + float idealSpeed = 1 * direction.mag() - 5; + + //if idealSpeed is "negative" we should just set it to 0 + if (idealSpeed < 0) { + idealSpeed = 0; + } + + println(idealSpeed); + + //use this to know how off the target speed we are, and slow down accordingly + //This will be positive if the ideal speed is higher than current speed, negative if ideal speed is lower. + float speedOffset = (idealSpeed - kinematic.getSpeed()); + + if (abs(speedOffset) < 1) { + kinematic.increaseSpeed(speedOffset, 0); + } else if (idealSpeed < speedOffset) { + kinematic.increaseSpeed(1,0); + } else if (idealSpeed > speedOffset) { + kinematic.increaseSpeed(-1,0); + } } From 19fe85e1fc50daeb11a437a9ea1799261d2e9b3e Mon Sep 17 00:00:00 2001 From: JH159753 Date: Sun, 30 Oct 2022 23:50:38 -0700 Subject: [PATCH 2/6] Delete Boid10308162985695495767.autosave --- Boid10308162985695495767.autosave | 99 ------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 Boid10308162985695495767.autosave diff --git a/Boid10308162985695495767.autosave b/Boid10308162985695495767.autosave deleted file mode 100644 index f3b2a3b..0000000 --- a/Boid10308162985695495767.autosave +++ /dev/null @@ -1,99 +0,0 @@ -/// In this file, you will have to implement seek and waypoint-following -/// The relevant locations are marked with "TODO" - -class Crumb -{ - PVector position; - Crumb(PVector position) - { - this.position = position; - } - void draw() - { - fill(255); - noStroke(); - circle(this.position.x, this.position.y, CRUMB_SIZE); - } -} - -class Boid -{ - Crumb[] crumbs = {}; - int last_crumb; - float acceleration; - float rotational_acceleration; - KinematicMovement kinematic; - PVector target; - - Boid(PVector position, float heading, float max_speed, float max_rotational_speed, float acceleration, float rotational_acceleration) - { - this.kinematic = new KinematicMovement(position, heading, max_speed, max_rotational_speed); - this.last_crumb = millis(); - this.acceleration = acceleration; - this.rotational_acceleration = rotational_acceleration; - } - - void update(float dt) - { - if (target != null) - { - // TODO: Implement seek here - print(kinematic.getHeading()); - - } - - // place crumbs, do not change - if (LEAVE_CRUMBS && (millis() - this.last_crumb > CRUMB_INTERVAL)) - { - this.last_crumb = millis(); - this.crumbs = (Crumb[])append(this.crumbs, new Crumb(this.kinematic.position)); - if (this.crumbs.length > MAX_CRUMBS) - this.crumbs = (Crumb[])subset(this.crumbs, 1); - } - - // do not change - this.kinematic.update(dt); - - draw(); - } - - void draw() - { - for (Crumb c : this.crumbs) - { - c.draw(); - } - - fill(255); - noStroke(); - float x = kinematic.position.x; - float y = kinematic.position.y; - float r = kinematic.heading; - circle(x, y, BOID_SIZE); - // front - float xp = x + BOID_SIZE*cos(r); - float yp = y + BOID_SIZE*sin(r); - - // left - float x1p = x - (BOID_SIZE/2)*sin(r); - float y1p = y + (BOID_SIZE/2)*cos(r); - - // right - float x2p = x + (BOID_SIZE/2)*sin(r); - float y2p = y - (BOID_SIZE/2)*cos(r); - triangle(xp, yp, x1p, y1p, x2p, y2p); - } - - void seek(PVector target) - { - this.target = target; - - } - - void follow(ArrayList waypoints) - { - // TODO: change to follow *all* waypoints - this.target = waypoints.get(0); - - } -} From ce0baa87b548581b0ff8ca8fdff6525221071e07 Mon Sep 17 00:00:00 2001 From: JH159753 Date: Sun, 30 Oct 2022 23:50:43 -0700 Subject: [PATCH 3/6] Delete Boid1037558311854801587.autosave --- Boid1037558311854801587.autosave | 189 ------------------------------- 1 file changed, 189 deletions(-) delete mode 100644 Boid1037558311854801587.autosave diff --git a/Boid1037558311854801587.autosave b/Boid1037558311854801587.autosave deleted file mode 100644 index 2fe67df..0000000 --- a/Boid1037558311854801587.autosave +++ /dev/null @@ -1,189 +0,0 @@ -/// In this file, you will have to implement seek and waypoint-following -/// The relevant locations are marked with "TODO" - -class Crumb -{ - PVector position; - Crumb(PVector position) - { - this.position = position; - } - void draw() - { - fill(255); - noStroke(); - circle(this.position.x, this.position.y, CRUMB_SIZE); - } -} - -class Boid -{ - Crumb[] crumbs = {}; - int last_crumb; - float acceleration; - float rotational_acceleration; - KinematicMovement kinematic; - PVector target; - - Boid(PVector position, float heading, float max_speed, float max_rotational_speed, float acceleration, float rotational_acceleration) - { - this.kinematic = new KinematicMovement(position, heading, max_speed, max_rotational_speed); - this.last_crumb = millis(); - this.acceleration = acceleration; - this.rotational_acceleration = rotational_acceleration; - } - - void update(float dt) - { - if (target != null) - { - // TODO: Implement seek here - - - //This makes a vector with the direction our boid needs to go to - PVector direction = PVector.sub(target, kinematic.position); - - //atan2(direction.y, direction.x) will return the direction we need to go in radians - - //print direction we need to go and the direction we are facing right now - //println(atan2(direction.y, direction.x) + " " + normalize_angle_left_right(kinematic.getHeading())); - - float directionalThreshold = .1; - float angleToTarget = normalize_angle_left_right(atan2(direction.y, direction.x) - normalize_angle_left_right(kinematic.getHeading())); - float arrivalThreshold = 60.0; - - //This just draws a circle for visual debugging purposes - circle(target.x, target.y, 3); - - //prints the angle to the target - //println(angleToTarget); - - //if the angle is larger than the threshold in the positive direction, rotate counterclockwise - if (angleToTarget >= .1) { - println("positive angle"); - kinematic.increaseSpeed(0.0, 2); - - //if the angle is smaller than the threshold in the negative direction, rotate clockwise - } else if (angleToTarget < -.1) { - kinematic.increaseSpeed(0.0, -1); - - //if the angle is within our threshold, stop our rotational velocity by rotating opposite - } else if (directionalThreshold > angleToTarget) { - - if (kinematic.getRotationalVelocity() > 0) { - kinematic.increaseSpeed(0.0, -1); - } else if (kinematic.getRotationalVelocity() < 0) { - kinematic.increaseSpeed(0.0, 1); - } - - - - - //Sometimes our Boid just goes and does weird things and I don't know why - - //if the target is outside its arrival threshold, accelerate. - //if the target is inside its arrival threshold, accelerate backwards until the speed is 0. - if (direction.mag() > arrivalThreshold) { - kinematic.increaseSpeed(1,0); - } else if (direction.mag() < arrivalThreshold) { - //Need more specific code here to handle arrivals correctly - - if (kinematic.getSpeed() < 40 && direction.mag() > 30) { - kinematic.increaseSpeed(1,0); - } else if (kinematic.getSpeed() < 20 && direction.mag() > 15) { - kinematic.increaseSpeed(.75,0); - } else if (kinematic.getSpeed() < 10 && direction.mag() > 5) { - kinematic.increaseSpeed(.5,0); - } else if (kinematic.getSpeed() < 5 && direction.mag() < 5) { - //This should ensure that the boid's speed can be dropped to exactly 0 so we don't have stuttering - kinematic.increaseSpeed(-kinematic.getSpeed(),0); - } else { - kinematic.increaseSpeed(-1,0); - } - - - - } - } - - - - //drawing a line for testing purposes - //line(kinematic.position.x, kinematic.position.y, kinematic.position.x + direction.x, kinematic.position.y + direction.y); - } - - // place crumbs, do not change - if (LEAVE_CRUMBS && (millis() - this.last_crumb > CRUMB_INTERVAL)) - { - this.last_crumb = millis(); - this.crumbs = (Crumb[])append(this.crumbs, new Crumb(this.kinematic.position)); - if (this.crumbs.length > MAX_CRUMBS) - this.crumbs = (Crumb[])subset(this.crumbs, 1); - } - - // do not change - this.kinematic.update(dt); - - draw(); - } - - void draw() - { - for (Crumb c : this.crumbs) - { - c.draw(); - } - - fill(255); - noStroke(); - float x = kinematic.position.x; - float y = kinematic.position.y; - float r = kinematic.heading; - circle(x, y, BOID_SIZE); - // front - float xp = x + BOID_SIZE*cos(r); - float yp = y + BOID_SIZE*sin(r); - - // left - float x1p = x - (BOID_SIZE/2)*sin(r); - float y1p = y + (BOID_SIZE/2)*cos(r); - - // right - float x2p = x + (BOID_SIZE/2)*sin(r); - float y2p = y - (BOID_SIZE/2)*cos(r); - triangle(xp, yp, x1p, y1p, x2p, y2p); - } - - void seek(PVector target) - { - this.target = target; - } -int count = 0; - - //void follow(ArrayList waypoints) - //{ - - // //println("func count " + count); - // if(count > waypoints.size() - 1){ - // this.target = waypoints.get(0); - // return; - // } - // else { - // // TODO: change to follow *all* waypoints - // println("count " + count); - // this.target = waypoints.get(count); - // PVector temp = waypoints.remove(count); - // count++; - // //count--; - - // follow(waypoints); - // } - - //} - void follow(ArrayList waypoints) - { - this.target = waypoints.get(0); - - - } -} From 88967458d9a74c46659a7dca1c1c243f93aa1d46 Mon Sep 17 00:00:00 2001 From: JH159753 Date: Sun, 30 Oct 2022 23:50:48 -0700 Subject: [PATCH 4/6] Delete Boid10419224425232634497.autosave --- Boid10419224425232634497.autosave | 175 ------------------------------ 1 file changed, 175 deletions(-) delete mode 100644 Boid10419224425232634497.autosave diff --git a/Boid10419224425232634497.autosave b/Boid10419224425232634497.autosave deleted file mode 100644 index 73e7fb9..0000000 --- a/Boid10419224425232634497.autosave +++ /dev/null @@ -1,175 +0,0 @@ -/// In this file, you will have to implement seek and waypoint-following -/// The relevant locations are marked with "TODO" - -class Crumb -{ - PVector position; - Crumb(PVector position) - { - this.position = position; - } - void draw() - { - fill(255); - noStroke(); - circle(this.position.x, this.position.y, CRUMB_SIZE); - } -} - -class Boid -{ - Crumb[] crumbs = {}; - int last_crumb; - float acceleration; - float rotational_acceleration; - KinematicMovement kinematic; - PVector target; - - Boid(PVector position, float heading, float max_speed, float max_rotational_speed, float acceleration, float rotational_acceleration) - { - this.kinematic = new KinematicMovement(position, heading, max_speed, max_rotational_speed); - this.last_crumb = millis(); - this.acceleration = acceleration; - this.rotational_acceleration = rotational_acceleration; - } - - void update(float dt) - { - if (target != null) - { - // TODO: Implement seek here - - - //This makes a vector with the direction our boid needs to go to - PVector direction = PVector.sub(target, kinematic.position); - - //atan2(direction.y, direction.x) will return the direction we need to go in radians - - //print direction we need to go and the direction we are facing right now - //println(atan2(direction.y, direction.x) + " " + normalize_angle_left_right(kinematic.getHeading())); - - float directionalThreshold = .1; - float angleToTarget = normalize_angle(atan2(direction.y, direction.x)) - kinematic.getHeading(); - float arrivalThreshold = 60.0; - - //This just draws a circle for visual debugging purposes - //circle(target.x, target.y, arrivalThreshold); - - //prints the angle to the target - //println(angleToTarget); - - //if the angle is larger than the threshold in the positive direction, rotate counterclockwise - if (angleToTarget > directionalThreshold) { - kinematic.increaseSpeed(0.0, 1); - - //if the angle is smaller than the threshold in the negative direction, rotate clockwise - } else if (angleToTarget < -directionalThreshold) { - kinematic.increaseSpeed(0.0, -1); - - //if the angle is within our threshold, stop our rotational velocity by rotating opposite - } else if (directionalThreshold > angleToTarget) { - - if (kinematic.getRotationalVelocity() > 0) { - kinematic.increaseSpeed(0.0, -1); - } - else if (kinematic.getRotationalVelocity() < 0) { - kinematic.increaseSpeed(0.0, 1); - } - } - - - - //Slight flaw: since the arrival threshold is so big, the boid just won't move if its target is that close. - - //if the target is outside its arrival threshold, accelerate. - //if the target is inside its arrival threshold, accelerate backwards until the speed is 0. - if (direction.mag() > arrivalThreshold) { - kinematic.increaseSpeed(1,0); - } else if (direction.mag() < arrivalThreshold) { - //Need more specific code here to handle arrivals correctly - - if (kinematic.getSpeed() < 40 && direction.mag() > 30) { - kinematic.increaseSpeed(1,0); - } else if (kinematic.getSpeed() < 20 && direction.mag() > 15) { - kinematic.increaseSpeed(.75,0); - } else if (kinematic.getSpeed() < 10 && direction.mag() > 5) { - kinematic.increaseSpeed(.5,0); - } else if (kinematic.getSpeed() < 5 && direction.mag() < 3) { - kinematic.increaseSpeed(.25,0); - } else { - kinematic.increaseSpeed(-1,0); - } - - - } - - - - //drawing a line for testing purposes - //line(kinematic.position.x, kinematic.position.y, kinematic.position.x + direction.x, kinematic.position.y + direction.y); - - - - - - - - - - } - - // place crumbs, do not change - if (LEAVE_CRUMBS && (millis() - this.last_crumb > CRUMB_INTERVAL)) - { - this.last_crumb = millis(); - this.crumbs = (Crumb[])append(this.crumbs, new Crumb(this.kinematic.position)); - if (this.crumbs.length > MAX_CRUMBS) - this.crumbs = (Crumb[])subset(this.crumbs, 1); - } - - // do not change - this.kinematic.update(dt); - - draw(); - } - - void draw() - { - for (Crumb c : this.crumbs) - { - c.draw(); - } - - fill(255); - noStroke(); - float x = kinematic.position.x; - float y = kinematic.position.y; - float r = kinematic.heading; - circle(x, y, BOID_SIZE); - // front - float xp = x + BOID_SIZE*cos(r); - float yp = y + BOID_SIZE*sin(r); - - // left - float x1p = x - (BOID_SIZE/2)*sin(r); - float y1p = y + (BOID_SIZE/2)*cos(r); - - // right - float x2p = x + (BOID_SIZE/2)*sin(r); - float y2p = y - (BOID_SIZE/2)*cos(r); - triangle(xp, yp, x1p, y1p, x2p, y2p); - } - - void seek(PVector target) - { - this.target = target; - - } - - void follow(ArrayList waypoints) - { - // TODO: change to follow *all* waypoints - this.target = waypoints.get(0); - - } -} From 385a1a9354442cee0193de8736072d84e60dec20 Mon Sep 17 00:00:00 2001 From: JH159753 Date: Sun, 30 Oct 2022 23:50:55 -0700 Subject: [PATCH 5/6] Delete Boid17200078021981803956.autosave --- Boid17200078021981803956.autosave | 198 ------------------------------ 1 file changed, 198 deletions(-) delete mode 100644 Boid17200078021981803956.autosave diff --git a/Boid17200078021981803956.autosave b/Boid17200078021981803956.autosave deleted file mode 100644 index 15350a8..0000000 --- a/Boid17200078021981803956.autosave +++ /dev/null @@ -1,198 +0,0 @@ -/// In this file, you will have to implement seek and waypoint-following -/// The relevant locations are marked with "TODO" - -class Crumb -{ - PVector position; - Crumb(PVector position) - { - this.position = position; - } - void draw() - { - fill(255); - noStroke(); - circle(this.position.x, this.position.y, CRUMB_SIZE); - } -} - -class Boid -{ - Crumb[] crumbs = {}; - int last_crumb; - float acceleration; - float rotational_acceleration; - KinematicMovement kinematic; - PVector target; - - Boid(PVector position, float heading, float max_speed, float max_rotational_speed, float acceleration, float rotational_acceleration) - { - this.kinematic = new KinematicMovement(position, heading, max_speed, max_rotational_speed); - this.last_crumb = millis(); - this.acceleration = acceleration; - this.rotational_acceleration = rotational_acceleration; - } - - void update(float dt) - { - if (target != null) - { - // TODO: Implement seek here - - - //This makes a vector with the direction our boid needs to go to - PVector direction = PVector.sub(target, kinematic.position); - - //atan2(direction.y, direction.x) will return the direction we need to go in radians - - //print direction we need to go and the direction we are facing right now - //println(atan2(direction.y, direction.x) + " " + normalize_angle_left_right(kinematic.getHeading())); - - float directionalThreshold = .1; - float angleToTarget = normalize_angle_left_right(atan2(direction.y, direction.x) - normalize_angle_left_right(kinematic.getHeading())); - float arrivalThreshold = 60.0; - - //This just draws a circle for visual debugging purposes - circle(target.x, target.y, 3); - - //prints the angle to the target - //println(angleToTarget); - - //if the angle is larger than the threshold in the positive direction, rotate counterclockwise - if (angleToTarget >= .1) { - println("positive angle"); - kinematic.increaseSpeed(0.0, 2); - - //if the angle is smaller than the threshold in the negative direction, rotate clockwise - } else if (angleToTarget < -.1) { - kinematic.increaseSpeed(0.0, -1); - - //if the angle is within our threshold, stop our rotational velocity by rotating opposite - } else if (directionalThreshold > angleToTarget) { - - if (kinematic.getRotationalVelocity() > 0) { - kinematic.increaseSpeed(0.0, -1); - } else if (kinematic.getRotationalVelocity() < 0) { - kinematic.increaseSpeed(0.0, 1); - } - } - - - - //Sometimes our Boid just goes and does weird things and I don't know why - - //if the target is outside its arrival threshold, accelerate. - //if the target is inside its arrival threshold, accelerate backwards until the speed is 0. - if (direction.mag() > arrivalThreshold) { - //println("main if"); - kinematic.increaseSpeed(.5, 0); - } else if (direction.mag() < arrivalThreshold) { - //Need more specific code here to handle arrivals correctly - - if (kinematic.getSpeed() < 40 && direction.mag() > 30) { - //println("if 1"); - kinematic.increaseSpeed(1, 0); - } else if (kinematic.getSpeed() < 20 && direction.mag() > 15) { - //println("if .75"); - kinematic.increaseSpeed(.75, 0); - } else if (kinematic.getSpeed() < 10 && direction.mag() > 5) { - //println("if .5"); - kinematic.increaseSpeed(.5, 0); - } else if (kinematic.getSpeed() < 5 && direction.mag() < 5) { - //println("if -kin"); - //This should ensure that the boid's speed can be dropped to exactly 0 so we don't have stuttering - - kinematic.increaseSpeed(-kinematic.getSpeed(), 0); - } else { - println("else"); - kinematic.increaseSpeed(-1, 0); - } - } - - - - //drawing a line for testing purposes - //line(kinematic.position.x, kinematic.position.y, kinematic.position.x + direction.x, kinematic.position.y + direction.y); - } - - // place crumbs, do not change - if (LEAVE_CRUMBS && (millis() - this.last_crumb > CRUMB_INTERVAL)) - { - this.last_crumb = millis(); - this.crumbs = (Crumb[])append(this.crumbs, new Crumb(this.kinematic.position)); - if (this.crumbs.length > MAX_CRUMBS) - this.crumbs = (Crumb[])subset(this.crumbs, 1); - } - - // do not change - this.kinematic.update(dt); - - draw(); - } - - void draw() - { - for (Crumb c : this.crumbs) - { - c.draw(); - } - - fill(255); - noStroke(); - float x = kinematic.position.x; - float y = kinematic.position.y; - float r = kinematic.heading; - circle(x, y, BOID_SIZE); - // front - float xp = x + BOID_SIZE*cos(r); - float yp = y + BOID_SIZE*sin(r); - - // left - float x1p = x - (BOID_SIZE/2)*sin(r); - float y1p = y + (BOID_SIZE/2)*cos(r); - - // right - float x2p = x + (BOID_SIZE/2)*sin(r); - float y2p = y - (BOID_SIZE/2)*cos(r); - triangle(xp, yp, x1p, y1p, x2p, y2p); - } - - void seek(PVector target) - { - this.target = target; - } -int count = 0; - - //void follow(ArrayList waypoints) - //{ - - // //println("func count " + count); - // if(count > waypoints.size() - 1){ - // this.target = waypoints.get(0); - // return; - // } - // else { - // // TODO: change to follow *all* waypoints - // println("count " + count); - // this.target = waypoints.get(count); - // PVector temp = waypoints.remove(count); - // count++; - // //count--; - - // follow(waypoints); - // } - - //} - void follow(ArrayList waypoints) - { - this.target = waypoints.get(0); - // println("distance " + PVector.sub(this.target,this.kinematic.position).mag()); - for (int i = 1; i < waypoints.size(); i++){ - println("distance " + PVector.sub(this.target,this.kinematic.position).mag()); - if(PVector.sub(this.target,this.kinematic.position).mag() < 4) - this.target = waypoints.get(i); - - } - } - -} From e9802c54ac3a7fbefa9fef2d7c32ce1e1fb86d56 Mon Sep 17 00:00:00 2001 From: JH159753 Date: Sun, 30 Oct 2022 23:55:33 -0700 Subject: [PATCH 6/6] fix weird merge breaking stuff --- Boid.pde | 151 +------------------------------------------------------ 1 file changed, 1 insertion(+), 150 deletions(-) diff --git a/Boid.pde b/Boid.pde index e7eec17..aaba96e 100644 --- a/Boid.pde +++ b/Boid.pde @@ -1,6 +1,6 @@ /// In this file, you will have to implement seek and waypoint-following /// The relevant locations are marked with "TODO" -import java.util.*; + class Crumb { PVector position; @@ -18,61 +18,6 @@ class Crumb class Boid { -<<<<<<< HEAD - Crumb[] crumbs = {}; - int last_crumb; - float acceleration; - float rotational_acceleration; - KinematicMovement kinematic; - PVector target; - - Boid(PVector position, float heading, float max_speed, float max_rotational_speed, float acceleration, float rotational_acceleration) - { - this.kinematic = new KinematicMovement(position, heading, max_speed, max_rotational_speed); - this.last_crumb = millis(); - this.acceleration = acceleration; - this.rotational_acceleration = rotational_acceleration; - } - - void update(float dt) - { - - if (waypoints != null) { - for (int i = 0; i= .1) { - //println("positive angle"); - kinematic.increaseSpeed(0.0, 2); - -======= Crumb[] crumbs = {}; int last_crumb; float acceleration; @@ -91,7 +36,6 @@ class Boid this.acceleration = acceleration; this.rotational_acceleration = rotational_acceleration; } ->>>>>>> 3d16b646a807cb7a2384072f4c267c5888644f96 void update(float dt) { @@ -142,39 +86,6 @@ class Boid kinematic.increaseSpeed(0.0, kinematic.getRotationalVelocity()); } } -<<<<<<< HEAD - } - - - - //Sometimes our Boid just goes and does weird things and I don't know why - - //if the target is outside its arrival threshold, accelerate. - //if the target is inside its arrival threshold, accelerate backwards until the speed is 0. - if (direction.mag() > arrivalThreshold) { - //println("main if"); - kinematic.increaseSpeed(.5, 0); - } else if (direction.mag() < arrivalThreshold) { - //Need more specific code here to handle arrivals correctly - - if (kinematic.getSpeed() < 40 && direction.mag() > 30) { - //println("if 1"); - kinematic.increaseSpeed(1, 0); - } else if (kinematic.getSpeed() < 20 && direction.mag() > 15) { - //println("if .75"); - kinematic.increaseSpeed(.75, 0); - } else if (kinematic.getSpeed() < 10 && direction.mag() > 5) { - //println("if .5"); - kinematic.increaseSpeed(.5, 0); - } else if (kinematic.getSpeed() < 5 && direction.mag() < 5) { - //println("if -kin"); - //This should ensure that the boid's speed can be dropped to exactly 0 so we don't have stuttering - - kinematic.increaseSpeed(-kinematic.getSpeed(), 0); - } else { - //println("else"); - kinematic.increaseSpeed(-1, 0); -======= @@ -296,7 +207,6 @@ class Boid } ->>>>>>> 3d16b646a807cb7a2384072f4c267c5888644f96 } @@ -341,64 +251,6 @@ class Boid } -<<<<<<< HEAD - // //println("func count " + count); - // if(count > waypoints.size() - 1){ - // this.target = waypoints.get(0); - // return; - // } - // else { - // // TODO: change to follow *all* waypoints - // println("count " + count); - // this.target = waypoints.get(count); - // PVector temp = waypoints.remove(count); - // count++; - // //count--; - - // follow(waypoints); - // } - - //} - void follow(ArrayList waypoints) - { - if(waypoints.size() == 0) return; - println("vector " + waypoints); - println("reverse vector " + waypoints); - int count = 0; - PVector stop = waypoints.get(0); - this.seek(stop); - - - - - PVector temp = waypoints.remove(0); - println("temp vector " + waypoints); - //follow(waypoints); - - //this.target = waypoints.get(0); - //do{ - - - // println("in while " + count); - ////this.target = waypoints.get(count); - //this.target = waypoints.get(count); - //if(PVector.sub(this.target,this.kinematic.position).mag() < 40){ - // count++; - //} - - - //}while(count < waypoints.size()); - //count++; - //for(int i = 1; i < waypoints.size(); i++){ - // println("dist " + PVector.sub(this.target,this.kinematic.position).mag()); - // if(PVector.sub(this.target,this.kinematic.position).mag() < 40){ - // this.seek(waypoints.get(i)); - // this.target = waypoints.get(i); - // } - - } - -======= // place crumbs, do not change if (LEAVE_CRUMBS && (millis() - this.last_crumb > CRUMB_INTERVAL)) { @@ -461,5 +313,4 @@ class Boid } ->>>>>>> 3d16b646a807cb7a2384072f4c267c5888644f96 }