Example #1
0
        public void Draw()
        {
            if (this.RenderDescription == null)
            {
                this.RenderDescription = new Nodes.RenderDescription();
            }

            if (particleSystem == null)
            {
                return;
            }

            for (int i = 0; i < particleSystem.numberOfParticles(); i++)
            {
                Particle p   = particleSystem.getParticle(i);
                XYZ      pos = p.getPosition();
                if (i < this.RenderDescription.points.Count())
                {
                    this.RenderDescription.points[i] = new Point3D(pos.X, pos.Y, pos.Z);
                }
                else
                {
                    Point3D pt = new System.Windows.Media.Media3D.Point3D(pos.X, pos.Y, pos.Z);
                    this.RenderDescription.points.Add(pt);
                }
            }

            for (int i = 0; i < particleSystem.numberOfSprings(); i++)
            {
                ParticleSpring ps   = particleSystem.getSpring(i);
                XYZ            pos1 = ps.getOneEnd().getPosition();
                XYZ            pos2 = ps.getTheOtherEnd().getPosition();

                if (i * 2 + 1 < this.RenderDescription.lines.Count())
                {
                    this.RenderDescription.lines[i * 2]     = new Point3D(pos1.X, pos1.Y, pos1.Z);
                    this.RenderDescription.lines[i * 2 + 1] = new Point3D(pos2.X, pos2.Y, pos2.Z);
                }
                else
                {
                    Point3D pt1 = new System.Windows.Media.Media3D.Point3D(pos1.X, pos1.Y, pos1.Z);
                    Point3D pt2 = new System.Windows.Media.Media3D.Point3D(pos2.X, pos2.Y, pos2.Z);

                    this.RenderDescription.lines.Add(pt1);
                    this.RenderDescription.lines.Add(pt2);
                }
            }
        }
        public void Draw()
        {
            if (RenderDescription == null)
            {
                RenderDescription = new RenderDescription();
            }

            if (ParticleSystem == null)
            {
                return;
            }

            for (int i = 0; i < ParticleSystem.numberOfParticles(); i++)
            {
                Particle p   = ParticleSystem.getParticle(i);
                XYZ      pos = p.getPosition();
                if (i < RenderDescription.points.Count())
                {
                    RenderDescription.points[i] = new Point3D(pos.X, pos.Y, pos.Z);
                }
                else
                {
                    var pt = new Point3D(pos.X, pos.Y, pos.Z);
                    RenderDescription.points.Add(pt);
                }
            }

            for (int i = 0; i < ParticleSystem.numberOfSprings(); i++)
            {
                ParticleSpring ps   = ParticleSystem.getSpring(i);
                XYZ            pos1 = ps.getOneEnd().getPosition();
                XYZ            pos2 = ps.getTheOtherEnd().getPosition();

                if (i * 2 + 1 < RenderDescription.lines.Count())
                {
                    RenderDescription.lines[i * 2]     = new Point3D(pos1.X, pos1.Y, pos1.Z);
                    RenderDescription.lines[i * 2 + 1] = new Point3D(pos2.X, pos2.Y, pos2.Z);
                }
                else
                {
                    var pt1 = new Point3D(pos1.X, pos1.Y, pos1.Z);
                    var pt2 = new Point3D(pos2.X, pos2.Y, pos2.Z);

                    RenderDescription.lines.Add(pt1);
                    RenderDescription.lines.Add(pt2);
                }
            }
        }
Example #3
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            ParticleSystem particleSystem = (ParticleSystem)((Value.Container)args[0]).Item;

            var result = FSharpList <Value> .Empty;

            Particle p;
            XYZ      pt;

            //create an XYZ from each Particle
            for (int i = 0; i < particleSystem.numberOfParticles(); i++)
            {
                p      = particleSystem.getParticle(i);
                pt     = new XYZ(p.getPosition().X, p.getPosition().Y, p.getPosition().Z);
                result = FSharpList <Value> .Cons(Value.NewContainer(pt), result);
            }

            return(Value.NewList(result));
        }
 private void UpdateSystem()
 {
     //update the spring values
     for (int j = 0; j < ParticleSystem.numberOfSprings(); j++)
     {
         ParticleSpring spring = ParticleSystem.getSpring(j);
         spring.setDamping(_d);
         if (!_useRl)
         {
             spring.setRestLength(_r);
         }
         spring.setSpringConstant(_s);
     }
     for (int j = 0; j < ParticleSystem.numberOfParticles(); j++)
     {
         Particle p = ParticleSystem.getParticle(j);
         p.setMass(_m);
     }
 }
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            _points    = ((Value.List)args[0]).Item;                      //point list
            _curves    = ((Value.List)args[1]).Item;                      //spring list
            _d         = ((Value.Number)args[2]).Item;                    //dampening
            _s         = ((Value.Number)args[3]).Item;                    //spring constant
            _r         = ((Value.Number)args[4]).Item;                    //rest length
            _useRl     = Convert.ToBoolean(((Value.Number)args[5]).Item); //use rest length
            _rlf       = ((Value.Number)args[6]).Item;                    //rest length factor
            _m         = ((Value.Number)args[7]).Item;                    //nodal mass
            _g         = ((Value.Number)args[8]).Item;                    //gravity z component
            _threshold = ((Value.Number)args[9]).Item;                    //convergence threshold

            //if we are in the evaluate, this has been
            //marked dirty and we should set it to unconverged
            //in case one of the inputs has changed.
            ParticleSystem.setConverged(false);
            ParticleSystem.setGravity(_g);
            ParticleSystem.setThreshold(_threshold);

            //if the particle system has a different layout, then
            //clear it instead of updating
            if (ParticleSystem.numberOfParticles() == 0 ||
                _fixPtCount != _points.Count() ||
                _curves.Count() != ParticleSystem.numberOfSprings() ||
                _reset)
            {
                ResetSystem(_points, _curves);
            }
            else
            {
                UpdateSystem();
            }

            outPuts[_psPort]     = Value.NewContainer(ParticleSystem);
            outPuts[_forcesPort] = Value.NewList(Utils.SequenceToFSharpList(
                                                     ParticleSystem.Springs.Select(s => Value.NewNumber(s.getResidualForce()))));
        }
Example #6
0
        public void step(double t)
        {
            s.clearForces();
            s.applyForces();

            double halftt = 0.5 * t * t;
            double tt     = t * t;

            for (int i = 0; i < s.numberOfParticles(); i++)
            {
                Particle p = s.getParticle(i);
                if (p.isFree())
                {
                    XYZ a   = p.getForce() / p.getMass();
                    XYZ xmm = p.getOldPosition();
                    XYZ xm  = p.getPosition();
                    XYZ x   = xm.Add(xm - xmm) + a * tt;
                    XYZ vm  = p.getVelocity();

                    p.setPosition(x);
                    p.setVelocity((x - xmm) / (2 * t));
                }
            }
        }