Ejemplo n.º 1
0
        protected bool isCollidingWalls(CObject cobject2)
        {
            BoundingBox BB1, BB2;

            foreach (ModelMesh mesh in model.Meshes)
            {
                BoundingSphere m1BoundingSphere = mesh.BoundingSphere;
                m1BoundingSphere.Center  = position;
                m1BoundingSphere.Radius *= this.scale;
                BB1 = BoundingBox.CreateFromSphere(m1BoundingSphere);
                foreach (ModelMesh mesh2 in cobject2.Model.Meshes)
                {
                    BB2 = CalculateBoundingBox(cobject2);
                    if (cobject2.ID == "floor")
                    {
                        if (i == 0)
                        {
                            Console.WriteLine(BB2.Max);
                            Console.WriteLine(BB2.Min);
                            Console.WriteLine(position);
                        }
                        i++;
                        if (i > 10)
                        {
                            i = 0;
                        }
                    }
                    if (BB1.Intersects(BB2))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /*private BoundingBox createMerged(Model model) // Use it for low quality computers.
         * {
         *  BoundingBox b = new BoundingBox();
         *  BoundingBox aux;
         *  foreach (ModelMesh mesh in model.Meshes)
         *  {
         *      aux = BoundingBox.CreateFromSphere(mesh.BoundingSphere);
         *      BoundingBox.CreateMerged(b, aux);
         *  }
         *  return b;
         * }*/
        /*protected bool isCollidingBB(Model model2)
         * {
         *  BoundingBox BB1, BB2;
         *  BB1 = CalculateBoundingBox(this.model);
         *  BB2 = CalculateBoundingBox(model2);
         *  if (BB1.Intersects(BB2))
         *  {
         *      Console.WriteLine(BB1.GetCorners());
         *      Console.WriteLine(BB2.GetCorners());
         *      Console.WriteLine(BB1.Min + " - " + BB1.Max);
         *      Console.WriteLine(BB2.Min + " - " + BB2.Max);
         *      return true;
         *  }
         *  return false;
         * }*/
        protected bool isCollidingBB(CObject cobject2)
        {
            BoundingBox BB1, BB2;

            foreach (ModelMesh mesh in model.Meshes)
            {
                BoundingSphere m1BoundingSphere = mesh.BoundingSphere;
                m1BoundingSphere.Center  = position;
                m1BoundingSphere.Radius *= this.scale;
                BB1 = BoundingBox.CreateFromSphere(m1BoundingSphere);
                foreach (ModelMesh mesh2 in cobject2.Model.Meshes)
                {
                    BoundingSphere m2BoundingSphere = mesh2.BoundingSphere;
                    m2BoundingSphere.Center = cobject2.position;
                    if (cobject2.ID == "floor" || cobject2.ID.Contains("wall"))
                    {
                        m2BoundingSphere.Radius *= cobject2.scale * 30.0f;
                    }
                    else
                    {
                        m2BoundingSphere.Radius *= cobject2.scale;
                    }
                    BB2 = BoundingBox.CreateFromSphere(m2BoundingSphere);

                    if (BB1.Intersects(BB2))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        protected BoundingBox CalculateBoundingBox(CObject cobject)
        {
            Vector3 min = new Vector3(cobject.position.X, cobject.position.Y - cobject.specs.Y, cobject.position.Z);
            Vector3 max = new Vector3(cobject.position.X, cobject.position.Y + cobject.specs.Y, cobject.position.Z);

            min.X -= cobject.specs.X;
            min.Z -= cobject.specs.Z;
            max.X += cobject.specs.X;
            max.Z += cobject.specs.Z;

            /*min.X -= (rotation.Y == 0) ? cobject.specs.X : cobject.specs.Z;
            *  min.Z -= (rotation.Y == 0) ? cobject.specs.Z : cobject.specs.X;
            *  max.X += (rotation.Y == 0) ? cobject.specs.X : cobject.specs.Z;
            *  max.Z += (rotation.Y == 0) ? cobject.specs.Z : cobject.specs.X;*/
            return(new BoundingBox(min, max));
        }
Ejemplo n.º 4
0
 protected bool isCollidingBS(CObject cobject2, int i)
 {
     foreach (ModelMesh mesh in model.Meshes)
     {
         BoundingSphere m1BoundingSphere = mesh.BoundingSphere;
         m1BoundingSphere.Center  = position;
         m1BoundingSphere.Radius *= this.scale;
         foreach (ModelMesh mesh2 in cobject2.Model.Meshes)
         {
             BoundingSphere m2BoundingSphere = mesh2.BoundingSphere;
             m2BoundingSphere.Center  = cobject2.position;
             m2BoundingSphere.Radius *= cobject2.scale;
             if (m1BoundingSphere.Intersects(m2BoundingSphere))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
 protected bool isCollidingWalls(CObject cobject2)
 {
     BoundingBox BB1, BB2;
     foreach (ModelMesh mesh in model.Meshes) {
         BoundingSphere m1BoundingSphere = mesh.BoundingSphere;
         m1BoundingSphere.Center = position;
         m1BoundingSphere.Radius *= this.scale;
         BB1 = BoundingBox.CreateFromSphere(m1BoundingSphere);
         foreach (ModelMesh mesh2 in cobject2.Model.Meshes)
         {
             BB2 = CalculateBoundingBox(cobject2);
             if (cobject2.ID == "floor")
             {
                 if (i == 0)
                 {
                     Console.WriteLine(BB2.Max);
                     Console.WriteLine(BB2.Min);
                     Console.WriteLine(position);
                 }
                 i++;
                 if (i > 10)
                     i = 0;
             }
             if (BB1.Intersects(BB2))
             {
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 6
0
 protected bool isCollidingBS(CObject cobject2, int i)
 {
     foreach (ModelMesh mesh in model.Meshes)
     {
         BoundingSphere m1BoundingSphere = mesh.BoundingSphere;
         m1BoundingSphere.Center = position;
         m1BoundingSphere.Radius *= this.scale;
         foreach (ModelMesh mesh2 in cobject2.Model.Meshes)
         {
             BoundingSphere m2BoundingSphere = mesh2.BoundingSphere;
             m2BoundingSphere.Center = cobject2.position;
             m2BoundingSphere.Radius *= cobject2.scale;
             if (m1BoundingSphere.Intersects(m2BoundingSphere))
             {
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 7
0
        /*private BoundingBox createMerged(Model model) // Use it for low quality computers.
        {
            BoundingBox b = new BoundingBox();
            BoundingBox aux;
            foreach (ModelMesh mesh in model.Meshes)
            {
                aux = BoundingBox.CreateFromSphere(mesh.BoundingSphere);
                BoundingBox.CreateMerged(b, aux);
            }
            return b;
        }*/
        /*protected bool isCollidingBB(Model model2)
        {
            BoundingBox BB1, BB2;
            BB1 = CalculateBoundingBox(this.model);
            BB2 = CalculateBoundingBox(model2);
            if (BB1.Intersects(BB2))
            {
                Console.WriteLine(BB1.GetCorners());
                Console.WriteLine(BB2.GetCorners());
                Console.WriteLine(BB1.Min + " - " + BB1.Max);
                Console.WriteLine(BB2.Min + " - " + BB2.Max);
                return true;
            }
            return false;
        }*/
        protected bool isCollidingBB(CObject cobject2)
        {
            BoundingBox BB1, BB2;
            foreach (ModelMesh mesh in model.Meshes)
            {
                BoundingSphere m1BoundingSphere = mesh.BoundingSphere;
                m1BoundingSphere.Center = position;
                m1BoundingSphere.Radius *= this.scale;
                BB1 = BoundingBox.CreateFromSphere(m1BoundingSphere);
                foreach (ModelMesh mesh2 in cobject2.Model.Meshes)
                {
                    BoundingSphere m2BoundingSphere = mesh2.BoundingSphere;
                    m2BoundingSphere.Center = cobject2.position;
                    if (cobject2.ID == "floor" || cobject2.ID.Contains("wall"))
                    {
                        m2BoundingSphere.Radius *= cobject2.scale * 30.0f;
                    }
                    else
                        m2BoundingSphere.Radius *= cobject2.scale;
                    BB2 = BoundingBox.CreateFromSphere(m2BoundingSphere);

                    if (BB1.Intersects(BB2))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
Ejemplo n.º 8
0
 protected BoundingBox CalculateBoundingBox(CObject cobject)
 {
     Vector3 min = new Vector3(cobject.position.X, cobject.position.Y - cobject.specs.Y, cobject.position.Z);
     Vector3 max = new Vector3(cobject.position.X, cobject.position.Y + cobject.specs.Y, cobject.position.Z);
     min.X -= cobject.specs.X;
     min.Z -= cobject.specs.Z;
     max.X += cobject.specs.X;
     max.Z += cobject.specs.Z;
     /*min.X -= (rotation.Y == 0) ? cobject.specs.X : cobject.specs.Z;
     min.Z -= (rotation.Y == 0) ? cobject.specs.Z : cobject.specs.X;
     max.X += (rotation.Y == 0) ? cobject.specs.X : cobject.specs.Z;
     max.Z += (rotation.Y == 0) ? cobject.specs.Z : cobject.specs.X;*/
     return new BoundingBox(min, max);
 }