changed variables to 3d for motion computation