DeltaManipulation.Rotation如何判断旋转是顺时针还是逆时针?
DeltaManipulation.Rotation how determine if rotation is clockwise or counterclockwise?
我需要使用 DeltaManipulation.Rotation 确定旋转方向。
该代码有效,但每次顺时针或逆时针完全旋转时都会出现 return 错误信息。
我做错了什么?
int oldValue = 0;
int realValue;
private void ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
e.Handled = true;
MyRotateTransform.Angle += e.DeltaManipulation.Rotation;
int angle = (int)MyRotateTransform.Angle;
realValue = angle % 360;
if (realValue < 0)
{
realValue = 360 - (-realValue);
}
if (realValue > oldValue)
{
//clockwise rotation
oldValue = realValue;
}
if (realValue < oldValue)
{
//counterclockwise rotation
oldValue = realValue;
}
}
不检查 MyRotateTransform.Angle
中的累积(和归一化)旋转角度。相反,只需检查 e.DeltaManipulation.Rotation
.
如果小于零,则逆时针旋转,如果大于零,则顺时针旋转:
if (e.DeltaManipulation.Rotation < 0)
{
Debug.WriteLine("counterclockwise");
}
else if (e.DeltaManipulation.Rotation > 0)
{
Debug.WriteLine("clockwise");
}
我需要使用 DeltaManipulation.Rotation 确定旋转方向。 该代码有效,但每次顺时针或逆时针完全旋转时都会出现 return 错误信息。 我做错了什么?
int oldValue = 0;
int realValue;
private void ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
e.Handled = true;
MyRotateTransform.Angle += e.DeltaManipulation.Rotation;
int angle = (int)MyRotateTransform.Angle;
realValue = angle % 360;
if (realValue < 0)
{
realValue = 360 - (-realValue);
}
if (realValue > oldValue)
{
//clockwise rotation
oldValue = realValue;
}
if (realValue < oldValue)
{
//counterclockwise rotation
oldValue = realValue;
}
}
不检查 MyRotateTransform.Angle
中的累积(和归一化)旋转角度。相反,只需检查 e.DeltaManipulation.Rotation
.
如果小于零,则逆时针旋转,如果大于零,则顺时针旋转:
if (e.DeltaManipulation.Rotation < 0)
{
Debug.WriteLine("counterclockwise");
}
else if (e.DeltaManipulation.Rotation > 0)
{
Debug.WriteLine("clockwise");
}