When the dice lands it is flat on a flat surface. That means either the tilt or the pan angle will be dividable by 90 degrees. You can then code a case distinction between a) either tilt or pan are dividable by 90 and b) what angle the angle is, that divides by 90. The combination of both should give you the number you want to achieve.