Add C++ change direction calculation.