Exemplo n.º 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++;
        }
Exemplo n.º 2
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++;
        }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
 public static void HandleAllObjects( GameObject physObject, List<GameObject> objectList)
 {
     if (Mode == PhysMode.CircleBox)
     {
         foreach (GameObject obj in objectList)
         {
             CollideCircleBox(physObject, obj);
         }
     }
     else
     {
         foreach (GameObject obj in objectList)
         {
             CollideBox(physObject, obj);
         }
     }
 }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        public void RenderObjects(OpenGL gl, GameObject[] objects)
        {
            //clears the screen
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            //St matrix mode to PROJECTION so we can move the camera
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            //  Load the identity matrix.
            gl.LoadIdentity();
            //Move the camera
            CamController.SetCam(gl);
            //Set matrix mode back to Modelview so we can draw objects
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            if (_mode == RenderMode.WireFrame || _mode == RenderMode.Hitboxes)
            {
                foreach(GameObject obj in objects){
                    //Draw the object with texture
                    obj.Draw(gl);
                    //Unbind texture so we can draw lines
                    gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
                    if ( _mode == RenderMode.Hitboxes)
                    {
                        obj.DrawVelocity(gl);
                        DrawCircle(gl, obj.GetPosition().x,obj.GetPosition().y, obj.GetPhysSize());
                    }
                    else
                    {
                        obj.DrawWireFrame(gl);
                    }
                }
            }
            else
            {
                foreach ( GameObject obj in objects )
                {
                    //Draw the object with texture
                    obj.Draw(gl);
                }
            }
            //Unbind texture
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
        }
Exemplo n.º 8
0
 public static void AddGameObject(GameObject obj)
 {
     toAdd.Add(obj);
 }
Exemplo n.º 9
0
 public virtual bool OnColision(GameObject col, float inpact)
 {
     return true;
 }