1

wpfでx軸とz軸を一定に保ちながら、3D立方体をy軸で連続的に回転させる方法は??

4

1 に答える 1

0

このコードを 内で使用できますUserControl:

 <Viewport3D x:Name="CubeLogo"
            Height="400" Width="400" OpacityMask="#FF000000">
    <Viewport3D.Camera>
        <PerspectiveCamera x:Name="Camara"
                           FarPlaneDistance="20"
                           NearPlaneDistance="1"
                           LookDirection="0,-0.65,-1"
                           UpDirection="0.220607433377356,0.678217480739237,-0.440841362480504"
                           Position="0,1.6,2.6" FieldOfView="40" />
    </Viewport3D.Camera>

    <Viewport3D.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation From="0" To="360" Duration="0:0:6"
                            Storyboard.TargetName="LogoRotation3D"
                            Storyboard.TargetProperty="Angle" RepeatBehavior="Forever" x:Name="Animacion"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Viewport3D.Triggers>

    <ModelVisual3D>
        <ModelVisual3D.Content>
            <Model3DGroup>
                <AmbientLight Color="White"/>

                <GeometryModel3D ScrollViewer.IsDeferredScrollingEnabled="False">
                    <GeometryModel3D.Geometry>
                                <MeshGeometry3D TriangleIndices="0,1,2 3,4,5 6,7,8 9,10,11 12,13,14 15,16,17 18,19,20 21,22,23 24,25,26 27,28,29 30,31,32 33,34,35 "
                                        Normals="0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,-1,0 0,-1,0 0,-1,0 0,-1,0 0,-1,0 0,-1,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 0,1,0 0,1,0 0,1,0 0,1,0 0,1,0 0,1,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0"
                                        TextureCoordinates="1,1 1,0 0,0 0,0 0,1 1,1 0,1 1,1 1,0 1,0 0,0 0,1 0,1 1,1 1,0 1,0 0,0 0,1 1,1 1,0 0,0 0,0 0,1 1,1 1,0 0,0 0,1 0,1 1,1 1,0 0,0 0,1 1,1 1,1 1,0 0,0"
                                        Positions="-0.5,-0.5,-0.5 -0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,-0.5,-0.5 -0.5,-0.5,-0.5 -0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,-0.5,0.5 0.5,-0.5,0.5 -0.5,-0.5,0.5 -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,0.5 0.5,0.5,0.5 0.5,-0.5,0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5 -0.5,0.5,-0.5 -0.5,0.5,0.5 -0.5,0.5,0.5 0.5,0.5,0.5 0.5,0.5,-0.5 -0.5,0.5,-0.5 -0.5,-0.5,-0.5 -0.5,-0.5,0.5 -0.5,-0.5,0.5 -0.5,0.5,0.5 -0.5,0.5,-0.5"/>
                    </GeometryModel3D.Geometry>

                    <GeometryModel3D.Transform>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D x:Name="LogoRotation3D"
                                                     Angle="35"
                                                     Axis="1 1 1"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </GeometryModel3D.Transform>

                    <!-- Background color of the cube -->
                    <GeometryModel3D.BackMaterial>
                        <DiffuseMaterial Brush="WhiteSmoke"/>
                    </GeometryModel3D.BackMaterial>

                    <!-- Content of the cube -->
                    <GeometryModel3D.Material>
                        <DiffuseMaterial>
                            <DiffuseMaterial.Brush>
                                <VisualBrush>
                                    <VisualBrush.Visual>
                                        <Image x:Name="Logo" />
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </GeometryModel3D.Material>
                </GeometryModel3D>
            </Model3DGroup>

        </ModelVisual3D.Content>
    </ModelVisual3D>

</Viewport3D>

そして、別の中で次のように呼び出しますXAML:

xmlns:local="clr-namespace:RotatoryCube"

<local:RotatoryCube x:Name="RotatoryCubeInterface"></local:RotatoryCube>

DoubleAnimation回転がどれくらい続くか、FromおよびTo角度を示すものはありません。どちらを回転させ、どの角度にするAxisRotation3Dかについても注意してください。Axis

于 2013-03-01T08:21:20.527 に答える