예제 #1
0
 public ArrayList getEdgeParticles()
 {
     if (_edgePositions.Count == 0)
     {
         getEdgePositions();
     }
     if (_edgeParticles.Count == 0)
     {
         CircleParticle cp1 = new CircleParticle(0, 0, 1, false, 1, 0.3, 0, Color.Black, "edgeparticle");
         cp1.setCollidable(false);
         cp1.setVisible(false);
         APEngine.addParticle(cp1);
         CircleParticle cp2 = new CircleParticle(0, 0, 1, false, 1, 0.3, 0, Color.Black, "edgeparticle");
         cp2.setCollidable(false);
         cp2.setVisible(false);
         APEngine.addParticle(cp2);
         CircleParticle cp3 = new CircleParticle(0, 0, 1, false, 1, 0.3, 0, Color.Black, "edgeparticle");
         cp3.setCollidable(false);
         cp3.setVisible(false);
         APEngine.addParticle(cp3);
         CircleParticle cp4 = new CircleParticle(0, 0, 1, false, 1, 0.3, 0, Color.Black, "edgeparticle");
         cp4.setCollidable(false);
         cp4.setVisible(false);
         APEngine.addParticle(cp4);
         _edgeParticles.Add(cp1);
         _edgeParticles.Add(cp2);
         _edgeParticles.Add(cp3);
         _edgeParticles.Add(cp4);
         updateEdgeParticles();
     }
     return(_edgeParticles);
 }
예제 #2
0
        private static void integrate()
        {
            int i = 0;

            for (i = 0; i <= particles.Count - 1; i++)
            {
                if (particles[i] is RectangleParticle)
                {
                    //DirectCast(particles.Item(i), RectangleParticle).update(timeStep)
                    RectangleParticle objRect = (RectangleParticle)particles[i];

                    objRect.update(timeStep);
                }
                else if (particles[i] is CircleParticle)
                {
                    //DirectCast(particles.Item(i), CircleParticle).update(timeStep)

                    CircleParticle objCir = (CircleParticle)particles[i];

                    objCir.update(timeStep);

                    //particles[i].update(timeStep);
                }
            }
        }
예제 #3
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))
        }
예제 #4
0
        public static void testCirclevsCircle(CircleParticle ca, CircleParticle cb)
        {
            double depthX = testIntervals(ca.getIntervalX(), cb.getIntervalX());

            if (depthX == 0)
            {
                return;

                return;
            }
            double depthY = testIntervals(ca.getIntervalY(), cb.getIntervalY());

            if (depthY == 0)
            {
                return;

                return;
            }
            Vector collisionNormal = ca.curr.minus(cb.curr);
            double mag             = collisionNormal.magnitude();
            double collisionDepth  = (ca.getRadius() + cb.getRadius()) - mag;

            if (collisionDepth > 0)
            {
                collisionNormal.divEquals(mag);
                CollisionResolver.resolveParticleParticle(ca, cb, collisionNormal, collisionDepth);

                //*************collision
                ModEnumConst.nofcollosions = ModEnumConst.nofcollosions + 1;
                //*************


                //If cb.myColor = ca.myColor Then
                //    'My.Computer.Audio.Play(System.AppDomain.CurrentDomain.BaseDirectory & "\score.wav")
                //    Totalscore = Totalscore + 1

                //End If
            }
        }
예제 #5
0
        private static void testOBBvsCircle(RectangleParticle ra, CircleParticle ca)
        {
            Vector    collisionNormal = new Vector(0, 0);
            double    collisionDepth  = ModEnumConst.POSITIVE_INFINITY;
            ArrayList depths          = new ArrayList(2);
            int       i = 0;

            //While i < 2
            for (i = 0; i <= 1; i++)
            {
                Vector boxAxis = (Vector)ra.getAxes()[i];
                double depth   = testIntervals(ra.getProjection(boxAxis), ca.getProjection(boxAxis));
                if (depth == 0)
                {
                    return;

                    return;
                }
                if (Math.Abs(depth) < Math.Abs(collisionDepth))
                {
                    collisionNormal = boxAxis;
                    collisionDepth  = depth;
                }
                depths.Insert(i, depth);
                // System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
            }
            //End While
            double r = ca.getRadius();


            //SByte objSByte0 = (SByte)depths[0];
            int objSByte0 = Convert.ToInt32(depths[0]);



            //SByte objSByte1 = (SByte)depths[1];
            int objSByte1 = Convert.ToInt32(depths[1]);


            if (Math.Abs(objSByte0) < r && Math.Abs(objSByte1) < r)
            {
                Vector vertex = closestVertexOnOBB(ca.curr, ra);
                collisionNormal = vertex.minus(ca.curr);
                double mag = collisionNormal.magnitude();
                collisionDepth = r - mag;
                if (collisionDepth > 0)
                {
                    collisionNormal.divEquals(mag);


                    //*************collision
                    ModEnumConst.nofcollosions = ModEnumConst.nofcollosions + 1;
                    //*************


                    //If ra.myColor = ca.myColor Then

                    //    Totalscore = Totalscore + 1
                    //    'APEngine1.removeParticle(ca)
                    //    'APEngine1.removeParticle(ra)

                    //End If
                }
                else
                {
                    return;

                    return;
                }
            }
            CollisionResolver.resolveParticleParticle(ra, ca, collisionNormal, collisionDepth);
        }