Пример #1
0
        public void VelocityColl(PointMass A, Connection B)
        {
            Vector_2d pos = get_line_intersection(A.Pos, A.OldPos, PointMassList[B.PointA].Pos, PointMassList[B.PointB].Pos);

            if (pos != null)
            {
                float     COR            = 0.98F;//Coefficent of restetution
                Vector_2d ConB           = PointMassList[B.PointA].Pos.Sub(PointMassList[B.PointB].Pos);
                Vector_2d ConBPerpNormal = ConB.Perpendicular().Div((float)Math.Sqrt(ConB.Dot(ConB)));
                Vector_2d Velocity       = A.OldPos.Sub(A.Pos);
                Vector_2d newVelocity    = PointMassList[B.PointA].OldPos.Sub(PointMassList[B.PointA].Pos);
                newVelocity = newVelocity.Add(PointMassList[B.PointB].OldPos.Sub(PointMassList[B.PointB].Pos));
                //newVelocity = newVelocity.Sub(Velocity);
                float Distribution = (float)Math.Sqrt(pos.Sub(PointMassList[B.PointA].Pos).Dot(pos.Sub(PointMassList[B.PointA].Pos))) / B.UsedDistance;


                A.Pos = A.OldPos.Add(newVelocity.Mult(COR));
                PointMassList[B.PointA].Pos = PointMassList[B.PointA].OldPos.Add(Velocity.Mult(1 - Distribution));
                PointMassList[B.PointB].Pos = PointMassList[B.PointB].OldPos.Add(Velocity.Mult(Distribution));
                B.Damadge -= (A.Mass * A.DamadgeMulti);
                if (A.State == 6 && !A.Grabbed)
                {
                    int conA = Game.World.AddConnection(new ConnectionStaticDistance(Game.World, A.Id, B.PointA));
                    int conB = Game.World.AddConnection(new ConnectionStaticDistance(Game.World, A.Id, B.PointB));
                    Game.World.ConnectionList[conA].Render = false;
                    Game.World.ConnectionList[conB].Render = false;
                    PointMassList[A.Id].Grabbed            = true;
                    if (A.Player != -1)
                    {
                        PlayerList[A.Player].JointActuators.Add(new int[] { conA, A.Id });
                        PlayerList[A.Player].JointActuators.Add(new int[] { conB, A.Id });
                    }
                }
            }
        }
Пример #2
0
        public void Intergrate(World world, float friction = 0)
        {
            friction /= InverseMass;
            Vector_2d newOld      = Pos;
            Vector_2d Friction    = new Vector_2d(2 - friction, 2 - friction); //Normal air friction
            Vector_2d FrictionOld = new Vector_2d(1 - friction, 1 - friction); //Normal air friction

            if (OnGround)
            {
                //Friction.X = 1 + friction;
                //FrictionOld.X = friction;
            }
            Pos          = Pos.Mult(Friction).Sub(OldPos.Mult(FrictionOld));
            Pos          = Pos.Add(Acceleration.Mult(world.DeltaTime * world.DeltaTime));
            OldPos       = newOld;
            Acceleration = new Vector_2d(0, 0);
        }
Пример #3
0
        public void CheckBounds(World world)
        {
            bool      Affect   = false;
            Vector_2d Displace = new Vector_2d();

            if (Pos.Y < world.BufferSize)
            {
                Affect     = true;
                Displace.Y = (world.BufferSize - Pos.Y);
            }
            if (Math.Abs(Pos.Y - world.BufferSize) < 5 || Pos.Y < world.BufferSize)
            {
                OnGround = true;
            }
            else
            {
                OnGround = false;
            }
            if (Pos.Y > world.Size.Y - world.BufferSize)
            {
                Affect     = true;
                Displace.Y = ((world.Size.Y - world.BufferSize) - Pos.Y);
            }
            if (Pos.X < world.BufferSize)
            {
                Affect     = true;
                Displace.X = (world.BufferSize - Pos.X);
            }
            if (Pos.X > world.Size.X - world.BufferSize)
            {
                Affect     = true;
                Displace.X = ((world.Size.X - world.BufferSize) - Pos.X);
            }
            if (Affect)
            {
                Vector_2d newOld = Pos.Add(Displace.Mult(2F));
                Pos    = OldPos;
                OldPos = newOld;
            }
        }
Пример #4
0
 public void Accerate(Vector_2d vec, World world)
 {
     Acceleration = Acceleration.Add(vec);
 }