Wpf 如何仅在Z轴上旋转三维对象?

Wpf 如何仅在Z轴上旋转三维对象?,wpf,3d,Wpf,3d,我们使用3DTools()绘制了一条3d线,它允许用户用鼠标旋转它。我有一个问题,如何限制用户只能在Z轴上旋转它?还是仅在X轴、Y轴上 <tool:TrackballDecorator > <tool:Interactive3DDecorator ContainsInk="True"> <Viewport3D> <Viewport3D.Camera>

我们使用3DTools()绘制了一条3d线,它允许用户用鼠标旋转它。我有一个问题,如何限制用户只能在Z轴上旋转它?还是仅在X轴、Y轴上


<tool:TrackballDecorator >
    <tool:Interactive3DDecorator 
         ContainsInk="True">
        <Viewport3D>
            <Viewport3D.Camera>
                <PerspectiveCamera x:Name="camera1" Position="4.89,-11,5" LookDirection="-4.89,11,-5"
                                   FieldOfView="45" UpDirection="-4,9,-1"/>
            </Viewport3D.Camera>
            <ModelVisual3D x:Name="modelVisual3D">
                <ModelVisual3D.Children>
                    <tool:ScreenSpaceLines3D x:Name="axisX" Color="Cyan"
                        Thickness="2.0"
                        Points="0, 0, 0, 5, 0, 0" />
                    <tool:ScreenSpaceLines3D  Color="LightCyan"
                        Thickness="2.0"
                        Points="-5, 0, 0, 0, 0, 0" />
                    <tool:ScreenSpaceLines3D x:Name="axisY" Color="Green"
                        Thickness="2.0"
                        Points="0,0,0, 0,5,0"/>
                    <tool:ScreenSpaceLines3D  Color="LightGreen"
                        Thickness="2.0"
                        Points="0,-5,0, 0,0,0"/>

                    <tool:ScreenSpaceLines3D x:Name="axisZ" Color="Red"
                        Thickness="2.0"
                        Points="0,0,0, 0,0,5"/>
                    <tool:ScreenSpaceLines3D  Color="LightPink"
                        Thickness="2.0"
                        Points="0,0,-5, 0,0,0"/>
                </ModelVisual3D.Children>
            </ModelVisual3D>
        </Viewport3D>
    </tool:Interactive3DDecorator>
</tool:TrackballDecorator>

将“Trackball.cs”中的Trackball.Track()方法替换为以下方法:

private void Track(Point currentPosition)
    {
        Vector3D currentPosition3D = ProjectToTrackball(
            EventSource.ActualWidth, EventSource.ActualHeight, currentPosition);

        Vector3D axisToRotate = new Vector3D(0, 1, 0); // Rotation around Y only

        Vector3D currProjected = Vector3D.CrossProduct(axisToRotate, currentPosition3D);
        Vector3D prevProjected = Vector3D.CrossProduct(axisToRotate, _previousPosition3D);
        double angle = Vector3D.AngleBetween(currProjected, prevProjected);            

        int sign = Math.Sign(Vector3D.DotProduct(
            axisToRotate, 
            Vector3D.CrossProduct(_previousPosition3D, currentPosition3D)));

        if (sign != 0)
        {
            Quaternion delta = new Quaternion(axisToRotate * sign, -angle);

            AxisAngleRotation3D r = _rotation;
            Quaternion q = new Quaternion(_rotation.Axis, _rotation.Angle);

            q *= delta;

            _rotation.Axis = q.Axis;
            _rotation.Angle = q.Angle;
        }

        _previousPosition3D = currentPosition3D;
    }

你确定它会旋转直线吗?我想它只是用TrackballDecorator旋转摄像机…@SMART\n,你说得对,谢谢你的提示,我在读了3DTools的源代码后就知道了,我找到了一种只在Z轴上旋转的方法,它可以工作,但不好。鼠标移动了很长一段距离,但摄像机只是旋转了一点。对不起,我不知道如何描述它。