關(guān)于3D旋轉(zhuǎn)的原理,請(qǐng)看Daniel Lehenbauer的文章 《Rotating the Camera with the Mouse》
里面非常清楚的講解了原理和方法,,很受用,。
相關(guān)代碼:
2.1 Finding the Point on the Sphere private Vector3D ProjectToTrackball(Double width, Double height, Point point) x = x - 1; // Translate 0,0 to the center Double z2 = 1 - x * x - y * y; // z^2 = 1 - x^2 - y^2
2.2 Rotating Between the Points private void Rotate(Point currentPosition) Vector3D axis = Vector3D.CrossProduct(_previousRotPosition3D, currentPosition3D); Rotate(axis, angle); _previousRotPosition3D = currentPosition3D;
private void Rotate(Vector3D axis, Double angle) Quaternion q = new Quaternion(_axisAngleRotation3D.Axis, _axisAngleRotation3D.Angle); q *= delta; Vector3D zeorVec = new Vector3D(0.0, 0.0, 0.0); _axisAngleRotation3D.Axis = q.Axis; |
|