Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 1: Raymond Yang #23

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Part1.2 Finished
  • Loading branch information
UserRYang committed Sep 12, 2021
commit 53bbc11c1aea4a891e6401b2208d4710d3cb06f2
13 changes: 6 additions & 7 deletions src/kernel.cu
Original file line number Diff line number Diff line change
@@ -234,9 +234,12 @@ __device__ glm::vec3 computeVelocityChange(int N, int iSelf, const glm::vec3 *po
// Rule 2: boids try to stay a distance d away from each other
// Rule 3: boids try to match the speed of surrounding boids

float rule1NumNeighbor, rule3NumNeighbor;
float rule1NumNeighbor = 0.f;
float rule3NumNeighbor = 0.f;

glm::vec3 rule1Vel, rule2Vel, rule3Vel;
glm::vec3 rule1Vel(0.f);
glm::vec3 rule2Vel(0.f);
glm::vec3 rule3Vel(0.f);

const glm::vec3 myPos(pos[iSelf]);
const glm::vec3 myVel(vel[iSelf]);
@@ -268,7 +271,7 @@ __device__ glm::vec3 computeVelocityChange(int N, int iSelf, const glm::vec3 *po
}
}

glm::vec3 newVel;
glm::vec3 newVel = myVel;

if (rule1NumNeighbor > 0) {
newVel += (rule1Vel / rule1NumNeighbor - myPos) * rule1Scale;
@@ -283,10 +286,6 @@ __device__ glm::vec3 computeVelocityChange(int N, int iSelf, const glm::vec3 *po
// Clamp
if (glm::length(newVel) > maxSpeed) { newVel = glm::normalize(newVel) * maxSpeed; }

// Add original velocity and Clamp again
newVel += myVel;
if (glm::length(newVel) > maxSpeed) { newVel = glm::normalize(newVel) * maxSpeed; }

return newVel;
}