Two Forms switching for wpf Animation

Source: Internet
Author: User

<Window x: Class = "flip. MainWindow" xmlns =" http://schemas.microsoft.com/winfx/2006/xaml /Presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "Title =" MainWindow "Height =" 420 "Width =" 650 "xmlns: local =" clr-namespace: flip "WindowStyle =" None "ResizeMode =" NoResize "AllowsTransparency =" True "Background =" Transparent "WindowStartupLocation =" CenterScreen "> <Grid. rowDefinitions> <RowDefinition Height = "*"/> <RowDefinition Height = "auto"/> </Grid. rowDefinitions> <Viewport3D Grid. row = "0" Margin = "3"> <Viewport3D. camera> <! -- Position: the camera Position expressed in the world coordinate LookDirection defines the Vector3D NearPlaneDistance of the camera's shooting direction in the world coordinate to specify the distance of the camera to the camera's near-cut plane --> <PerspectiveCamera Position = "0 0 800 "LookDirection =" 0 0-1 "NearPlaneDistance =" 100 "/> </Viewport3D. camera> <Viewport3D. children> <ContainerUIElement3D> <Viewport2DVisual3D> <Viewport2DVisual3D. geometry> <MeshGeometry3D Positions = "-200 150 0-200-150 0 200-150 0 200 150 0" TriangleIndices = "0 1 2 0 2 3 "TextureCoordinates =" 0 0 0 1 1 1 1 0 "/> </Viewport2DVisual3D. geometry> <Viewport2DVisual3D. material> <DiffuseMaterial Viewport2DVisual3D. isVisualHostMaterial = "True"/> </Viewport2DVisual3D. material> <Viewport2DVisual3D. visual> <local: UcSample1 Width = "400" Height = "300"/> </Viewport2DVisual3D. visual> </Viewport2DVisual3D> <Viewport2DVisual3D> <Viewport2DVisual3D. geometry> <MeshGeometry3D Posi Tions = "200 150 0 200-150 0-200-150 0-200 150 0" TriangleIndices = "0 1 2 0 2 3" TextureCoordinates = "0 0 0 1 1 1 0 "/> </Viewport2DVisual3D. geometry> <Viewport2DVisual3D. material> <DiffuseMaterial Viewport2DVisual3D. isVisualHostMaterial = "True"/> </Viewport2DVisual3D. material> <Viewport2DVisual3D. visual> <local: UcSample2 Width = "400" Height = "300"/> </Viewport2DVisual3D. visual> </Viewport2DVisual3D> <! -- 3D transformation conversion direction --> <ContainerUIElement3D. transform> <RotateTransform3D CenterX = "0.5" CenterY = "0.5" CenterZ = "0.5"> <RotateTransform3D. rotation> <AxisAngleRotation3D x: Name = "axr" Angle = "0" Axis = "0 1 0"/> </RotateTransform3D. rotation> </RotateTransform3D> </ContainerUIElement3D. transform> </ContainerUIElement3D> <! -- Background --> <ModelVisual3D> <ModelVisual3D. content> <DirectionalLight Color = "Transparent"/> </ModelVisual3D. content> </ModelVisual3D> </Viewport3D. children> </Viewport3D> <StackPanel Grid. row = "1" Margin = "0, 5, "Orientation =" Horizontal "HorizontalAlignment =" Center "> <Button Padding =" "Content =" Forward "Click =" OnClick "/> <Button Padding =" "Content = "backward" Click = "OnClick" Margin = "12, 0, "/> <Button Padding =" "Content =" close "Click =" OnClick "Margin =, 0, 0 "/> </StackPanel> </Grid> </Window>

  

Private void OnClick (object sender, RoutedEventArgs e)
{
Button btn = e. OriginalSource as Button;
If (btn! = Null)
{
String s = btn. Content. ToString ();
If (s = "close ")
{
This. Close ();
}
DoubleAnimation da = new DoubleAnimation ();
Da. Duration = new Duration (TimeSpan. FromSeconds (1 ));
If (s = "Forward ")
{
Da. To = 0d;
}
Else if (s = "backward ")
{
Da. To = 180d;
}
This. axr. BeginAnimation (AxisAngleRotation3D. AngleProperty, da );
}

Local: UcSample1 and local: UcSample2 are two separate forms.

 

Let's talk about the four attributes commonly used in MeshGeometry3D.

Let's take a look at the MSDN introduction.

First, let's talk about Positions. It's about the set of vertex Positions. What do you mean by reading an image.

This simple description of a three-coordinate system, which contains four coordinate points, that is, the vertex Positions, which have been marked and constitute a set (Positions ).

It indicates a square. Put it here first. Next we will talk about TriangleIndices.

The relationship between TriangleIndices and Positions is often unclear.

For example:

TriangleIndices = "0 1 2 2 3 0"

What it represents. What does each number mean.

First, let's talk about the concept. It literally refers to the set of triangle indexes. Why do we need triangles? In the 3D world, all things can be described as a collection of triangles.

For example, the square we draw can be composed of two triangles.

TriangleIndices = "0 1 2 2 3 0" can be translated as "P0 P1 P2, P2 P3 P0" according to the image display, or 0 corresponds to (-, 0 ), 1 corresponds to (-1,-1, 0), and so on.

Each number corresponds to each vertex in the image. But why.

This is related to the positive and negative sides of the triangle. It can be seen that each of the above three points is in a counter-clockwise order, because WPF uses a counter-clockwise surround to display the front,

Or use the right hand rule: hold the right hand, stick out the thumb, four fingers in the counterclockwise direction, the thumb points to the front.

If your order is reversed, it will be black. Because you didn't describe the back.

The relationship between TriangleIndices and Positions is basically clarified here.

These two are also the main attributes, because the other two attributes, if not written, will automatically determine to give the default value.

Let's talk about Normals and TextureCoordinates.

TextureCoordinates: texture coordinates are used to determine how Material maps to the vertices of the triangle that forms the mesh.

This is easy to understand, such

TextureCoordinates = "0, 0, 1, 1, 0"

The normal coordinates of the material are P0, P3, P2, and P1 in sequence. That is to say, 0, 0, 0 is a normal order and is displayed according to the original image.

However, if you change to TextureCoordinates = "1 0, 0 0, 0 1, 1", you will find that the picture is displayed to the left.

This is also related to the coordinate set you defined.

Finally

Normals: A normal vector is a vector perpendicular to the surface of each triangle in the defined mesh. The normal vector is used to determine whether to highlight a given triangle surface. If a triangle index is specified, the adjacent surface is considered to generate a normal vector.

Related Article

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.