2013-08-23 63 views

回答

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; 
相關問題