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(); } }
private void Draw_8(MechanismInfo mi) { if (mi.Number != -1 && mi.G != null) { Mechanism_8 mechanism = (Mechanism_8)mi.mechanism; mechanism.ReturnState(mi.Timems * 0.05); Bitmap bp = new Bitmap(mi.Size.X, mi.Size.Y, mi.G); Graphics g = Graphics.FromImage(bp); g.SmoothingMode = SmoothingMode.AntiAlias; HatchBrush Br = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Black, Color.White); Pen p = new Pen(Color.Black); SolidBrush SBr = new SolidBrush(Color.White); Rectangle Rect = new Rectangle(); //for static ball float y0 = (float)(mechanism.Center.Y - mechanism.R1); float x0 = (float)(mechanism.Center.X - mechanism.R1); //for rope moving block float x = (float)(mechanism.Center.X + mechanism.R1); float y = (float)(mechanism.Center.Y + ((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 = y0 + mechanism.R1 + lv - mi.Timems * mechanism.v_block * 0.05; if ((yb - (y0 + mechanism.R1) < 0.001 || ((y + mechanism.State.deltaO2) - mechanism.Center.Y) < 0.01) && mi.Timems != 0) { mi.Timer.Stop(); return; } //clear Rect.Location = new Point(0, 0); Rect.Size = new Size(bp.Size.Width, bp.Size.Height); g.FillRectangle(SBr, Rect); //block big static Rect.Location = new Point((int)x0, (int)y0); Rect.Size = new Size((int)(2 * mechanism.R1), (int)(2 * mechanism.R1)); g.FillEllipse(SBr, Rect); g.DrawEllipse(p, Rect); //block small static Rect.Location = new Point((int)(mechanism.Center.X - mechanism.r1), (int)(mechanism.Center.Y - mechanism.r1)); Rect.Size = new Size((int)(2 * mechanism.r1), (int)(2 * mechanism.r1)); g.FillEllipse(SBr, Rect); g.DrawEllipse(p, Rect); //bearing draw Point side = new Point(mechanism.Center.X - 10, mechanism.Center.Y + 20); g.DrawLine(p, side, mechanism.Center); side.X = mechanism.Center.X + 10; side.Y = mechanism.Center.Y + 20; g.DrawLine(p, mechanism.Center, side); Rect.Location = new Point(mechanism.Center.X - 15, mechanism.Center.Y + 20); Rect.Size = new Size(30, 7); g.FillRectangle(Br, Rect); g.DrawLine(p, mechanism.Center.X + 15, mechanism.Center.Y + 20, mechanism.Center.X - 15, mechanism.Center.Y + 20); //bearing ball Rect.Location = new Point(mechanism.Center.X - 5, mechanism.Center.Y - 5); Rect.Size = new Size(10, 10); g.FillEllipse(SBr, Rect); g.DrawEllipse(p, Rect); //dot lines p.DashStyle = DashStyle.DashDot; g.DrawLine(p, (int)(mechanism.Center.X + mechanism.R1 * Math.Sin(mechanism.State.rot1)), (int)(mechanism.Center.Y - mechanism.R1 * Math.Cos(mechanism.State.rot1)), (int)(mechanism.Center.X - mechanism.R1 * Math.Sin(mechanism.State.rot1)), (int)(mechanism.Center.Y + mechanism.R1 * Math.Cos(mechanism.State.rot1))); g.DrawLine(p, (int)(mechanism.Center.X - mechanism.R1 * Math.Cos(mechanism.State.rot1)), (int)(mechanism.Center.Y - mechanism.R1 * Math.Sin(mechanism.State.rot1)), (int)(mechanism.Center.X + mechanism.R1 * Math.Cos(mechanism.State.rot1)), (int)(mechanism.Center.Y + mechanism.R1 * Math.Sin(mechanism.State.rot1))); p.DashStyle = DashStyle.Solid; //rope left g.DrawLine(p, x, mechanism.Center.Y, (float)(mechanism.Center.X + mechanism.R1), (int)(y + mechanism.State.deltaO2)); //rope right g.DrawLine(p, xx, (int)(y + mechanism.State.deltaO2), (float)(x + 2 * mechanism.r2), y0); //mount g.DrawLine(p, xx - 30, y0, xx + 30, y0); Rect.Location = new Point((int)(xx - 30), (int)(y0 - 10)); Rect.Size = new Size(60, 10); g.FillRectangle(Br, Rect); //blockrope g.DrawLine(p, (float)(x0 + (mechanism.R1 - mechanism.r1)), (float)(y0 + mechanism.R1), (float)(x0 + (mechanism.R1 - mechanism.r1)), (float)(yb)); Rect.Location = new Point((int)(x0 + (mechanism.R1 - mechanism.r1) - 10), (int)yb); Rect.Size = new Size(20, 30); g.FillRectangle(Br, Rect); g.DrawRectangle(p, Rect); //block moving Rect.Location = new Point((int)x, (int)(y - mechanism.r2 + mechanism.State.deltaO2)); Rect.Size = new Size((int)(2 * mechanism.r2), (int)(2 * mechanism.r2)); g.FillEllipse(SBr, Rect); g.DrawEllipse(p, Rect); //dots line double xo2 = Rect.Location.X + mechanism.r2, yo2 = Rect.Location.Y + mechanism.r2; p.DashStyle = DashStyle.DashDot; g.DrawLine(p, (int)(xo2 - mechanism.r2 * Math.Sin(mechanism.State.rot2)), (int)(yo2 - mechanism.r2 * Math.Cos(mechanism.State.rot2)), (int)(xo2 + mechanism.r2 * Math.Sin(mechanism.State.rot2)), (int)(yo2 + mechanism.r2 * Math.Cos(mechanism.State.rot2))); g.DrawLine(p, (int)(xo2 - mechanism.r2 * Math.Cos(mechanism.State.rot2)), (int)(yo2 + mechanism.r2 * Math.Sin(mechanism.State.rot2)), (int)(xo2 + mechanism.r2 * Math.Cos(mechanism.State.rot2)), (int)(yo2 - mechanism.r2 * Math.Sin(mechanism.State.rot2))); p.DashStyle = DashStyle.Solid; //trajectories if (mi.choise != Dots.None) { DrawTrajectory(mi.mechanism.ID, mi.Timems == 0, g); } mi.G.DrawImage(bp, 0, 0); g.Dispose(); mi.Timems += mi.Timer.Interval; } }