WPF animations that enable 3D flipping

Source: Internet
Author: User

1. Front-end Code implementation

1.1 Principle See Code injection analysis

<GridMouseDown= "Grid_mousedown">    <Viewport3D>        <Viewport3d.camera>            <!--The Position property specifies the position of the camera in 3D space, and the Lookdirection property is the camera orientation -            <PerspectivecameraPosition= "0 0"lookdirection= "0 0-1" />        </Viewport3d.camera>        <Viewport3d.children>            <Containeruielement3d>                <Viewport2dvisual3d>                    <Viewport2dvisual3d.geometry>                        <!--The Positions property represents a collection of points for the drawing object, and the Triangleindices property represents the front and the sides of the object (WPF represents the frontal side by anti-clockwise), and the Texturecoordinates property represents a 2D texture mapping to a 3D object -                        <!--generally deduced from 3D modeling tools -                        <MeshGeometry3Dpositions= " -200 0-200-200 0 200-200 0 0"triangleindices= "0 1 2 0 2 3"texturecoordinates= "0 0 0 1 1 1 1 0"/>                    </Viewport2dvisual3d.geometry>                    <viewport2dvisual3d.material>                        <diffusematerialviewport2dvisual3d.isvisualhostmaterial= "True"/>                    </viewport2dvisual3d.material>                    <viewport2dvisual3d.visual>                        <!--placing a front-facing custom user control -                        <page:win1Width= "The "Height= "The "/>                    </viewport2dvisual3d.visual>                </Viewport2dvisual3d>                <Viewport2dvisual3d>                    <Viewport2dvisual3d.geometry>                        <MeshGeometry3Dpositions= "0 200-200 0-200-200 0-200 0"triangleindices= "0 1 2 0 2 3"texturecoordinates= "0 0 0 1 1 1 1 0"/>                    </Viewport2dvisual3d.geometry>                    <viewport2dvisual3d.material>                        <diffusematerialviewport2dvisual3d.isvisualhostmaterial= "True"/>                    </viewport2dvisual3d.material>                    <viewport2dvisual3d.visual>                        <!--To place the opposite custom user control -                        <page:win2Width= "The "Height= "The "/>                    </viewport2dvisual3d.visual>                </Viewport2dvisual3d>                <Containeruielement3d.transform>                    <RotateTransform3D>                        <rotatetransform3d.rotation>                            <!--set the axis of rotation to align the y axis of the coordinate system -                            <axisanglerotation3dx:name= "AAR"Angle= "0"Axis= "0 1 0"/>                        </rotatetransform3d.rotation>                    </RotateTransform3D>                </Containeruielement3d.transform>            </Containeruielement3d>            <ModelVisual3D>                <modelvisual3d.content>                    <!--Sets the parallel light fill scene propagating in the specified direction -                    <DirectionalLightColor= "Transparent"/>                </modelvisual3d.content>            </ModelVisual3D>        </Viewport3d.children>    </Viewport3D></Grid>
2, back-end code implementation

2.1 Flip animation with the mouse click the opposite side of the 180-degree display object, the mouse double-click the animation 0 degrees display object front.

Private voidGrid_mousedown (Objectsender, MouseButtonEventArgs e) {DoubleAnimation da=NewDoubleAnimation (); Da. Duration=NewDuration (Timespan.fromseconds (1)); if(E.clickcount = =2) da. to=0d; Elseda. to=180d; Axisanglerotation3d AAR= Application.Current.MainWindow.FindName ("AAR") asaxisanglerotation3d; Aar.  BeginAnimation (Axisanglerotation3d.angleproperty, DA); }
3. Operation effect

3.1 as follows

Welcome reprint, but please specify the source: http://www.cnblogs.com/julyweb/, thank you!

WPF animations that enable 3D flipping

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.