Beispiel #1
0
        private void Draw_8_3D(MechanismInfo mi)
        {
            Material kolesoMaterial = new Material();

            kolesoMaterial.Diffuse           = Color.Purple;
            kolesoMaterial.Specular          = Color.Yellow;
            kolesoMaterial.SpecularSharpness = 1;


            if (mi.Number != -1 && mi.Window != null)
            {
                int koef = mi.zoom;

                Mechanism_8 mechanism = (Mechanism_8)mi.mechanism;
                mechanism.ReturnState(mi.Timems * 0.01);

                //for static ball

                //for rope moving block
                float x = (float)(mechanism.R1 + mechanism.r2);
                float y = (float)(((mechanism.l - mechanism.R1) / 2 - Math.PI * mechanism.r2 / 2));
                //for ropes
                float xx = (float)(x + 2 * mechanism.r2);
                //for block
                int    lv = 100;
                double yb = mechanism.R1 + lv - mi.Timems * mechanism.v_block * 0.01;

                if ((yb < (mechanism.R1 / 2) || (y + mechanism.State.deltaO2) < 0.01) && mi.Timems != 0 && mi.Timer.Enabled)
                {
                    mi.Timer.Stop(); return;
                }



                DirectMatrix displace = DirectMatrix.Translation(-(float)(mechanism.R1 * 2) / koef, -(float)(mechanism.R1 * 2) / koef, 0);



                mi.d3d.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Wheat, 1.0f, 0);
                mi.d3d.BeginScene();

                SetupProjections(mi);

                mi.d3d.RenderState.FillMode = (mi.XRay)? Microsoft.DirectX.Direct3D.FillMode.Solid : Microsoft.DirectX.Direct3D.FillMode.WireFrame;
                mi.d3d.RenderState.Lighting = true;

                Mechanism_8 m8 = mi.mechanism as Mechanism_8;

                //Большое неподвижное колесо
                Mesh static_wheel = Mesh.Cylinder(mi.d3d, (float)m8.R1 / koef, (float)m8.R1 / koef, 0.1f, 50, 10);

                mi.d3d.Material        = kolesoMaterial;
                mi.d3d.Transform.World = DirectMatrix.RotationZ((float)mechanism.State.rot1) * displace *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                         DirectMatrix.Translation(0, 0, 6f);
                static_wheel.DrawSubset(0);

                //Вращающееся колесо
                Mesh nonstatic_wheel = Mesh.Cylinder(mi.d3d, (float)m8.r2 / koef, (float)m8.r2 / koef, 0.1f, 50, 10);

                mi.d3d.Transform.World = DirectMatrix.RotationZ(-(float)mechanism.State.rot2) * displace *

                                         DirectMatrix.Translation(x / koef, (float)(y + mechanism.State.deltaO2) / koef, 0) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180))
                                         * DirectMatrix.Translation(0, 0, 6f);
                nonstatic_wheel.DrawSubset(0);

                //Маленькое неподвижное колесо
                Mesh static_wheel1 = Mesh.Cylinder(mi.d3d, (float)m8.r1 / (koef), (float)m8.r1 / koef, 0.1f, 50, 10);
                kolesoMaterial.Diffuse = Color.Tomato;
                mi.d3d.Material        = kolesoMaterial;
                mi.d3d.Transform.World = DirectMatrix.RotationZ((float)mechanism.State.rot1) * displace * DirectMatrix.Translation(0, 0, 0.1f) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180))
                                         * DirectMatrix.Translation(0, 0, 6f);

                static_wheel1.DrawSubset(0);



                float len = (float)(y + mechanism.State.deltaO2);
                if (len < 0)
                {
                    len = -len;
                }

                kolesoMaterial.Diffuse = Color.DimGray;
                mi.d3d.Material        = kolesoMaterial;
                Mesh rope_left = Mesh.Cylinder(mi.d3d, 0.01f, 0.01f,
                                               len / koef, 50, 10
                                               );
                mi.d3d.Transform.World =
                    DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                    DirectMatrix.Translation((float)(mechanism.R1) / koef, len / (2 * koef), 0) *
                    DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                    DirectMatrix.Translation(0, 0, 6f);
                rope_left.DrawSubset(0);

                Mesh rope_right = Mesh.Cylinder(mi.d3d, 0.01f, 0.01f,
                                                len / koef, 50, 10
                                                );
                mi.d3d.Transform.World =
                    DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                    DirectMatrix.Translation((float)(mechanism.R1 + 2 * mechanism.r2) / koef, len / (2 * koef), 0) *
                    DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                    DirectMatrix.Translation(0, 0, 6f);
                rope_right.DrawSubset(0);

                Mesh rope_block = Mesh.Cylinder(mi.d3d, 0.01f, 0.01f,
                                                (float)yb / koef, 50, 10
                                                );
                mi.d3d.Transform.World =
                    DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                    DirectMatrix.Translation((float)(-mechanism.r1) / koef, (float)yb / (2 * koef), 0.08f) *
                    DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                    DirectMatrix.Translation(0, 0, 6f);
                rope_block.DrawSubset(0);


                //грузик
                kolesoMaterial.Diffuse = Color.ForestGreen;
                mi.d3d.Material        = kolesoMaterial;
                Mesh block = Mesh.Box(mi.d3d, 0.1f, 0.05f, 0.2f);

                mi.d3d.Transform.World =
                    DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                    DirectMatrix.Translation((float)(-mechanism.r1) / koef, (float)(yb + 0.05f) / koef, 0.08f) *
                    DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                    DirectMatrix.Translation(0, 0, 6f);
                block.DrawSubset(0);

                kolesoMaterial.Diffuse = Color.PapayaWhip;
                mi.d3d.Material        = kolesoMaterial;
                Mesh ball1 = Mesh.Sphere(mi.d3d, (float)mechanism.r1 / (3 * koef), 50, 20);
                mi.d3d.Transform.World = displace *
                                         DirectMatrix.Translation(0, 0, -0.05f) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                         DirectMatrix.Translation(0, 0, 6f);
                ball1.DrawSubset(0);

                Mesh ball2 = Mesh.Sphere(mi.d3d, (float)mechanism.r1 / (3 * koef), 50, 20);
                mi.d3d.Transform.World = displace *
                                         DirectMatrix.Translation(0, 0, 0.15f) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                         DirectMatrix.Translation(0, 0, 6f);
                ball2.DrawSubset(0);

                mi.d3d.RenderState.CullMode = Cull.None;
                kolesoMaterial.Diffuse      = Color.Purple;
                mi.d3d.Material             = kolesoMaterial;

                Mesh platform = Mesh.Polygon(mi.d3d, (float)mechanism.r2 / koef, 6);
                mi.d3d.Transform.World = DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                                         DirectMatrix.Translation((float)(mechanism.R1 + 2 * mechanism.r2) / koef, 0, 0) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                         DirectMatrix.Translation(0, 0, 6f);
                platform.DrawSubset(0);



                if (mi.choise != Dots.None)
                {
                    DrawTrajectory(mi.mechanism.ID, mi.Timems == 0);
                }

                mi.d3d.EndScene();
                mi.d3d.Present();


                if (mi.Timer.Enabled)
                {
                    mi.Timems += mi.Timer.Interval;
                }
                static_wheel.Dispose();
                static_wheel1.Dispose();
                nonstatic_wheel.Dispose();
                rope_left.Dispose();
                rope_right.Dispose();
                rope_block.Dispose();
                block.Dispose();
                ball1.Dispose();
                ball2.Dispose();
                platform.Dispose();
            }
        }
Beispiel #2
0
        private void DrawTrajectory(int ID, bool f)
        {
            MechanismInfo mi = FindMechanismInfo(ID);

            if (mi.Number == 8)
            {
                Dots        choise    = mi.choise;
                Mechanism_8 mechanism = (Mechanism_8)mi.mechanism;

                Point _O2 = new Point((int)(mechanism.R1 + mechanism.r2), (int)(((mechanism.l - mechanism.R1) / 2 - Math.PI * mechanism.r2 / 2) + mechanism.State.deltaO2));
                Point _A  = new Point((int)(_O2.X + mechanism.r2 * 3 * Math.Cos(mechanism.State.rot2) / 4),
                                      (int)(_O2.Y - mechanism.r2 * 3 * Math.Sin(mechanism.State.rot2) / 4));

                Point _B = new Point((int)(_O2.X + mechanism.r2 * Math.Cos(mechanism.State.rot2 + 3 * Math.PI / 4)),
                                     (int)(_O2.Y - mechanism.r2 * Math.Sin(mechanism.State.rot2 + 3 * Math.PI / 4)));

                CustomVertex.PositionColored A = new CustomVertex.PositionColored(new Vector3((float)_A.X, (float)_A.Y, 0), Color.Blue.ToArgb());
                A.Color = Color.Blue.ToArgb();

                CustomVertex.PositionColored B = new CustomVertex.PositionColored(new Vector3((float)_B.X, (float)_B.Y, 0), Color.Silver.ToArgb());
                B.Color = Color.Red.ToArgb();

                if (trajectories_vertex.Count < 2)
                {
                    trajectories_vertex.Add(new List <CustomVertex.PositionColored>());
                    trajectories_vertex.Add(new List <CustomVertex.PositionColored>());

                    trajectories_vertex[0].Add(A);
                    trajectories_vertex[1].Add(B);
                }
                if (f)
                {
                    trajectories_vertex[0].Clear();
                    trajectories_vertex[1].Clear();
                }
                trajectories_vertex[0].Add(A);
                trajectories_vertex[1].Add(B);

                //РИСОВАНИЕ КУРВ 3D


                List <CustomVertex.PositionColored> real_trajectoriesA = new List <CustomVertex.PositionColored>();
                List <CustomVertex.PositionColored> real_trajectoriesB = new List <CustomVertex.PositionColored>();

                for (int i = 0; i < trajectories_vertex[0].Count; i++)
                {
                    real_trajectoriesA.Add(new CustomVertex.PositionColored(new Vector3(trajectories_vertex[0][i].X / mi.zoom, trajectories_vertex[0][i].Y / mi.zoom, 0), trajectories_vertex[0][i].Color));
                    real_trajectoriesB.Add(new CustomVertex.PositionColored(new Vector3(trajectories_vertex[1][i].X / mi.zoom, trajectories_vertex[1][i].Y / mi.zoom, 0), trajectories_vertex[1][i].Color));
                }


                mi.d3d.VertexFormat = CustomVertex.PositionColored.Format;
                DirectMatrix displace = DirectMatrix.Translation(-(float)(mechanism.R1 * 2) / mi.zoom, -(float)(mechanism.R1 * 2) / mi.zoom, 0);

                Material kolesoMaterial = new Material();
                kolesoMaterial.Diffuse = Color.Blue;

                mi.d3d.RenderState.Lighting = true;

                if ((choise == Dots.A) || (choise == Dots.Both))
                {
                    mi.d3d.Material = kolesoMaterial;

                    Mesh ball2 = Mesh.Sphere(mi.d3d, (float)mechanism.r2 / (4 * mi.zoom), 50, 20);
                    mi.d3d.Transform.World = displace *
                                             DirectMatrix.Translation((float)(_A.X) / mi.zoom, (float)(_A.Y) / mi.zoom, 0) *
                                             DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                             DirectMatrix.Translation(0, 0, 6f);
                    ball2.DrawSubset(0);
                    ball2.Dispose();


                    mi.d3d.Transform.World = displace * DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) * DirectMatrix.Translation(0, 0, 6f);
                    mi.d3d.DrawUserPrimitives(PrimitiveType.LineStrip, real_trajectoriesA.Count - 1, real_trajectoriesA.ToArray());
                }
                if ((choise == Dots.B) || (choise == Dots.Both))
                {
                    kolesoMaterial.Diffuse = Color.Red;
                    mi.d3d.Material        = kolesoMaterial;

                    Mesh ball2 = Mesh.Sphere(mi.d3d, (float)mechanism.r2 / (4 * mi.zoom), 50, 20);
                    mi.d3d.Transform.World = displace *
                                             DirectMatrix.Translation((float)(_B.X) / mi.zoom, (float)(_B.Y) / mi.zoom, 0) *
                                             DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                             DirectMatrix.Translation(0, 0, 6f);
                    ball2.DrawSubset(0);
                    ball2.Dispose();

                    mi.d3d.Transform.World = displace * DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) * DirectMatrix.Translation(0, 0, 6f);
                    mi.d3d.DrawUserPrimitives(PrimitiveType.LineStrip, real_trajectoriesB.Count - 1, real_trajectoriesB.ToArray());
                }
            }
        }