We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Why does changing:
void render() {
if (type == 1) {
fill(156, 206, 255);
stroke(16, 16, 222);
ellipse(pos.x, pos.y, mass, mass);
PVector dir = vel.get();
dir.normalize();
line(pos.x, pos.y, pos.x + dir.x*10, pos.y + dir.y*10);
}
else if (type == 2) {
// Draw a triangle rotated in the direction of velocity
float theta = vel.heading2D() + radians(90);
pushMatrix();
translate(pos.x, pos.y);
rotate(theta);
fill(220, 0, 0);
noStroke();
beginShape(TRIANGLES);
vertex(0, -mass);
vertex(-3, mass);
vertex(3, mass);
endShape();
popMatrix();
}
to this :
void render() {
if (type == 1) {
fill(156, 206, 255);
stroke(16, 16, 222);
ellipse(pos.x, pos.y, mass, mass);
PVector dir = vel.get();
dir.normalize();
line(pos.x, pos.y, pos.x + dir.x*10, pos.y + dir.y*10);
}
else if (type == 2) {
// Draw a triangle rotated in the direction of velocity
float theta = vel.heading2D() + radians(90);
pushMatrix();
translate(pos.x, pos.y);
rotate(theta);
fill(220, 52, 255);
stroke(16, 16, 222);
ellipse(pos.x, pos.y, mass, mass);
PVector dir = vel.get();
dir.normalize();
line(pos.x, pos.y, pos.x + dir.x*10, pos.y + dir.y*10);
popMatrix();
}
make the type 2 boids whizz around erratically and go outside the boundary?
I only wanted to change the shape and colour of the render to the same shape as type 1 but red, because they're representing parasitized sheep rather than predators now.
Answers
Ah, sorry, fixed it myself already!!
(I don't know why it worked, but I just commented out
Because you already used the pos PVector (I assume it's a PVector) in ellipse()/line(), shifting the current transformation matrix by pos would actually double the translation. Just replace line 19 and 22 in the above shown code with the following two lines:
As you already translated by pos, you don't need to use pos in you drawing functions.