本文整理汇总了C#中Vector3.Flatten方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Flatten方法的具体用法?C# Vector3.Flatten怎么用?C# Vector3.Flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3
的用法示例。
在下文中一共展示了Vector3.Flatten方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateAngles
public static void CalculateAngles(ushort nodeId, Vector3 direction, ICollection<Measurement> measurements)
{
direction = direction.Flatten();
var node = NetManager.instance.m_nodes.m_buffer[nodeId];
var existingSegments = NetNodeUtility.GetNodeSegmentIds(node);
if (existingSegments.Count == 0)
{
return;
}
var nearestLeftAngle = 360f;
ushort nearestLeftSegmentId = 0;
var nearestLeftNormal = Vector3.zero;
var nearestRightAngle = 360f;
ushort nearestRightSegmentId = 0;
var nearestRightNormal = Vector3.zero;
for (var i = 0; i < existingSegments.Count; i++)
{
var s = NetManager.instance.m_segments.m_buffer[existingSegments[i]];
var d = s.m_startNode == nodeId ? s.m_startDirection : s.m_endDirection;
d = d.Flatten();
var angle = Vector3Extensions.GetClockwiseAngleBetween(-d, direction, Vector3.up);
var leftAngle = 360f - angle;
var rightAngle = angle;
var n = Vector3.Normalize(direction + d);
if (leftAngle < nearestLeftAngle)
{
nearestLeftAngle = leftAngle;
nearestLeftSegmentId = existingSegments[i];
nearestLeftNormal = Quaternion.AngleAxis(leftAngle*0.5f, Vector3.up)*direction;
}
if (rightAngle < nearestRightAngle)
{
nearestRightAngle = rightAngle;
nearestRightSegmentId = existingSegments[i];
nearestRightNormal = Quaternion.AngleAxis(rightAngle*-0.5f, Vector3.up)*direction;
}
}
// When both angles are 180, only show the one on the right.
if (Math.Abs(nearestLeftAngle - 180f) < 0.25f && Math.Abs(nearestRightAngle - 180f) < 0.25f)
{
measurements.Add(new AngleMeasurement(nearestRightAngle, node.m_position, nearestRightNormal,
MeasurementFlags.Primary));
return;
}
var leftFlags = nearestRightSegmentId > 0
? (nearestLeftAngle < nearestRightAngle ? MeasurementFlags.Primary : MeasurementFlags.Secondary)
: MeasurementFlags.Secondary;
var rightFlags = nearestLeftSegmentId > 0
? (nearestRightAngle <= nearestLeftAngle ? MeasurementFlags.Primary : MeasurementFlags.Secondary)
: MeasurementFlags.Secondary;
if (nearestLeftSegmentId > 0)
{
measurements.Add(new AngleMeasurement(nearestLeftAngle, node.m_position, nearestLeftNormal, leftFlags));
}
if (nearestRightSegmentId > 0)
{
measurements.Add(new AngleMeasurement(nearestRightAngle, node.m_position, nearestRightNormal, rightFlags));
}
}
示例2: CanNodeBranchInDirection
private static bool CanNodeBranchInDirection(ushort nodeId, Vector3 direction)
{
var closestSegmentId = NetNodeUtility.GetClosestSegmentId(nodeId, direction);
var exitDirection = NetNodeUtility.GetSegmentExitDirection(nodeId, closestSegmentId);
var exitAngle = Vector3Extensions.GetSignedAngleBetween(direction.Flatten(), exitDirection.Flatten(), Vector3.up);
return Mathf.Abs(exitAngle) >= 45f;
}
示例3: TestLine
private static void TestLine(NetInfo netInfo, Vector3 startPoint, Vector3 endPoint, Vector3 l1, Vector3 l2,
IList<GuideLine> lines, ushort segmentId = 0, ushort nodeId = 0)
{
var p = Util.LineIntersectionPoint(startPoint.xz(), endPoint.xz(), l1.xz(), l2.xz());
// Lines never meet, discard
if (!p.HasValue)
return;
var intersect = new Vector3(p.Value.x, 0, p.Value.y);
var intersectDistanceSqr = Vector3Extensions.DistanceSquared(intersect, endPoint.Flatten());
// Discard if intersect is silly distance away
if (intersectDistanceSqr > Settings.MaxGuideLineQueryDistanceSqr)
return;
var guideDirection = l1.Flatten().DirectionTo(l2.Flatten());
var intersectDirection = l1.Flatten().DirectionTo(intersect);
// Ignore guides in the wrong direction
if (Mathf.Abs(Vector3Extensions.GetSignedAngleBetween(guideDirection, intersectDirection, Vector3.up)) > 90f)
return;
intersect.y = TerrainManager.instance.SampleRawHeightSmooth(intersect);
var intersectDistance = Mathf.Sqrt(intersectDistanceSqr);
var line = new GuideLine(l1, intersect, netInfo.m_halfWidth*2f, intersectDistance, segmentId);
int index;
if (IsDuplicate(lines, line, out index)) {
var d = lines[index];
// If a duplicate, check if it is closer than the duplicate
if (Vector3Extensions.DistanceSquared(d.Origin, endPoint) > Vector3Extensions.DistanceSquared(l1, endPoint)) {
lines[index] = line;
}
return;
}
// Check for intersection with existing nodes
var ra = Vector3.Cross(guideDirection, Vector3.up);
var quad = new Quad3(l1 + ra, l1 - ra, intersect + ra, intersect - ra);
if (NetManager.instance.OverlapQuad(Quad2.XZ(quad), 0, 1280f, netInfo.m_class.m_layer, nodeId, 0, segmentId)) {
return;
}
lines.Add(line);
}
示例4: CalculateAngles
static void CalculateAngles(Vector3 anglePosition, Vector3 guideDirection, Vector3 incomingDirection, ICollection<Measurement> measurements)
{
guideDirection = guideDirection.Flatten().normalized;
incomingDirection = incomingDirection.Flatten().normalized;
var angleSize = Vector3.Angle(guideDirection, incomingDirection);
var angleDirection = Vector3.Normalize(guideDirection + incomingDirection);
var otherAngleSize = 180f - angleSize;
var otherAngleDirection = Vector3.Normalize(-guideDirection + incomingDirection);
if (otherAngleSize < angleSize) {
Util.Swap(ref angleSize, ref otherAngleSize);
Util.Swap(ref angleDirection, ref otherAngleDirection);
}
measurements.Add(new AngleMeasurement(angleSize, anglePosition, angleDirection,
MeasurementFlags.Primary | MeasurementFlags.Guide));
if (Mathf.Abs(angleSize - 180f) < 0.5f || Mathf.Abs(otherAngleSize - 180f) < 0.5f)
return;
measurements.Add(new AngleMeasurement(otherAngleSize, anglePosition, otherAngleDirection,
MeasurementFlags.Secondary | MeasurementFlags.Guide));
}