Added directionToMatrix