要旋轉的對象應該是ModelVisual3D,添加到螺旋視口中。
獲得從ModelVisual3D.Transform3D Matrix3D對象,這裏是圍繞任意軸旋轉的函數:
public static Matrix3D Rotate(this Matrix3D m, Vector3D vr, double angleDeg, bool multiply = true)
{
var rm = new Matrix3D();
//vr /= vr.Length;
vr.Normalize();
var t = angleDeg.ToRad();
var c = Math.Cos(t);
var s = Math.Sin(t);
var c1 = 1 - c;
var x = vr.X; var y = vr.Y; var z = vr.Z;
var x2 = x * x; var y2 = y * y; var z2 = z * z;
var xy = x * y;
var xz = x * z;
var yz = y * z;
//col 1
rm.M11 = c1 * x2 + c;
rm.M21 = c1 * xy - s * z;
rm.M31 = c1 * xz + s * y;
//col 2
rm.M12 = c1 * xy + s * z;
rm.M22 = c1 * y2 + c;
rm.M32 = c1 * yz - s * x;
//col 3
rm.M13 = c1 * xz - s * y;
rm.M23 = c1 * yz + s * x;
rm.M33 = c1 * z2 + c;
if (multiply) return rm * m;
return rm;
}
然後設置的Transform3D =新MatrixTransform3D(的Matrix3D)。
希望它可以幫助別人......