3D scenarios using WPF [2]

Source: Internet
Author: User

In the previous article, we learned how to construct a simple 3D scenario. In this course, I will work with you to learn how to use code to complete the observation of the established 3D scenario.

First, let's take a look at the demo interface:

 

 

You can see the buttons in eight directions, which provide the ability to observe the angle change and rotate the 3D scene.

Observe the location changes:

Implementation principle: Changing the camera's absolute position and other attributes in the scenario

Implementation Code:

Define a camera

<Viewport3d name = "myviewport" margin = "0, 0, 0"
<Viewport3d. Camera>
<Perspectivecamera X: Name = "myviewportcamera" farplanedistance = "5000" nearplanedistance = "0.25" fieldofview = "90" position = "1800,0, 0" lookdirection =, 0 "updirection =" 0, 1 "> </perspectivecamera>
</Viewport3d. Camera>

Define a camera (viewing angle) change event:

Void rightbutton_click (Object sender, routedeventargs E)
...{
This. myviewportcamera. position = new system. windows. media. media3d. point3d (this. myviewportcamera. position. x, this. myviewportcamera. position. y, this. myviewportcamera. position. Z + 100 );
}

Void leftbutton_click (Object sender, routedeventargs E)
...{
This. myviewportcamera. position = new system. windows. media. media3d. point3d (this. myviewportcamera. position. x, this. myviewportcamera. position. y, this. myviewportcamera. position. z-100 );
}

Void backbutton_click (Object sender, routedeventargs E)
...{
This. myviewportcamera. position = new system. windows. media. media3d. point3d (this. myviewportcamera. position. x plus 100, this. myviewportcamera. position. y, this. myviewportcamera. position. z );
}

Void frontbutton_click (Object sender, routedeventargs E)
...{
This. myviewportcamera. position = new system. windows. media. media3d. point3d (this. myviewportcamera. position. *-100, this. myviewportcamera. position. y, this. myviewportcamera. position. z );
}

 

3D scene angle changes:

Implementation principle: change the angle of the axis defined in a 3D scenario

Implementation Code:

Define the operation axis:

<Modelvisual3d. Transform>
<Transform3dgroup>
<Matrixtransform3d/>
<Rotatetransform3d>
<Rotatetransform3d. Rotation>
<Axisanglerotation3d angle = "0" axis = "0, 10, 0" X: Name = "myanglerotationchair"/>
</Rotatetransform3d. Rotation>
</Rotatetransform3d>
<Rotatetransform3d>
<Rotatetransform3d. Rotation>
<Axisanglerotation3d angle = "0" axis = "0, 0, 10" X: Name = "myanglerotationchair_1"/>
</Rotatetransform3d. Rotation>
</Rotatetransform3d>
</Transform3dgroup>
</Modelvisual3d. Transform>
</Modelvisual3d>

Define the axis rotation code:

Void down_click (Object sender, routedeventargs E)
...{
This. myanglerotationchair_1.angle-= 10;
}

Void up_click (Object sender, routedeventargs E)
...{
This. myanglerotationchair_1.angle + = 10;
}

Void left_click (Object sender, routedeventargs E)
...{
This. myanglerotationchair. Angle-= 10;
}

Void right_click (Object sender, routedeventargs E)
...{
This. myanglerotationchair. Angle + = 10;
}

 

Okay ~ If you want to know more about 3D scenarios, please pay attention to the third section.

If you want to download the source code or listen to the voice tutorial, visit: Microsoft webcast

 

Thank you again for your attention. Thank you!

 

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.