public static void CollideBox(GameObject physObject1, GameObject physObject2)
        {
            PointFloat vel1 = physObject1.GetVelocity();
            PointFloat vel2 = physObject2.GetVelocity();
            float      h1   = -(float)Math.Atan2(vel1.x, vel1.y);
            float      h2   = -(float)Math.Atan2(vel2.x, vel2.y);

            if (h2 > h1 + (_pi / 2.0f) && h2 < h1 - (_pi / 2.0f))
            {
                return;
            }
            PointFloat pos1 = physObject1.GetPosition();
            PointFloat pos2 = physObject2.GetPosition();
            float      x    = pos1.x - pos2.x;
            float      y    = pos1.y - pos2.y;
            float      h    = -(float)Math.Atan2(x, y);
            PointFloat dir  = GetDirection(h + (float)Math.PI / 2.0f);
            float      e1   = (Math.Abs(vel1.x) + Math.Abs(vel2.x)) * dir.x;
            float      e2   = (Math.Abs(vel1.y) + Math.Abs(vel2.y)) * dir.y;

            e1 = e1 / 2;
            e2 = e2 / 2;
            if (!physObject1.OnColision(physObject2, e1 + e2))
            {
                return;
            }
            int count = 0;

            while (count <= 10 && IsInBox(physObject1.GetPosition(), physObject2.GetPosition(), physObject1.GetSize(), physObject2.GetSize()))
            {
                if (vel1.GetSpeed() < vel2.GetSpeed())
                {
                    physObject2.SetPosAdd(vel2 / -10);
                }
                else
                {
                    physObject1.SetPosAdd(vel1 / 10);
                }
                count++;
            }
            if (physObject2.HasMass() == true)
            {
                physObject1.SetVelocity(0, 0);
            }
            if (physObject1.HasMass() == true)
            {
                physObject2.SetVelocity(0, 0);
            }

            PhysInteractions++;
        }
Beispiel #2
0
        public static void CollideBox(GameObject physObject1, GameObject physObject2)
        {
            PointFloat vel1 = physObject1.GetVelocity();
            PointFloat vel2 = physObject2.GetVelocity();
            float h1 = -(float)Math.Atan2(vel1.x, vel1.y);
            float h2 = -(float)Math.Atan2(vel2.x, vel2.y);
            if (h2 > h1 + (_pi / 2.0f) && h2 < h1 - (_pi / 2.0f))
            {
                return;
            }
            PointFloat pos1 = physObject1.GetPosition();
            PointFloat pos2 = physObject2.GetPosition();
            float x = pos1.x - pos2.x;
            float y = pos1.y - pos2.y;
            float h = -(float)Math.Atan2(x, y);
            PointFloat dir = GetDirection(h + (float)Math.PI / 2.0f);
            float e1 = (Math.Abs(vel1.x) + Math.Abs(vel2.x)) * dir.x;
            float e2 = (Math.Abs(vel1.y) + Math.Abs(vel2.y)) * dir.y;
            e1 = e1 / 2;
            e2 = e2 / 2;
            if (!physObject1.OnColision(physObject2, e1 + e2))
            {
                return;
            }
            int count = 0;
            while (count <= 10 && IsInBox(physObject1.GetPosition(), physObject2.GetPosition(), physObject1.GetSize(), physObject2.GetSize()))
            {
                if (vel1.GetSpeed() < vel2.GetSpeed())
                {
                    physObject2.SetPosAdd(vel2 / -10);
                }
                else
                {
                    physObject1.SetPosAdd(vel1 / 10);
                }
                count++;
            }
            if (physObject2.HasMass() == true)
            {
                physObject1.SetVelocity(0, 0);
            }
            if (physObject1.HasMass() == true)
            {
                physObject2.SetVelocity(0, 0);
            }

            PhysInteractions++;
        }
        public static List <GameObject> GetAllOverlapping(GameObject physObject)
        {
            _tempList.Clear();
            if (Mode == PhysMode.CircleBox)
            {
                PointFloat physPos  = physObject.GetPosition();
                float      physSize = physObject.GetPhysSize();
                foreach (GameObject obj in TomatoMainEngine.GameObjects)
                {
                    if (obj.HasPhysics() && obj != physObject && !(physObject.IsParticle() && obj.Type == physObject.Type))
                    {
                        PointFloat objPos    = obj.GetPosition();
                        float      gemX      = Math.Abs(objPos.x - physPos.x);
                        float      gemY      = Math.Abs(objPos.y - physPos.y);
                        float      fDistance = gemX + gemY - obj.GetPhysSize();
                        if (fDistance < physSize)
                        {
                            _tempList.Add(obj);
                        }
                    }
                }
            }
            else
            {
                PointFloat physPos  = physObject.GetPosition();
                PointFloat physSize = physObject.GetSize();
                foreach (GameObject obj in TomatoMainEngine.GameObjects)
                {
                    if (obj.HasPhysics() && obj != physObject && !(physObject.IsParticle() && obj.Type == physObject.Type))
                    {
                        if (IsInBox(physPos, obj.GetPosition(), physSize, obj.GetSize()))
                        {
                            _tempList.Add(obj);
                        }
                    }
                }
            }

            return(_tempList);
        }
        public static bool IsOverlappingInCircle(GameObject physObject1, GameObject physObject2)
        {
            PointFloat physPos  = physObject1.GetPosition();
            float      physSize = physObject1.GetPhysSize();

            if (physObject2.HasPhysics() && !(physObject2.IsParticle() && physObject2.Type == physObject1.Type))
            {
                PointFloat objPos    = physObject2.GetPosition();
                float      fDistance = (float)(Math.Pow(physPos.x - objPos.x, 2) + Math.Pow(physPos.y - objPos.y, 2));
                if (fDistance < physSize + physObject2.GetPhysSize())
                {
                    return(true);
                }
            }
            return(false);
        }
        //handles collision
        public static void CollideCircleBox(GameObject physObject1, GameObject physObject2)
        {
            PointFloat vel1 = physObject1.GetVelocity();
            PointFloat vel2 = physObject2.GetVelocity();
            float      h1   = -(float)Math.Atan2(vel1.x, vel1.y);
            float      h2   = -(float)Math.Atan2(vel2.x, vel2.y);

            if (h2 > h1 + (_pi / 2.0f) && h2 < h1 - (_pi / 2.0f))
            {
                return;
            }
            PointFloat pos1 = physObject1.GetPosition();
            PointFloat pos2 = physObject2.GetPosition();
            float      x    = pos1.x - pos2.x;
            float      y    = pos1.y - pos2.y;
            float      h    = -(float)Math.Atan2(x, y);
            PointFloat dir  = GetDirection(h + (float)Math.PI / 2.0f);
            //while ( IsOverlappingInCircle(physObject1, physObject2) )
            //{
            //physObject1.SetPosAdd(dir / 1);
            //physObject2.SetPosAdd(dir / -1);
            //}
            float e1 = (Math.Abs(vel1.x) + Math.Abs(vel2.x)) * dir.x;
            float e2 = (Math.Abs(vel1.y) + Math.Abs(vel2.y)) * dir.y;

            e1 = e1 / 2;
            e2 = e2 / 2;
            if (!physObject1.OnColision(physObject2, e1 + e2))
            {
                return;
            }

            if (physObject2.HasMass() == true)
            {
                physObject1.SetPosAdd(vel1 / -1);
                physObject1.SetVelocity(e1, e2);
                physObject1.SetRotationVelocity(((float)Math.Atan2(vel1.x + vel2.x, vel1.y + vel2.y) - (float)Math.Atan2(x, y)) / 100f);
            }
            if (physObject1.HasMass() == true)
            {
                physObject2.SetVelocity(-e1, -e2);
                physObject2.SetRotationVelocity(((float)Math.Atan2(vel1.x + vel2.x, vel1.y + vel2.y) - (float)Math.Atan2(x, y)) / 100f);
            }

            PhysInteractions++;
        }
        //is colliding
        public static bool IsOverlappingInCircle(GameObject physObject)
        {
            PointFloat physPos  = physObject.GetPosition();
            float      physSize = physObject.GetPhysSize();

            foreach (GameObject obj in TomatoMainEngine.GameObjects)
            {
                if (obj.HasPhysics() && !(obj.IsParticle() && obj.Type == physObject.Type) && obj != physObject)
                {
                    float fDistance = (float)(Math.Pow(physPos.x - obj.GetPosition().x, 2) + Math.Pow(physPos.y - obj.GetPosition().y, 2));
                    if (fDistance < physSize + obj.GetPhysSize())
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #7
0
        //handles collision
        public static void CollideCircleBox(GameObject physObject1, GameObject physObject2)
        {
            PointFloat vel1 = physObject1.GetVelocity();
            PointFloat vel2 = physObject2.GetVelocity();
            float h1 = -(float)Math.Atan2(vel1.x, vel1.y);
            float h2 = -(float)Math.Atan2(vel2.x, vel2.y);
            if ( h2 > h1 + (_pi/2.0f) && h2 < h1 - (_pi/2.0f) )
            {
                return;
            }
            PointFloat pos1 = physObject1.GetPosition();
            PointFloat pos2 = physObject2.GetPosition();
            float x = pos1.x - pos2.x;
            float y = pos1.y - pos2.y;
            float h = -(float)Math.Atan2(x, y);
            PointFloat dir = GetDirection(h + (float)Math.PI / 2.0f);
            //while ( IsOverlappingInCircle(physObject1, physObject2) )
            //{
                //physObject1.SetPosAdd(dir / 1);
                //physObject2.SetPosAdd(dir / -1);
            //}
            float e1 = ( Math.Abs(vel1.x) + Math.Abs(vel2.x) ) * dir.x;
            float e2 = ( Math.Abs(vel1.y)+ Math.Abs(vel2.y) ) * dir.y;
            e1 = e1 / 2;
            e2 = e2 / 2;
            if(!physObject1.OnColision(physObject2, e1 + e2)){
                return;
            }

            if ( physObject2.HasMass()  == true )
            {
                physObject1.SetPosAdd(vel1 / -1);
                physObject1.SetVelocity(e1, e2);
                physObject1.SetRotationVelocity(( (float)Math.Atan2(vel1.x + vel2.x, vel1.y + vel2.y) - (float)Math.Atan2(x, y) ) / 100f);
            }
            if ( physObject1.HasMass() == true )
            {
                physObject2.SetVelocity(-e1, -e2);
                physObject2.SetRotationVelocity(( (float)Math.Atan2(vel1.x + vel2.x, vel1.y + vel2.y) - (float)Math.Atan2(x, y) ) / 100f);
            }

            PhysInteractions++;
        }
Beispiel #8
0
        public static bool IsOverlappingInCircle(GameObject physObject1, GameObject physObject2)
        {
            PointFloat physPos = physObject1.GetPosition();
            float physSize = physObject1.GetPhysSize();

            if (physObject2.HasPhysics() && !( physObject2.IsParticle () && physObject2.Type == physObject1.Type))
            {
                PointFloat objPos = physObject2.GetPosition();
                float fDistance = (float)( Math.Pow(physPos.x-objPos.x, 2) + Math.Pow(physPos.y-objPos.y, 2) );
                if ( fDistance < physSize + physObject2.GetPhysSize() )
                {
                    return true;
                }
            }
            return false;
        }
Beispiel #9
0
 //is colliding
 public static bool IsOverlappingInCircle(GameObject physObject)
 {
     PointFloat physPos = physObject.GetPosition();
     float physSize = physObject.GetPhysSize();
     foreach (GameObject obj in TomatoMainEngine.GameObjects)
     {
         if (obj.HasPhysics() && !(obj.IsParticle() && obj.Type == physObject.Type) && obj != physObject)
         {
             float fDistance = (float)(Math.Pow(physPos.x - obj.GetPosition().x, 2) + Math.Pow(physPos.y - obj.GetPosition().y, 2));
             if (fDistance < physSize + obj.GetPhysSize())
             {
                 return true;
             }
         }
     }
     return false;
 }
Beispiel #10
0
        public static List<GameObject> GetAllOverlapping(GameObject physObject)
        {
            _tempList.Clear();
            if(Mode == PhysMode.CircleBox){
                PointFloat physPos = physObject.GetPosition();
                float physSize = physObject.GetPhysSize();
                foreach (GameObject obj in TomatoMainEngine.GameObjects)
                {
                    if (obj.HasPhysics() && obj != physObject && !(physObject.IsParticle() && obj.Type == physObject.Type))
                    {
                        PointFloat objPos = obj.GetPosition();
                        float gemX = Math.Abs(objPos.x - physPos.x);
                        float gemY = Math.Abs(objPos.y - physPos.y);
                        float fDistance = gemX + gemY - obj.GetPhysSize();
                        if (fDistance < physSize)
                        {
                            _tempList.Add(obj);
                        }
                    }
                }
            }
            else
            {
                PointFloat physPos = physObject.GetPosition();
                PointFloat physSize = physObject.GetSize();
                foreach (GameObject obj in TomatoMainEngine.GameObjects)
                {
                    if (obj.HasPhysics() && obj != physObject && !(physObject.IsParticle() && obj.Type == physObject.Type))
                    {
                        if (IsInBox(physPos, obj.GetPosition(), physSize, obj.GetSize()))
                        {
                            _tempList.Add(obj);
                        }
                    }
                }
            }

            return _tempList;
        }