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


C# NetInfo.GetMinNodeDistance方法代码示例

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


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

示例1: SnapDirectionOverride

        public static NetTool.ControlPoint SnapDirectionOverride(NetTool.ControlPoint newPoint,
            NetTool.ControlPoint oldPoint,
            NetInfo info, out bool success, out float minDistanceSq)
        {
            if (Debug.Enabled)
            {
                DebugPrint = string.Format("oldPoint: {0}\nnewPoint:{1}", StringUtil.ToString(oldPoint),
                    StringUtil.ToString(newPoint));
            }

            GuideLines.Clear();
            SnappedGuideLine = null;

            minDistanceSq = info.GetMinNodeDistance();
            minDistanceSq = minDistanceSq*minDistanceSq;
            var controlPoint = newPoint;
            success = false;

            if (EnableSnapping)
            {
                // If dragging from a node
                if (oldPoint.m_node != 0 && !newPoint.m_outside)
                {
                    // Node the road build operation is starting from
                    var sourceNodeId = oldPoint.m_node;
                    var sourceNode = NetManager.instance.m_nodes.m_buffer[sourceNodeId];

                    // Direction and length of the line from the node to the users control point
                    var userLineDirection = (newPoint.m_position - sourceNode.m_position).Flatten();
                    var userLineLength = userLineDirection.magnitude;
                    userLineDirection.Normalize();

                    var closestSegmentId = NetNodeUtility.GetClosestSegmentId(sourceNodeId, userLineDirection);

                    if (closestSegmentId > 0)
                    {
                        // Snap to angle increments originating from this closest segment

                        var closestSegmentDirection = NetNodeUtility.GetSegmentExitDirection(sourceNodeId,
                            closestSegmentId);

                        var currentAngle = Vector3Extensions.Angle(closestSegmentDirection, userLineDirection,
                            Vector3.up);

                        var snappedAngle = Mathf.Round(currentAngle/Settings.SnapAngle)*Settings.SnapAngle;
                        var snappedDirection = Quaternion.AngleAxis(snappedAngle, Vector3.up)*closestSegmentDirection;

                        controlPoint.m_direction = snappedDirection.normalized;
                        controlPoint.m_position = sourceNode.m_position + userLineLength*controlPoint.m_direction;
                        controlPoint.m_position.y = newPoint.m_position.y;

                        minDistanceSq = (newPoint.m_position - controlPoint.m_position).sqrMagnitude;
                        success = true;

                        //minDistanceSq = olpo;
                    }
                }
                else if (oldPoint.m_segment != 0 && !newPoint.m_outside)
                {
                    // Else if dragging from a segment

                    // Segment the road build operation is starting from
                    var sourceSegmentId = oldPoint.m_segment;
                    var sourceSegment = NetManager.instance.m_segments.m_buffer[sourceSegmentId];

                    Vector3 segmentDirection;
                    Vector3 segmentPosition;

                    // Direction and length of the line between control points
                    var userLineDirection = (newPoint.m_position - oldPoint.m_position).Flatten();
                    var userLineLength = userLineDirection.magnitude;
                    userLineDirection.Normalize();

                    // Get direction of the segment at the branch position
                    sourceSegment.GetClosestPositionAndDirection(oldPoint.m_position, out segmentPosition,
                        out segmentDirection);

                    var currentAngle = Vector3Extensions.Angle(segmentDirection, userLineDirection, Vector3.up);

                    segmentDirection = segmentDirection.Flatten().normalized;

                    var snappedAngle = Mathf.Round(currentAngle/Settings.SnapAngle)*Settings.SnapAngle;
                    var snappedDirection = Quaternion.AngleAxis(snappedAngle, Vector3.up)*segmentDirection;

                    controlPoint.m_direction = snappedDirection.normalized;
                    controlPoint.m_position = oldPoint.m_position + userLineLength*controlPoint.m_direction;
                    controlPoint.m_position.y = newPoint.m_position.y;

                    minDistanceSq = (newPoint.m_position - controlPoint.m_position).sqrMagnitude;

                    success = true;
                }
                else if (oldPoint.m_direction.sqrMagnitude > 0.5f)
                {
                    if (newPoint.m_node == 0 && !newPoint.m_outside)
                    {
                        // Let's do some snapping between control point directions

                        var currentAngle = Vector3Extensions.Angle(oldPoint.m_direction, newPoint.m_direction,
                            Vector3.up);
//.........这里部分代码省略.........
开发者ID:droidmonkey,项目名称:PrecisionEngineering,代码行数:101,代码来源:SnapController.cs


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