Example #1
0
// Here we overload the - operator so we can subtract vectors 
boost::shared_ptr<Vector3d> Vector3d::operator-(Vector3d &rhs)
{
    boost::shared_ptr<Vector3d> result(new Vector3d);
    
    // Test if the 'rhs' vector has direction.  If so update accordingly.
    if (rhs.hasDirection())
    {
        // Initialize the direction portion of the vector.
        result->withDirection();
        
        // Assign directions.
        result->setDirX(rhs.getDirX());
        result->setDirY(rhs.getDirY());
        result->setDirZ(rhs.getDirZ());
    }

    // Bounds are zero based.  That is, the interval is between 0 -> upper bound.
    //result->location.x = this->location.x - abs((this->location.x) - (rhs.location.x));
    result->location.x = (this->location.x) - (rhs.location.x);
    result->location.y = (this->location.y) - (rhs.location.y);
    result->location.z = (this->location.z) - (rhs.location.z);
    
    return result;
}