Example #1
0
        /// <summary>
        /// check if two models colliding
        /// </summary>
        /// <param name="modelA">First model</param>
        /// <param name="modelB">Second model</param>
        /// <returns>True if modelA collinding modelB else false</returns>
        public static bool SphereCollide(YnMeshModel modelA, YnMeshModel modelB)
        {
            bool collide = false;
            int  j       = 0;

            int countMeshA = modelA.Model.Meshes.Count;
            int countMeshB = modelB.Model.Meshes.Count;

            for (int i = 0; i < countMeshA; i++)
            {
                BoundingSphere meshABS = modelA.Model.Meshes[i].BoundingSphere;
                meshABS.Center += modelA.Position;

                while (j < countMeshB && !collide)
                {
                    BoundingSphere meshBBS = modelB.Model.Meshes[j].BoundingSphere;
                    meshBBS.Center += modelB.Position;

                    if (meshABS.Intersects(meshBBS))
                    {
                        collide = true;
                    }

                    j++;
                }
            }

            return(collide);
        }
Example #2
0
        /// <summary>
        /// check if two models colliding with there bounding box
        /// </summary>
        /// <param name="modelA">First model</param>
        /// <param name="modelB">Second model</param>
        /// <returns>True if modelA collinding modelB else false</returns>
        public static bool CubeCollide(YnMeshModel modelA, YnMeshModel modelB)
        {
            if (modelA.Dynamic)
            {
                modelA.UpdateBoundingVolumes();
            }

            if (modelB.Dynamic)
            {
                modelB.UpdateBoundingVolumes();
            }

            return(modelA.BoundingBox.Intersects(modelB.BoundingBox));
        }
Example #3
0
        /// <summary>
        /// Test if the model colliding another objects with there bounding box
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="group">A collection of models</param>
        /// <returns>Array of models that collides with model</returns>
        public static YnMeshModel[] CubeCollide(YnMeshModel model, YnGroup3D group)
        {
            List <YnMeshModel> collides = new List <YnMeshModel>();

            int groupSize = group.Count;

            for (int i = 0; i < groupSize; i++)
            {
                if (group[i] is YnMeshModel)
                {
                    if (CubeCollide(model, group[i] as YnMeshModel))
                    {
                        collides.Add(group[i] as YnMeshModel);
                    }
                }
            }

            return(collides.ToArray());
        }
Example #4
0
        /// <summary>
        /// Test if the model colliding another objects with there bounding box
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="group">A collection of models</param>
        /// <returns>Array of models that collides with model</returns>
        public static YnMeshModel[] CubeCollide(YnMeshModel model, YnGroup3D group)
        {
            List<YnMeshModel> collides = new List<YnMeshModel>();

            int groupSize = group.Count;

            for (int i = 0; i < groupSize; i++)
            {
                if (group[i] is YnMeshModel)
                {
                    if (CubeCollide(model, group[i] as YnMeshModel))
                        collides.Add(group[i] as YnMeshModel);
                }
            }

            return collides.ToArray();
        }
Example #5
0
        /// <summary>
        /// check if two models colliding with there bounding box
        /// </summary>
        /// <param name="modelA">First model</param>
        /// <param name="modelB">Second model</param>
        /// <returns>True if modelA collinding modelB else false</returns>
        public static bool CubeCollide(YnMeshModel modelA, YnMeshModel modelB)
        {
            if (modelA.Dynamic)
                modelA.UpdateBoundingVolumes();

            if (modelB.Dynamic)
                modelB.UpdateBoundingVolumes();

            return modelA.BoundingBox.Intersects(modelB.BoundingBox);
        }
Example #6
0
        /// <summary>
        /// check if two models colliding
        /// </summary>
        /// <param name="modelA">First model</param>
        /// <param name="modelB">Second model</param>
        /// <returns>True if modelA collinding modelB else false</returns>
        public static bool SphereCollide(YnMeshModel modelA, YnMeshModel modelB)
        {
            bool collide = false;
            int j = 0;

            int countMeshA = modelA.Model.Meshes.Count;
            int countMeshB = modelB.Model.Meshes.Count;

            for (int i = 0; i < countMeshA; i++)
            {
                BoundingSphere meshABS = modelA.Model.Meshes[i].BoundingSphere;
                meshABS.Center += modelA.Position;

                while (j < countMeshB && !collide)
                {
                    BoundingSphere meshBBS = modelB.Model.Meshes[j].BoundingSphere;
                    meshBBS.Center += modelB.Position;

                    if (meshABS.Intersects(meshBBS))
                        collide = true;

                    j++;
                }
            }

            return collide;
        }