首页 新闻 搜索 专区 学院

请教如何暂停WFP的3D模型动画?代码可直接运行,在线急等

0
悬赏园豆:10 [已关闭问题]
我用代码写了一个生成3D模型的一个矩形,并让这个模型可以自动旋转,代码如下

C# code
private void BuildSolid() { // Define 3D mesh object MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions.Add(new Point3D(-1, -1, 0.2)); //mesh.Normals.Add(new Vector3D(0, 0, 1)); mesh.Positions.Add(new Point3D(1, -1, 0.2)); //mesh.Normals.Add(new Vector3D(0, 0, 1)); mesh.Positions.Add(new Point3D(1, 1, 0.2)); //mesh.Normals.Add(new Vector3D(0, 0, 1)); mesh.Positions.Add(new Point3D(-1, 1, 0.2)); //mesh.Normals.Add(new Vector3D(0, 0, 1)); mesh.Positions.Add(new Point3D(-1, -1, -0.2)); //mesh.Normals.Add(new Vector3D(0, 0, -1)); mesh.Positions.Add(new Point3D(1, -1, -0.2)); //mesh.Normals.Add(new Vector3D(0, 0, -1)); mesh.Positions.Add(new Point3D(1, 1, -0.2)); //mesh.Normals.Add(new Vector3D(0, 0, -1)); mesh.Positions.Add(new Point3D(-1, 1, -0.2)); //mesh.Normals.Add(new Vector3D(0, 0, -1)); // Front face mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(0); // Back face mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(7); mesh.TriangleIndices.Add(6); // Right face mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(2); // Top face mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(7); // Bottom face mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(5); // Right face mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(7); mesh.TriangleIndices.Add(4); // Geometry creation mGeometry = new GeometryModel3D(mesh, new DiffuseMaterial(Brushes.YellowGreen)); var tf = new Transform3DGroup(); mGeometry.Transform = tf; a = new AxisAngleRotation3D(new Vector3D(0, 10, 0), 0); tf.Children.Add(new RotateTransform3D(a)); var db=new DoubleAnimation(0,60,new Duration(TimeSpan.FromSeconds(10))); db.RepeatBehavior=RepeatBehavior.Forever; a.BeginAnimation(AxisAngleRotation3D.AngleProperty, db, HandoffBehavior.Compose); group.Children.Add(mGeometry); }



下面这部分代码让模型旋转

C# code
mGeometry = new GeometryModel3D(mesh, new DiffuseMaterial(Brushes.YellowGreen)); var tf = new Transform3DGroup(); mGeometry.Transform = tf; a = new AxisAngleRotation3D(new Vector3D(0, 10, 0), 0); tf.Children.Add(new RotateTransform3D(a)); var db=new DoubleAnimation(0,60,new Duration(TimeSpan.FromSeconds(10))); db.RepeatBehavior=RepeatBehavior.Forever; a.BeginAnimation(AxisAngleRotation3D.AngleProperty, db, HandoffBehavior.Compose); group.Children.Add(mGeometry);



但是这时就遇到一个问题,如果我想让模型暂时停止转动,应该怎么做?也就是点一个按钮,可以暂停模型转动
江城子的主页 江城子 | 初学一级 | 园豆:190
提问于:2009-09-07 08:43
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册