/// <summary>
        ///  Check if sphere collide with triangles
        /// </summary>
        /// <param name="vertices">List of triangles vertices</param>
        /// <param name="boundingSphere">Sphere</param>
        /// <param name="triangle">Return which triangle collide with the sphere</param>
        /// <param name="light">Use light or full detection</param>
        /// <returns>If sphere collide with triangle</returns>
        public static bool IsSphereCollideWithTringles(List <Vector3> vertices,
                                                       BoundingSphere boundingSphere, out Triangle triangle, bool light)
        {
            bool res = false;

            triangle = null;

            for (int i = 0; i < vertices.Count; i += 3)
            {
                // Create triangle from the tree vertices
                Triangle t = new Triangle(vertices[i], vertices[i + 1], vertices[i + 2]);

                // Check if the sphere collide with the triangle
                if (light)
                {
                    res = TriangleSphereCollisionDetection.LightSphereTriangleCollision(ref boundingSphere, ref t);
                }
                else
                {
                    res = TriangleSphereCollisionDetection.SphereTriangleCollision(ref boundingSphere, ref t);
                }

                if (res)
                {
                    triangle = t;
                    return(res);
                }
            }
            return(res);
        }
        /// <summary>
        /// Check if sphere collide with triangles
        /// </summary>
        /// <param name="vertices">List of triangles vertices</param>
        /// <param name="boundingSphere">Sphere</param>
        /// <param name="triangles">Return which triangles collide with the sphere</param>
        /// /// <param name="light">Use light or full detection</param>
        /// <returns>If sphere collide with triangle</returns>
        public static bool IsSphereCollideWithTringles(List <Vector3> vertices,
                                                       BoundingSphere boundingSphere, out IEnumerable <Triangle> triangles, bool light)
        {
            bool            res     = false;
            List <Triangle> resualt = new List <Triangle>();

            for (int i = 0; i < vertices.Count; i += 3)
            {
                // Create triangle from the tree vertices
                Triangle t = new Triangle(vertices[i], vertices[i + 1], vertices[i + 2]);

                // Check if the shpere collide with the triangle
                bool tmp;
                if (light)
                {
                    tmp = TriangleSphereCollisionDetection.LightSphereTriangleCollision(ref boundingSphere, ref t);
                }
                else
                {
                    tmp = TriangleSphereCollisionDetection.SphereTriangleCollision(ref boundingSphere, ref t);
                }

                if (tmp)
                {
                    resualt.Add(t);
                    res = true;
                }
            }
            triangles = resualt;
            return(res);
        }
Exemple #3
0
 /// <summary>
 /// Calculate which part of the maze a bounding sphere collides with.
 /// </summary>
 /// <param name="BoundingSphere">The bounding sphere to use for the collision
 /// check.</param>
 /// <param name="intersectDetails">Will hold the result of the collision
 /// check.</param>
 /// <param name="light">Use light or full detection.</param>
 public void GetCollisionDetails(BoundingSphere BoundingSphere, ref IntersectDetails intersectDetails,
                                 bool light)
 {
     intersectDetails.IntersectWithGround =
         TriangleSphereCollisionDetection.IsSphereCollideWithTringles(Ground,
                                                                      BoundingSphere, out intersectDetails.IntersectedGroundTriangle, true);
     intersectDetails.IntersectWithWalls =
         TriangleSphereCollisionDetection.IsSphereCollideWithTringles(Walls,
                                                                      BoundingSphere, out intersectDetails.IntersectedWallTriangle, light);
     intersectDetails.IntersectWithFloorSides =
         TriangleSphereCollisionDetection.IsSphereCollideWithTringles(FloorSides,
                                                                      BoundingSphere, out intersectDetails.IntersectedFloorSidesTriangle, true);
 }