当手指触摸移动时,我正在处理旋转图像!而且我不知道如何在触摸移动发生时获得 x、y、z 旋转角度。有人知道吗?请帮忙,谢谢!
问问题
103 次
1 回答
0
通过 X/Y/Z 旋转,我假设您想要某种轨迹球,如控制小部件。要实现这一点,您需要考虑使用四元数。
对于更简单的旋转形式,请将滚动为零,并将 x 运动映射到偏航,将 y 运动映射到俯仰......
dx = x - lastX;
dy = y - lastY;
rotation.x -= dy;
rotation.y += dx;
rotation.z = 0;
然后夹紧旋转,使偏航运动不会反转
rotation.y = min(max(rotation.y, -pi/2), pi/2);
或者,如果您想在拖动时找到围绕屏幕中心的旋转...
midX = screenWidth/2;
midY = screenHeight/2;
downAngle = atan2(downX-midX, downY-midY); //angle from +x to start position of rotation
upAndle = atan2(upX-midX, upY-midY); //angle from +x to current position
angle = upAndle - downAngle; //difference between them
if (angle > pi) angle -= 2*pi; //keep angle less than 180 degrees in either direction
if (angle < -pi) angle += 2*pi;
于 2013-08-23T09:44:46.933 回答