M_projMatrix.Scale( new Vector3D(sX, sX, sX)) M_projMatrix.Translate( new Vector3D(-xC, -圜, -zC)) Public void CalculateProjectionMatrix( double xMin, double xMax,ĭouble yMin, double yMax, double zMin, double zMax, double k) We will add another matrix to project the 3D object into the camera view range. We can change the camera position to keep the 3D object in camera view. If the 3D object is out of camera range, the 3D object will not be shown in Viewport3D. So the triangle is in the camera view range. The camera we used has a default width of 2. The triangle we used in the previous two sections has the data range -0.5 ~ 0.5. ( new MatrixTransform3D(transformMatrix.m_ m_viewMatrix)) Īfter we modify the transform matrix, we need to set a new view matrix to the 3D model’s transform property. Transform3DGroup group1 = triangleModel.Transform as Transform3DGroup M_transformMatrix.OnMouseMove(pt, mainViewport) If (args.LeftButton = MouseButtonState.Pressed) Point pt = args.GetPosition(mainViewport) Public void OnViewportMouseMove( object sender, Public WPFChart.TransformMatrix m_transformMatrix = new WPFChart.TransformMatrix() To use the TransformMatrix class, we can add a TransformMatrix variable to the window class, and call the mouse event handler of TransformMatrix object at the corresponding mouse events of the window class.Ĭopy Code public partial class Window1 : Window You can change this rotation sensitivity. We scale the rotate so the model moves 180 degrees when we move the mouse from one side of the window to another side. The view matrix will rotate according to the offset of the current mouse position and previous mouse position m_movePoint. The 3D rotation is implemented in the mouse move event. M_viewMatrix.Rotate( new Quaternion( new Vector3D( 0, 1, 0), aY)) M_viewMatrix.Rotate( new Quaternion( new Vector3D( 1, 0, 0), aX)) If (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))ĭouble aY = 180 * (pt.X - m_movePoint.X) / width ĭouble aX = 180 * (pt.Y - m_movePoint.Y) / height Public void OnMouseMove(Point pt, 3D viewPort) We will build a special transform class to use this matrix. The transform property of a 3D model can be described as 3D. ![]() For this project, we will modify the transform property of the 3D model. We can either change the camera location or change the transform property of the 3D model to rotate the 3D object. The mouse down, move and up events handlers of the canvas will be added to the window class. In order to catch the mouse event, we cover the Viewport3D with a transparent Canvas. Therefore, we need to keep a track of the transform when we rotate the 3D model. Rotating the 3D model in WPF is easy, but we want to implement our own selection function later. In this section, we will use the mouse to rotate the 3D model. ![]() In the next section, we will show how to rotate this 3D model. If we run the program, we will see a blue triangle. Model3D class in this project helps to generate a ModelVisual3D object. The vertices location is represented by a Point3D structure.Ĭopy Code (visualModel)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |