Пример #1
0
        public override void reactToCollision(PhysObj otherObj)
        {
            PhysCircle otherCircle = (PhysCircle)otherObj;

            Vector2 difference = getCenter() - otherCircle.getCenter();
            float d = difference.Length();

            Vector2 mtd = difference * ((radius + otherCircle.radius) - d) / d;

            float im1 = 1 / Mass;
            float im2 = 1 / otherObj.Mass;

            Position += mtd * (im1 / (im1 + im2));
            otherObj.Position -= mtd * (im2 / (im1 + im2));

            Vector2 v = Velocity - otherObj.Velocity;
            Vector2 mtdN = mtd;
            mtdN.Normalize();
            float vn = Vector2.Dot(v, mtdN);

            if (vn > 0.0f)
            {
                return;
            }

            float i = (-(1.0f + bounce) * vn) / (im1 + im2);
            Vector2 impulse = mtdN * i;

            Velocity += impulse * im1;
            otherObj.Velocity -= impulse * im2;
        }
Пример #2
0
        public override void reactToCollision(PhysObj otherObj)
        {
            PhysCircle otherCircle = (PhysCircle)otherObj;

            Vector2 difference = getCenter() - otherCircle.getCenter();
            float   d          = difference.Length();

            Vector2 mtd = difference * ((radius + otherCircle.radius) - d) / d;

            float im1 = 1 / Mass;
            float im2 = 1 / otherObj.Mass;

            Position          += mtd * (im1 / (im1 + im2));
            otherObj.Position -= mtd * (im2 / (im1 + im2));

            Vector2 v    = Velocity - otherObj.Velocity;
            Vector2 mtdN = mtd;

            mtdN.Normalize();
            float vn = Vector2.Dot(v, mtdN);

            if (vn > 0.0f)
            {
                return;
            }

            float   i       = (-(1.0f + bounce) * vn) / (im1 + im2);
            Vector2 impulse = mtdN * i;

            Velocity          += impulse * im1;
            otherObj.Velocity -= impulse * im2;
        }
Пример #3
0
        public override bool checkCollision(PhysObj otherObj)
        {
            PhysCircle otherCircle = (PhysCircle)otherObj;

            // for other shapes, there will need to be a method that returns the point closest to this circle
            // depending on shape type, rotation, etc. with that, this function should still work

            float distance = (otherCircle.getCenter() - getCenter()).Length();

            if (distance < radius + otherCircle.radius)
            {
                return true;
            }
            return false;
        }
Пример #4
0
        public override bool checkCollision(PhysObj otherObj)
        {
            PhysCircle otherCircle = (PhysCircle)otherObj;

            // for other shapes, there will need to be a method that returns the point closest to this circle
            // depending on shape type, rotation, etc. with that, this function should still work

            float distance = (otherCircle.getCenter() - getCenter()).Length();

            if (distance < radius + otherCircle.radius)
            {
                return(true);
            }
            return(false);
        }
Пример #5
0
 public abstract void reactToCollision(PhysObj otherObj);
Пример #6
0
 public abstract bool checkCollision(PhysObj otherObj);
Пример #7
0
 public override void reactToCollision(PhysObj otherObj)
 {
     throw new NotImplementedException();
 }
Пример #8
0
 public override bool checkCollision(PhysObj otherObj)
 {
     return false;
 }
Пример #9
0
 public abstract void reactToCollision(PhysObj otherObj);
Пример #10
0
 public abstract bool checkCollision(PhysObj otherObj);
Пример #11
0
 public override void reactToCollision(PhysObj otherObj)
 {
     throw new NotImplementedException();
 }
Пример #12
0
 public override bool checkCollision(PhysObj otherObj)
 {
     return(false);
 }