Beispiel #1
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);
        }
Beispiel #3
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;
        }
        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++;
        }