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); }
/*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); }
/*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; foreach (ModelMesh mesh in model.Meshes) { BB1 = BoundingBox.CreateFromSphere(mesh.BoundingSphere); foreach (ModelMesh mesh2 in model2.Meshes) { BB2 = BoundingBox.CreateFromSphere(mesh2.BoundingSphere); if (BB1.Intersects(BB2)) { return(true); } } } return(false); }