示例#1
0
        /// <summary>
        /// Sphere test for simple entities, like floating objects, and for avoiding dangerous ships tools.
        /// </summary>
        /// <param name="entity">The entity to test.</param>
        /// <param name="input"><see cref="TestInput"/></param>
        /// <param name="result"><see cref="GridTestResult"/></param>
        /// <returns>True if the entity is obstructing the ship.</returns>
        private bool SphereTest(MyEntity entity, ref TestInput input, ref GridTestResult result)
        {
            Vector3D currentPosition = AutopilotGrid.GetCentre();
            Vector3D rejectD         = input.Direction;
            Vector3D disp; Vector3D.Multiply(ref rejectD, input.Length, out disp);
            Vector3D finalPosition; Vector3D.Add(ref currentPosition, ref disp, out finalPosition);
            float    shipRadius = AutopilotGrid.PositionComp.LocalVolume.Radius;

            Vector3D obsPos = entity.GetCentre();
            Vector3D offObsPos; Vector3D.Subtract(ref obsPos, ref input.Offset, out offObsPos);
            float    obsRadius = entity.PositionComp.LocalVolume.Radius;

            if (entity is MyCubeBlock)
            {
                // it is an active tool so increase the radius
                obsRadius += 10f;
            }

            m_lineSegment.From = currentPosition;
            m_lineSegment.To   = finalPosition;
            Vector3D closest;

            result.Distance = (float)m_lineSegment.ClosestPoint(ref offObsPos, out closest);
            double distance; Vector3D.Distance(ref offObsPos, ref closest, out distance);

            result.Proximity = (float)distance - (shipRadius + obsRadius);

            if (result.Proximity <= 0f && IsRejectionTowards(ref obsPos, ref currentPosition, ref rejectD))
            {
                Logger.DebugLog("Rejection " + input.Direction + " hit " + entity.nameWithId());
                result.ObstructingBlock = entity as MyCubeBlock;                 // it may not be a block
                return(true);
            }
            return(false);
        }
示例#2
0
 public Vector3D GetCentre()
 {
     return(MatchPosition ? Entity.GetCentre() : Vector3D.Zero);
 }