fix weird merge breaking stuff
This commit is contained in:
parent
385a1a9354
commit
e9802c54ac
151
Boid.pde
151
Boid.pde
|
@ -1,6 +1,6 @@
|
||||||
/// In this file, you will have to implement seek and waypoint-following
|
/// In this file, you will have to implement seek and waypoint-following
|
||||||
/// The relevant locations are marked with "TODO"
|
/// The relevant locations are marked with "TODO"
|
||||||
import java.util.*;
|
|
||||||
class Crumb
|
class Crumb
|
||||||
{
|
{
|
||||||
PVector position;
|
PVector position;
|
||||||
|
@ -18,61 +18,6 @@ class Crumb
|
||||||
|
|
||||||
class Boid
|
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<waypoints.size(); i++)
|
|
||||||
{
|
|
||||||
text(i, waypoints.get(i).x + 10, waypoints.get(i).y + 10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
=======
|
|
||||||
Crumb[] crumbs = {};
|
Crumb[] crumbs = {};
|
||||||
int last_crumb;
|
int last_crumb;
|
||||||
float acceleration;
|
float acceleration;
|
||||||
|
@ -91,7 +36,6 @@ class Boid
|
||||||
this.acceleration = acceleration;
|
this.acceleration = acceleration;
|
||||||
this.rotational_acceleration = rotational_acceleration;
|
this.rotational_acceleration = rotational_acceleration;
|
||||||
}
|
}
|
||||||
>>>>>>> 3d16b646a807cb7a2384072f4c267c5888644f96
|
|
||||||
|
|
||||||
void update(float dt)
|
void update(float dt)
|
||||||
{
|
{
|
||||||
|
@ -142,39 +86,6 @@ class Boid
|
||||||
kinematic.increaseSpeed(0.0, kinematic.getRotationalVelocity());
|
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<PVector> 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
|
// place crumbs, do not change
|
||||||
if (LEAVE_CRUMBS && (millis() - this.last_crumb > CRUMB_INTERVAL))
|
if (LEAVE_CRUMBS && (millis() - this.last_crumb > CRUMB_INTERVAL))
|
||||||
{
|
{
|
||||||
|
@ -461,5 +313,4 @@ class Boid
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
>>>>>>> 3d16b646a807cb7a2384072f4c267c5888644f96
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue