예제 #1
0
        private void simForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (particle != null)
            {
                particle.Unmark();
            }
            if (line != null)
            {
                line.Unmark();
            }
            if (connection != null)
            {
                connection.Unmark();
            }

            a = new Vector(e.X, e.Y);

            particle = null;
            foreach (Particle p in World.Particles)
            {
                if ((p.Position - a).Length < (p.Radius / 2) + 1)
                {
                    particle = p;
                    particle.Mark();
                    break;
                }
            }

            if (true)
            {
                line = null;
                foreach (Line l in World.Lines)
                {
                    if (l.Distance(a) < 5)
                    {
                        line = l;
                        line.Mark();
                        break;
                    }
                }
            }

            if (true)
            {
                connection = null;
                foreach (ParticleConnection c in World.Connections)
                {
                    Line temp = new Line(c.Particle1.Position, c.Particle2.Position);
                    if (temp.Distance(a) < 5)
                    {
                        connection = c;
                        connection.Mark();
                        break;
                    }
                }
            }
        }
예제 #2
0
        private void simForm_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            switch (name)
            {
            case "particle":
                Particle p = new Particle();
                p.Position = new Vector(e.X, e.Y);
                p.Mass     = m;
                p.Radius   = r;
                p.Mark();
                World.AddParticle(p);
                particle = p;
                break;

            case "circle":
                World.BuildCircle(e.X, e.Y, (int)d, (int)r);
                break;

            case "wall":
                World.BuildWall(e.X, e.Y, (int)h, (int)w, (int)r, false);
                break;

            case "rope":
                World.BuildRope(e.X, e.Y, (int)l, this.e, m, r);
                break;

            case "square":
                World.BuildSquare(e.X, e.Y, (int)h, (int)w);
                break;

            case "chain":
                World.BuildChain(e.X, e.Y, (int)l, (int)r, (int)m, true, true);
                break;

            default:
                break;
            }
            Invalidate();
        }