本文整理汇总了C#中System.Numerics.Vector3.LengthSquared方法的典型用法代码示例。如果您正苦于以下问题:C# System.Numerics.Vector3.LengthSquared方法的具体用法?C# System.Numerics.Vector3.LengthSquared怎么用?C# System.Numerics.Vector3.LengthSquared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.Vector3
的用法示例。
在下文中一共展示了System.Numerics.Vector3.LengthSquared方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNewSimplexPoint
///<summary>
/// Adds a new point to the simplex.
///</summary>
///<param name="shapeA">First shape in the pair.</param>
///<param name="shapeB">Second shape in the pair.</param>
///<param name="iterationCount">Current iteration count.</param>
///<param name="closestPoint">Current point on simplex closest to origin.</param>
///<returns>Whether or not GJK should exit due to a lack of progression.</returns>
public bool GetNewSimplexPoint(ConvexShape shapeA, ConvexShape shapeB, int iterationCount, ref System.Numerics.Vector3 closestPoint)
{
System.Numerics.Vector3 negativeDirection;
Vector3Ex.Negate(ref closestPoint, out negativeDirection);
System.Numerics.Vector3 sa, sb;
shapeA.GetLocalExtremePointWithoutMargin(ref negativeDirection, out sa);
shapeB.GetExtremePointWithoutMargin(closestPoint, ref LocalTransformB, out sb);
System.Numerics.Vector3 S;
Vector3Ex.Subtract(ref sa, ref sb, out S);
//If S is not further towards the origin along negativeDirection than closestPoint, then we're done.
float dotS;
Vector3Ex.Dot(ref S, ref negativeDirection, out dotS); //-P * S
float distanceToClosest = closestPoint.LengthSquared();
float progression = dotS + distanceToClosest;
//It's likely that the system is oscillating between two or more states, usually because of a degenerate simplex.
//Rather than detect specific problem cases, this approach just lets it run and catches whatever falls through.
//During oscillation, one of the states is usually just BARELY outside of the numerical tolerance.
//After a bunch of iterations, the system lets it pick the 'better' one.
if (iterationCount > GJKToolbox.HighGJKIterations && distanceToClosest - previousDistanceToClosest < DistanceConvergenceEpsilon * errorTolerance)
return true;
if (distanceToClosest < previousDistanceToClosest)
previousDistanceToClosest = distanceToClosest;
//If "A" is the new point always, then the switch statement can be removed
//in favor of just pushing three points up.
switch (State)
{
case SimplexState.Point:
if (progression <= (errorTolerance = MathHelper.Max(A.LengthSquared(), S.LengthSquared())) * ProgressionEpsilon)
return true;
State = SimplexState.Segment;
B = S;
SimplexA.B = sa;
SimplexB.B = sb;
return false;
case SimplexState.Segment:
if (progression <= (errorTolerance = MathHelper.Max(MathHelper.Max(A.LengthSquared(), B.LengthSquared()), S.LengthSquared())) * ProgressionEpsilon)
return true;
State = SimplexState.Triangle;
C = S;
SimplexA.C = sa;
SimplexB.C = sb;
return false;
case SimplexState.Triangle:
if (progression <= (errorTolerance = MathHelper.Max(MathHelper.Max(A.LengthSquared(), B.LengthSquared()), MathHelper.Max(C.LengthSquared(), S.LengthSquared()))) * ProgressionEpsilon)
return true;
State = SimplexState.Tetrahedron;
D = S;
SimplexA.D = sa;
SimplexB.D = sb;
return false;
}
return false;
}
示例2: UpdateRestrictedAxes
private void UpdateRestrictedAxes()
{
localConstrainedAxis1 = System.Numerics.Vector3.Cross(Vector3Ex.Up, localAxisA);
if (localConstrainedAxis1.LengthSquared() < .001f)
{
localConstrainedAxis1 = System.Numerics.Vector3.Cross(Vector3Ex.Right, localAxisA);
}
localConstrainedAxis2 = System.Numerics.Vector3.Cross(localAxisA, localConstrainedAxis1);
localConstrainedAxis1.Normalize();
localConstrainedAxis2.Normalize();
}
示例3: SolveIteration
/// <summary>
/// Computes one iteration of the constraint to meet the solver updateable's goal.
/// </summary>
/// <returns>The rough applied impulse magnitude.</returns>
public override float SolveIteration()
{
//Compute relative velocity
System.Numerics.Vector3 lambda;
Vector3Ex.Cross(ref r, ref entity.angularVelocity, out lambda);
Vector3Ex.Subtract(ref lambda, ref entity.linearVelocity, out lambda);
//Add in bias velocity
Vector3Ex.Add(ref biasVelocity, ref lambda, out lambda);
//Add in softness
System.Numerics.Vector3 softnessVelocity;
Vector3Ex.Multiply(ref accumulatedImpulse, usedSoftness, out softnessVelocity);
Vector3Ex.Subtract(ref lambda, ref softnessVelocity, out lambda);
//In terms of an impulse (an instantaneous change in momentum), what is it?
Matrix3x3.Transform(ref lambda, ref effectiveMassMatrix, out lambda);
//Sum the impulse.
System.Numerics.Vector3 previousAccumulatedImpulse = accumulatedImpulse;
accumulatedImpulse += lambda;
//If the impulse it takes to get to the goal is too high for the motor to handle, scale it back.
float sumImpulseLengthSquared = accumulatedImpulse.LengthSquared();
if (sumImpulseLengthSquared > maxForceDtSquared)
{
//max / impulse gives some value 0 < x < 1. Basically, normalize the vector (divide by the length) and scale by the maximum.
accumulatedImpulse *= maxForceDt / (float)Math.Sqrt(sumImpulseLengthSquared);
//Since the limit was exceeded by this corrective impulse, limit it so that the accumulated impulse remains constrained.
lambda = accumulatedImpulse - previousAccumulatedImpulse;
}
entity.ApplyLinearImpulse(ref lambda);
System.Numerics.Vector3 taImpulse;
Vector3Ex.Cross(ref r, ref lambda, out taImpulse);
entity.ApplyAngularImpulse(ref taImpulse);
return (Math.Abs(lambda.X) + Math.Abs(lambda.Y) + Math.Abs(lambda.Z));
}