Example #1
0
/* Constraints */
void Particle::solveConstraints()
{
    /* Link Constraints */
    // Links make sure particles connected to this one is at a set distance away


    for (int i = 0; i < links.size(); i++)
    {
        Link * currentLink = (Link *) links.at(i);
        currentLink->constraintSolve();
    }

    /* Boundary Constraints */
    // These if statements keep the particles within the screen
    if (position.y < 1)
        position.y = 2 * (1) - position.y;
    if (position.y > ofGetHeight()-1)
        position.y = 2 * (ofGetHeight() - 1) - position.y;
    if (position.x > ofGetWidth()-1)
        position.x = 2 * (ofGetWidth() - 1) - position.x;
    if (position.x < 1)
        position.x = 2 * (1) - position.x;

    /* Other Constraints */
    // make sure the particle stays in its place if it's pinned
    if (pinned)
        position = pinLocation;

}