コード例 #1
0
        public static bool RayCastVoxels(ref Vector3D start, ref Vector3D end, out MyVoxelBase hitVoxel, out Vector3D hitPosition, bool checkPlanet = DefaultCheckPlanet)
        {
#if PROFILE
            Profiler.StartProfileBlock();
            try
            {
#endif
            CapsuleD capsule;
            capsule.P0     = start;
            capsule.P1     = end;
            capsule.Radius = 0f;

            return(CapsuleDExtensions.IntersectsVoxel(ref capsule, out hitVoxel, out hitPosition, checkPlanet));

#if PROFILE
        }

        finally { Profiler.EndProfileBlock(); }
#endif
        }
コード例 #2
0
        /// <summary>
        /// Ray cast all the voxels in the world to check for intersection.
        /// </summary>
        /// <param name="line">The line to check</param>
        ///// <param name="shortTest">Shortens the line by 5 m, needed to interact with an entity that may be on the surface of the voxel.</param>
        /// <returns>True iff any voxel intersects the line</returns>
        public static bool RayCastVoxels(LineD line, out MyVoxelBase hitVoxel, out Vector3D hitPosition, bool checkPlanet = DefaultCheckPlanet)
        {
            //const double ShortenBy = 5d;
#if PROFILE
            Profiler.StartProfileBlock();
            try
            {
#endif
            CapsuleD capsule;
            capsule.P0     = line.From;
            capsule.P1     = line.To;
            capsule.Radius = 0f;
            return(CapsuleDExtensions.IntersectsVoxel(ref capsule, out hitVoxel, out hitPosition, checkPlanet));

#if PROFILE
        }

        finally { Profiler.EndProfileBlock(); }
#endif
        }
コード例 #3
0
        /// <summary>
        /// Find a sphere free from voxel.
        /// </summary>
        /// <param name="voxel">The voxel to avoid.</param>
        /// <param name="startPosition">The position to start the search.</param>
        /// <param name="minRadius">The minimum radius around freePosition.</param>
        /// <param name="freePosition">A position that is minRadius from voxel</param>
        public static void FindFreeSpace(this MyVoxelBase voxel, Vector3D startPosition, double minRadius, out Vector3D freePosition)
        {
            MyPlanet planet = voxel as MyPlanet;

            if (planet != null)
            {
                Vector3D centre = planet.GetCentre();
                Vector3D direction; Vector3D.Subtract(ref startPosition, ref centre, out direction);
                direction.Normalize();

                FindFreeSpace(voxel, startPosition, direction, minRadius, out freePosition);
                return;
            }

            BoundingSphereD testSphere;

            testSphere.Radius = minRadius;

            for (double testDist = minRadius; ; testDist += minRadius)
            {
                foreach (Vector3I neighbour in Globals.Neighbours)
                {
                    Vector3D disp = Vector3D.Multiply(neighbour, testDist);
                    Vector3D.Add(ref startPosition, ref disp, out testSphere.Center);
                    if (!ContainsOrIntersects(voxel, ref testSphere, true))
                    {
                        CapsuleD capsule;
                        capsule.P0 = testSphere.Center;
                        Vector3D disp1 = Vector3D.Multiply(neighbour, testDist * 0.5d);
                        Vector3D.Add(ref startPosition, ref disp1, out capsule.P1);
                        capsule.Radius = (float)minRadius;

                        if (!CapsuleDExtensions.Intersects(ref capsule, voxel, out freePosition))
                        {
                            freePosition = capsule.P1;
                        }
                        return;
                    }
                }
            }
        }