Esempio n. 1
0
        private static bool isCustomParticle(AbstractParticle p)
        {
            bool   isWP      = false;
            bool   isCP      = false;
            bool   isRP      = false;
            string className = p.ToString();

            //if (p is WheelParticle)
            //{
            //    isWP = true;
            //}
            if (p is CircleParticle)
            {
                isCP = true;
            }
            if (p is RectangleParticle)
            {
                isRP = true;
            }
            if (!(isWP || isCP || isRP))
            {
                return(true);
            }
            return(false);
        }
 public SpringConstraintParticle(AbstractParticle p1, AbstractParticle p2)
     : base(0, 0, 0, 0, 0, false, 1, 0.3, 0, Color.Black,
            "")
 {
     this.p1     = p1;
     this.p2     = p2;
     avgVelocity = new Vector(0, 0);
 }
Esempio n. 3
0
        public static void removeParticle(AbstractParticle p)
        {
            int ppos = particles.IndexOf(p);

            if (ppos == -1)
            {
                return;
            }
            //particles.Remove(ppos)
            particles.RemoveAt(ppos);
        }
Esempio n. 4
0
        private void updateEdgeParticles()
        {
            int i = 0;

            for (i = 0; i <= 3; i++)
            {
                AbstractParticle _edgeparticle = (AbstractParticle)_edgeParticles[i];

                _edgeparticle.setpx(((Vector)_edgePositions[i]).x);
                _edgeparticle.setpy(((Vector)_edgePositions[i]).y);
                // System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
            }
        }
Esempio n. 5
0
 public SpringConstraint(AbstractParticle p1, AbstractParticle p2, double stiffness)
     : base(stiffness)
 {
     this.p1 = p1;
     this.p2 = p2;
     checkParticlesLocation();
     _collisionRectWidth = 1;
     _collisionRectScale = 1;
     _collidable         = false;
     delta       = p1.curr.minus(p2.curr);
     deltaLength = p1.curr.distance(p2.curr);
     restLen     = deltaLength;
 }
Esempio n. 6
0
        public static ArrayList getAPEParticles()
        {
            ArrayList apeParticles = new ArrayList();
            int       i            = 0;

            for (i = 0; i <= particles.Count - 1; i++)
            {
                AbstractParticle p = (AbstractParticle)particles[i];
                if (!isCustomParticle(p))
                {
                    apeParticles.Add(p);
                }
                //System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
            }
            return(apeParticles);
        }
Esempio n. 7
0
        public static void resolveParticleParticle(AbstractParticle pa, AbstractParticle pb, Vector normal, double depth)
        {
            Vector mtd = normal.mult(depth);
            double te  = pa.getElasticity() + pb.getElasticity();
            double tf  = 1 - (pa.getFriction() + pb.getFriction());

            if (tf > 1)
            {
                tf = 1;
            }
            else if (tf < 0)
            {
                tf = 0;
            }
            double    ma = (pa.getFixed()) ? 100000 : pa.getMass();
            double    mb = (pb.getFixed()) ? 100000 : pb.getMass();
            double    tm = ma + mb;
            Collision ca = pa.getComponents(normal);
            Collision cb = pb.getComponents(normal);

            if (ca.vn.x > 5)
            {
                int i = 9;
            }
            Vector vnA = (cb.vn.mult((te + 1) * mb).plus(ca.vn.mult(ma - te * mb))).divEquals(tm);
            Vector vnB = (ca.vn.mult((te + 1) * ma).plus(cb.vn.mult(mb - te * ma))).divEquals(tm);

            ca.vt.multEquals(tf);
            cb.vt.multEquals(tf);
            Vector mtdA = mtd.mult(mb / tm);
            Vector mtdB = mtd.mult(-ma / tm);

            if (!pa.getFixed())
            {
                pa.resolveCollision(mtdA, vnA.plusEquals(ca.vt), normal, depth, -1);
                //My.Computer.Audio.Play(System.AppDomain.CurrentDomain.BaseDirectory & "\fall.wav")
                if (vnA.x > 5)
                {
                    int i = 9;
                }
            }
            if (!pb.getFixed())
            {
                pb.resolveCollision(mtdB, vnB.plusEquals(cb.vt), normal, depth, 1);
            }
        }
Esempio n. 8
0
        public static void test(AbstractParticle objA, AbstractParticle objB)
        {
            if (objA.getFixed() && objB.getFixed())
            {
                return;

                return;
            }
            //// rectangle to rectangle
            if (objA is RectangleParticle & objB is RectangleParticle)
            {
                RectangleParticle objArect = (RectangleParticle)objA;
                RectangleParticle objBrect = (RectangleParticle)objB;

                testOBBvsOBB(objArect, objBrect);
                //// circle to circle
            }
            else if (objA is CircleParticle & objB is CircleParticle)
            {
                CircleParticle objAcir = (CircleParticle)objA;
                CircleParticle objBcir = (CircleParticle)objB;

                testCirclevsCircle(objAcir, objBcir);
                //// rectangle to circle - two ways
            }
            else if (objA is RectangleParticle & objB is CircleParticle)
            {
                RectangleParticle objArect = (RectangleParticle)objA;
                CircleParticle    objBcir  = (CircleParticle)objB;

                testOBBvsCircle(objArect, objBcir);
            }
            else if (objA is CircleParticle & objB is RectangleParticle)
            {
                CircleParticle    objAcir  = (CircleParticle)objA;
                RectangleParticle objBrect = (RectangleParticle)objB;

                testOBBvsCircle(objBrect, objAcir);
            }
            //testOBBvsOBB(DirectCast(objA, RectangleParticle), DirectCast(objB, RectangleParticle))
        }
Esempio n. 9
0
        private static void checkCollisions()
        {
            for (int j = 0; j <= particles.Count - 1; j++)
            {
                AbstractParticle pa = (AbstractParticle)particles[j];
                //DirectCast(particles.Item(j), AbstractParticle)

                int i = 0;

                for (i = j + 1; i <= particles.Count - 1; i++)
                {
                    AbstractParticle pb = (AbstractParticle)particles[i];
                    //DirectCast(particles.Item(i), AbstractParticle)
                    if ((pa.getCollidable() & pb.getCollidable()))
                    {
                        CollisionDetector.test(pa, pb);
                    }
                }

                for (int n = 0; n <= constraints.Count - 1; n++)
                {
                    if (constraints[n] is AngularConstraint)
                    {
                        //Do nothing
                    }
                    else
                    {
                        SpringConstraint c = (SpringConstraint)constraints[n];
                        if ((pa.getCollidable() & c.getCollidable() & (!c.isConnectedTo(pa))))
                        {
                            CollisionDetector.test(pa, c.getCollisionRect());
                        }
                    }
                }
                pa.isColliding = false;
            }
        }
Esempio n. 10
0
 public bool isConnectedTo(AbstractParticle p)
 {
     return(p.Equals(p1) | p.Equals(p2));
 }
Esempio n. 11
0
 public AngularConstraint(AbstractParticle p1, AbstractParticle p2, AbstractParticle p3, double stiffness)
 {
     stiffness = 0.4;
 }
Esempio n. 12
0
 public static void addParticle(AbstractParticle p)
 {
     particles.Add(p);
 }