Exemplo n.º 1
0
        void applyConstraints()
        {
            //gravity
            if (setting.gravity != Vector2.zero)
            {
                for (int i = 0; i < sim.numberOfParticles(); ++i)
                {
                    p = sim.getParticle(i);
                    if (p.IsFree)
                    {
                        p.Position += setting.gravity;
                    }
                }
            }

            //iterations
            for (int iter = 0; iter < setting.iteration; iter++)
            {
                if (setting.applyString)
                {
                    for (int p = 1; p <= sim.maxSpringConvergenceID; p++)
                    {
                        for (int i = 0; i < sim.numberOfSprings(); i++)
                        {
                            Spring2D sp = sim.getSpring(i);
                            if (sp.convergenceGroupID == p)
                            {
                                sp.apply();
                            }
                        }
                    }
                }

                if (setting.applyAngle)
                {
                    for (int p = 1; p <= sim.maxAngleConvergenceID; p++)
                    {
                        for (int i = 0; i < sim.numberOfAngleConstraints(); i++)
                        {
                            AngleConstraint2D ag = sim.getAngleConstraint(i);
                            if (ag.convergenceGroupID == p)
                            {
                                ag.GetDelta();
                            }
                        }

                        for (int i = 0; i < sim.numberOfAngleConstraints(); i++)
                        {
                            AngleConstraint2D ag = sim.getAngleConstraint(i);
                            if (ag.convergenceGroupID == p)
                            {
                                ag.apply();
                            }
                        }
                    }
                }
            }
        }