예제 #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);
        }
예제 #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));
        }
예제 #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());
        }
예제 #4
0
파일: YnG3.cs 프로젝트: shaoleibo/YnaEngine
        /// <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();
        }
예제 #5
0
파일: YnG3.cs 프로젝트: shaoleibo/YnaEngine
        /// <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);
        }
예제 #6
0
파일: YnG3.cs 프로젝트: shaoleibo/YnaEngine
        /// <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;
        }