public List<GameModel> detectCollisions(GameModel gameModel) { List<GameModel> results = new List<GameModel>(); List<GameModel> nearbyModels = getNearbyGameModels(gameModel); ////create modelmeshes //gameModel.BoundingSphere = new BoundingSphere(gameModel.Position, gameModel.Model.Meshes[0].BoundingSphere.Radius * gameModel.Scale); //foreach (GameModel gm in nearbyModels) //{ // gm.BoundingSphere = new BoundingSphere(gm.Position, gm.Model.Meshes[0].BoundingSphere.Radius * gm.Scale); //} //create modelmeshes gameModel.getBoundingSphere(); foreach (GameModel gm in nearbyModels) { gm.getBoundingSphere(); } //detect collisions foreach (GameModel gm in nearbyModels) { if (gm.BoundingSphere.Intersects(gameModel.BoundingSphere)) { results.Add(gm); } } return results; }
public List<GameModel> getNearbyGameModels(GameModel gameModel) { List<GameModel> results = new List<GameModel>(); if ((gameModel.SpatialIndexPosition.X < noRows) && (gameModel.SpatialIndexPosition.X < noColumns)) { results = new List<GameModel>(Grid[(int)gameModel.SpatialIndexPosition.X, (int)gameModel.SpatialIndexPosition.Y]); results.Remove(gameModel); } return results; }