The WPF section supports three-dimensional models, and why is it partially supported? After all, the focus of WPF is on application development, although some games are developed with WPF, but, in the old weeks, if you really want to develop a game, it's best to use a special framework that WPF should use to develop application functionality. However, animations, three-dimensional modeling these support can be used as a helper, especially on the UI, as appropriate, can be enhanced. Of course, do not to install force, make no fish and fish, that is the primary and secondary, and now there are many software is the primary and secondary.
In WPF, to render a three-dimensional model, you need to use Viewport3D, which is the total container for three-dimensional objects, all three-dimensional objects should be placed in this container. This article does not introduce three-dimensional object tree structure, but focus on the viewport3d of an important accessory-camera.
In fact, this "camera", like our real-world cameras, is an entrance to our three-dimensional model, just as we look at the subject from the viewfinder in the real camera, and because the camera has a limited breadth of view (even if the wide-angle lens is limited), the real object can be infinitely extended, but , what you see in the viewfinder can only be local. The truth is the same, in the three-dimensional model of WPF, Camara just sets the part of the three-dimensional object that we can see, and the dimension object itself may be infinitely extensible.
The Viewport3D object has a camera property that is used to set up a suitable camera instance. Cameras can be divided into two main categories:
The first class, Matrixcamera, it uses a matrix to describe the camera parameters, this estimate is not used much, because it is very complicated, anyway, old weeks do not know how to use.
The second type, Projectioncamera, is a camera with a projection perspective, which derives two cameras, note that not canon and Nikon, are Perspectivecamera and Orthographiccamera. Perspectivecamera camera better solution, because it is a perspective effect, which is also in line with the visual characteristics of our primate animals-close to the object will look larger, far away from the object would be smaller, of course, if the object size is close, otherwise, the sun is much bigger than the moon, so, Even if the sun is farther away from us, it looks bigger than the moon. And Orthographiccamera, it does not accord with the visual characteristics of our primates, because after using this camera, the object becomes orthogonal, that is, there is no perspective, no distance, whether far or near, is the same big. If people can do like the orthogonal lens so good, regardless of the same. Sometimes, people are not as good as code-friendly, because some people will calculate you, but the code will not, although sometimes, the code will play, let you love and hate, but it treats you is sincere, and people, perhaps only a small number of people can do, society too lack of integrity.
Well, the introduction of a few types of cameras, I believe that everyone will want to see the effect. OK, Old week also want to, or, let's try.
For the sake of simplicity, the old week only built a cube, and this cube is the clothes are not complete, only a skirt, just declare the left, front and right three faces.
<Viewport3D>...<!--model, three faces - <ModelVisual3D> <ModelVisual3D> <modelvisual3d.content> <GeometryModel3D> <Geometrymodel3d.geometry> <MeshGeometry3Dpositions= " -2,4,0-2,0,0-2,0,4-2,4,4"triangleindices= "0,1,2,0,2,3"/> </Geometrymodel3d.geometry> <geometrymodel3d.material> <diffusematerialBrush= "Green"/> </geometrymodel3d.material> </GeometryModel3D> </modelvisual3d.content> </ModelVisual3D> <ModelVisual3D> <modelvisual3d.content> <GeometryModel3D> <Geometrymodel3d.geometry> <MeshGeometry3Dpositions= " -2,4,4-2,0,4 2,0,4 2,4,4"triangleindices= "0,1,2,0,2,3"/> </Geometrymodel3d.geometry> <geometrymodel3d.material> <diffusematerialBrush= "Blue"/> </geometrymodel3d.material> </GeometryModel3D> </modelvisual3d.content> </ModelVisual3D> <ModelVisual3D> <modelvisual3d.content> <GeometryModel3D> <Geometrymodel3d.geometry> <MeshGeometry3Dpositions= "2,4,4 2,0,4 2,0,0 2,4,0"triangleindices= "0,1,2,0,2,3"/> </Geometrymodel3d.geometry> <geometrymodel3d.material> <diffusematerialBrush= "Red"/> </geometrymodel3d.material> </GeometryModel3D> </modelvisual3d.content> </ModelVisual3D> </ModelVisual3D> <!--lights to illuminate the model, or it's All black. - <ModelVisual3D> <modelvisual3d.content> <AmbientlightColor= "Purple" /> </modelvisual3d.content> </ModelVisual3D> </Viewport3D>
Ambientlight refers to the ambient light, which can illuminate the entire model of light, if used pointlight, is a light, similar to a small light bulb, small candles, can only illuminate a little space. The color attribute specifies that the light is purple and violet can trap pests, so it uses violet.
OK, here's the point, we'll look at the orthogonal camera first.
<Viewport3D> <Viewport3d.camera> <OrthographiccameraPosition= "16,2,18"lookdirection= " -1,0,-1"Width= "Ten" /> </Viewport3d.camera>...</Viewport3D>
Position is the location of the specified camera, note the coordinates of the z-axis, if the z-axis value is greater than the z-axis value of the model, then the lens is in front of the object and vice versa. So you can set lookdirection to adjust the orientation of the camera, position is the position of the camera, just like you stand at some point, and Lookdirection is the direction of the camera, as you can take the camera to shoot you in front of the sister, you can also shoot your left uncle, Or shoot your uncle at the angle of 30 degrees. Lookdirection specify where you look.
If the camera is in front of the object, the z-axis value of the lookdirection is less than 0, because the negative direction of the z-axis is pointing to the inside of the screen, the object can only be seen in the negative direction, and if the camera is on the back of the object, the z-axis value will be greater than 0.
The orthogonal camera sees the cube as shown.
This is the front and side of the cube, but, you see, Two faces as big, supposedly, the front should be closer to us, but, the orthogonal camera is not to consider this, in its eyes, the world is flat.
Let's replace the camera with a perspective effect.
< viewport3d > < viewport3d.camera
>
<
perspectivecamera position = "10,5,10" lookdirection = " -2.5,-1,-2" /> </ viewport3d.camera > </ viewport3d >
The camera is located in the left front of the object and is viewed toward the right lower part.
At this point, as shown, you'll see a perspective effect.
Perhaps, this is more in line with our observation in the real world.
Well, it is time to eat, talk to here today, there is free, another day we soak up a pot of longjing tea, continue to talk.
"Camera" in the "WPF" three-dimensional model