Sqr() private méthode

private Sqr ( float x ) : float
x float
Résultat float
Exemple #1
0
        private Vector2 Trace(Agent.VOBuffer vos, Vector2 p, out float score)
        {
            float   num    = Mathf.Max(this.radius, 0.2f * this.desiredSpeed);
            float   num2   = float.PositiveInfinity;
            Vector2 result = p;

            for (int i = 0; i < 50; i++)
            {
                float num3 = 1f - (float)i / 50f;
                num3 = Agent.Sqr(num3) * num;
                float   num4;
                Vector2 vector = this.EvaluateGradient(vos, p, out num4);
                if (num4 < num2)
                {
                    num2   = num4;
                    result = p;
                }
                vector.Normalize();
                vector *= num3;
                Vector2 a = p;
                p += vector;
                if (this.DebugDraw)
                {
                    Debug.DrawLine(Agent.FromXZ(a + this.position), Agent.FromXZ(p + this.position), Agent.Rainbow((float)i * 0.1f) * new Color(1f, 1f, 1f, 1f));
                }
            }
            score = num2;
            return(result);
        }
Exemple #2
0
 public VO(Vector2 center, Vector2 offset, float radius, float inverseDt, float inverseDeltaTime)
 {
     this.weightFactor = 1f;
     this.weightBonus  = 0f;
     this.circleCenter = center * inverseDt + offset;
     this.weightFactor = 4f * Mathf.Exp(-Agent.Sqr(center.sqrMagnitude / (radius * radius))) + 1f;
     if (center.magnitude < radius)
     {
         this.colliding = true;
         this.line1     = center.normalized * (center.magnitude - radius - 0.001f) * 0.3f * inverseDeltaTime;
         Vector2 vector = new Vector2(this.line1.y, -this.line1.x);
         this.dir1       = vector.normalized;
         this.line1     += offset;
         this.cutoffDir  = Vector2.zero;
         this.cutoffLine = Vector2.zero;
         this.dir2       = Vector2.zero;
         this.line2      = Vector2.zero;
         this.radius     = 0f;
     }
     else
     {
         this.colliding = false;
         center        *= inverseDt;
         radius        *= inverseDt;
         Vector2 b = center + offset;
         float   d = center.magnitude - radius + 0.001f;
         this.cutoffLine = center.normalized * d;
         Vector2 vector2 = new Vector2(-this.cutoffLine.y, this.cutoffLine.x);
         this.cutoffDir   = vector2.normalized;
         this.cutoffLine += offset;
         float num  = Mathf.Atan2(-center.y, -center.x);
         float num2 = Mathf.Abs(Mathf.Acos(radius / center.magnitude));
         this.radius = radius;
         this.line1  = new Vector2(Mathf.Cos(num + num2), Mathf.Sin(num + num2));
         this.dir1   = new Vector2(this.line1.y, -this.line1.x);
         this.line2  = new Vector2(Mathf.Cos(num - num2), Mathf.Sin(num - num2));
         this.dir2   = new Vector2(this.line2.y, -this.line2.x);
         this.line1  = this.line1 * radius + b;
         this.line2  = this.line2 * radius + b;
     }
     this.segmentStart = Vector2.zero;
     this.segmentEnd   = Vector2.zero;
     this.segment      = false;
 }