C#在WPF中使用3D立方体上的四元数

时间:2018-06-04 07:28:20

标签: c# wpf quaternions

我正在使用传感器将四元数发送到我的电脑。现在我想要旋转我在应用程序上创建的多维数据集。

<Viewport3D Name="viewport3D1" Margin="568,-85,-104,176" RenderTransformOrigin="0.317,0.482">

        <Viewport3D.Triggers>
            <EventTrigger RoutedEvent="Viewport3D.Loaded">
                <BeginStoryboard>
                    <Storyboard>

                        <QuaternionAnimation Storyboard.TargetName="myQuaternionRotation3D" />

                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Viewport3D.Triggers>
        <Viewport3D.Camera>
            <PerspectiveCamera x:Name="camMain" Position="6 5 4" LookDirection="-6 -5 -4">
            </PerspectiveCamera>
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <DirectionalLight x:Name="dirLightMain" Direction="-1,-1,-1">
                </DirectionalLight>
            </ModelVisual3D.Content>
        </ModelVisual3D>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <GeometryModel3D>
                    <GeometryModel3D.Geometry>
                        <MeshGeometry3D x:Name="meshMain"
                            Positions="0 0 0  1 0 0  0 1 0  1 1 0  0 0 1  1 0 1  0 1 1  1 1 1"
                            TriangleIndices="2 3 1  2 1 0  7 1 3  7 5 1  6 5 7  6 4 5  6 2 0  2 0 4  2 7 3  2 6 7  0 1 5  0 5 4">
                        </MeshGeometry3D>
                    </GeometryModel3D.Geometry>
                    <GeometryModel3D.Material>
                        <DiffuseMaterial x:Name="matDiffuseMain">
                            <DiffuseMaterial.Brush>
                                <SolidColorBrush Color="Red"/>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </GeometryModel3D.Material>
                </GeometryModel3D>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>

我在互联网上找到了一些例子,但它们不起作用。我添加了这样的QuaternionAnimation函数。

                private void cube_Rotation(string[] text) { 
        try
        {
            Double WValue = System.Convert.ToDouble(text[0]);
            Double XValue = System.Convert.ToDouble(text[1]);
            Double YValue = System.Convert.ToDouble(text[2]);
            Double ZValue = System.Convert.ToDouble(text[3]);

            endQuaternion = new Quaternion(XValue, YValue, ZValue, WValue);
        }
        catch
        {
            MessageBox.Show("Set non-null values for the quaternion.");
        }

        myQuaternionRotation3D = new QuaternionRotation3D(endQuaternion);
        myRotateTransform3D.Rotation = myQuaternionRotation3D;

        //update matrix display
        qrotationMatrix3D = myRotateTransform3D.Value;
    }

此外,初始化无法正常工作。有人在WPF中的3D立方体上使用四元数有任何想法或示例吗?如果有人可以帮助我,我会很高兴。

0 个答案:

没有答案