当前位置: 首页>>代码示例>>C#>>正文


C# Vector3.DistanceSquared方法代码示例

本文整理汇总了C#中System.Vector3.DistanceSquared方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.DistanceSquared方法的具体用法?C# Vector3.DistanceSquared怎么用?C# Vector3.DistanceSquared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Vector3的用法示例。


在下文中一共展示了Vector3.DistanceSquared方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HasLOS

        /// <summary>
        /// Checks of the two positions have a clear line of sight on the given MapId.
        /// </summary>
        /// <param name="mapId">The <see cref="WCell.Constants.World.MapId"/> that corresponds to the desired map.</param>
        /// <param name="pos1">The start position for the LOS check.</param>
        /// <param name="pos2">The end position for the LOS check.</param>
        /// <returns>True if the LOS check was successful.</returns>
        public bool HasLOS(MapId mapId, Vector3 pos1, Vector3 pos2)
        {
            if (pos1.DistanceSquared(pos2) > _maxLOSRadiusSquared)
            {
                log.Warn(
                    "LOS request on points whose distance exceeds the maximum: Point 1: {0}, Point 2: {1}, Max Distance: {2}",
                    pos1, pos2, MaxLOSRadius);
                return false;
            }

            Map map;
            return (((!TryGetMap(mapId, out map)) || (map.HasLOS(pos1, pos2))));
        }
开发者ID:WCell,项目名称:WCell-Terrain,代码行数:20,代码来源:World.cs

示例2: Vector3DistanceSquaredTest

        public void Vector3DistanceSquaredTest()
        {
            var a = new Vector3(3.0f, 4.0f, 2.0f);
            var b = new Vector3(6.0f, 8.0f, 4.0f);

            var expectedResult = 29.0f;

            var r = a.DistanceSquared(b);

            Assert.Equal<float>(expectedResult, r);
        }
开发者ID:richardhallett,项目名称:nml,代码行数:11,代码来源:Vector3Tests.cs

示例3: RayTraceIntersection

        public RayTraceHit RayTraceIntersection(Vector3 startSegment, Vector3 endSegment)
        {
            // Plane intersection

            Vector3? southIntersection = Vector3.IntersectPointForSegmentAndPlane(startSegment, endSegment, this.Maximum, Vector3.XAxis);
            Vector3? northIntersection = Vector3.IntersectPointForSegmentAndPlane(startSegment, endSegment, this.Minimum, Vector3.XAxis);
            Vector3? topIntersection = Vector3.IntersectPointForSegmentAndPlane(startSegment, endSegment, this.Maximum, Vector3.YAxis);
            Vector3? bottomIntersection = Vector3.IntersectPointForSegmentAndPlane(startSegment, endSegment, this.Minimum, Vector3.YAxis);
            Vector3? westIntersection = Vector3.IntersectPointForSegmentAndPlane(startSegment, endSegment, this.Maximum, Vector3.ZAxis);
            Vector3? eastIntersection = Vector3.IntersectPointForSegmentAndPlane(startSegment, endSegment, this.Minimum, Vector3.ZAxis);

            // Check each intersection to be sure it lies within the other axis as well
            if (northIntersection.HasValue && !this.IsVectorWithinYZ(northIntersection.Value))
            {
                northIntersection = null;
            }
            if (southIntersection.HasValue && !this.IsVectorWithinYZ(southIntersection.Value))
            {
                southIntersection = null;
            }
            if (topIntersection.HasValue && !this.IsVectorWithinXZ(topIntersection.Value))
            {
                topIntersection = null;
            }
            if (bottomIntersection.HasValue && !this.IsVectorWithinXZ(bottomIntersection.Value))
            {
                bottomIntersection = null;
            }
            if (westIntersection.HasValue && !this.IsVectorWithinXY(westIntersection.Value))
            {
                westIntersection = null;
            }
            if (eastIntersection.HasValue && !this.IsVectorWithinXY(eastIntersection.Value))
            {
                eastIntersection = null;
            }

            Vector3? rayHitPoint = null;
            BlockFace faceHit = BlockFace.Self;
            if (northIntersection != null)
            {
                rayHitPoint = northIntersection;
                faceHit = BlockFace.North;
            }
            if (southIntersection != null && (rayHitPoint == null || startSegment.DistanceSquared(southIntersection.Value) < startSegment.DistanceSquared(rayHitPoint.Value)))
            {
                rayHitPoint = southIntersection;
                faceHit = BlockFace.South;
            }
            if (topIntersection != null && (rayHitPoint == null || startSegment.DistanceSquared(topIntersection.Value) < startSegment.DistanceSquared(rayHitPoint.Value)))
            {
                rayHitPoint = topIntersection;
                faceHit = BlockFace.Up;
            }
            if (bottomIntersection != null && (rayHitPoint == null || startSegment.DistanceSquared(bottomIntersection.Value) < startSegment.DistanceSquared(rayHitPoint.Value)))
            {
                rayHitPoint = bottomIntersection;
                faceHit = BlockFace.Down;
            }
            if (westIntersection != null && (rayHitPoint == null || startSegment.DistanceSquared(westIntersection.Value) < startSegment.DistanceSquared(rayHitPoint.Value)))
            {
                rayHitPoint = westIntersection;
                faceHit = BlockFace.West;
            }
            if (eastIntersection != null && (rayHitPoint == null || startSegment.DistanceSquared(eastIntersection.Value) < startSegment.DistanceSquared(rayHitPoint.Value)))
            {
                rayHitPoint = eastIntersection;
                faceHit = BlockFace.East;
            }

            if (rayHitPoint != null)
                return new RayTraceHit(rayHitPoint.Value, faceHit);
            else
                return null;
        }
开发者ID:keneo,项目名称:c-raft,代码行数:75,代码来源:BoundingBox.cs

示例4: WillHit

        /// <summary>
        ///     Returns if the spell will hit the point when casted
        /// </summary>
        /// <param name="point">
        ///     Vector3 Target
        /// </param>
        /// <param name="castPosition">
        ///     Cast Position
        /// </param>
        /// <param name="extraWidth">
        ///     Extra Width
        /// </param>
        /// <returns>
        ///     Will Spell Hit
        /// </returns>
        public bool WillHit(Vector3 point, Vector3 castPosition, int extraWidth = 0)
        {
            switch (this.Type)
            {
                case SkillshotType.SkillshotCircle:
                    if (point.DistanceSquared(castPosition) < this.WidthSqr)
                    {
                        return true;
                    }

                    break;

                case SkillshotType.SkillshotLine:
                    if (point.ToVector2().DistanceSquared(castPosition.ToVector2(), this.From.ToVector2(), true)
                        < Math.Pow(this.Width + extraWidth, 2))
                    {
                        return true;
                    }

                    break;
                case SkillshotType.SkillshotCone:
                    var edge1 = (castPosition.ToVector2() - this.From.ToVector2()).Rotated(-this.Width / 2);
                    var edge2 = edge1.Rotated(this.Width);
                    var v = point.ToVector2() - this.From.ToVector2();
                    if (point.DistanceSquared(this.From) < this.RangeSqr && edge1.CrossProduct(v) > 0
                        && v.CrossProduct(edge2) > 0)
                    {
                        return true;
                    }

                    break;
            }

            return false;
        }
开发者ID:ShineSharp,项目名称:LeagueSharp.SDK,代码行数:50,代码来源:Spell.cs


注:本文中的System.Vector3.DistanceSquared方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。