public void NormalizeTest()
        {
            Vector2D v1 = new Vector2D(100, 200);

            var normalizedVector = v1.Normalize();
            Assert.AreEqual(0.447, Math.Round(normalizedVector.x * 1000) / 1000);
            Assert.AreEqual(0.894, Math.Round(normalizedVector.y * 1000) / 1000);
        }
Esempio n. 2
0
        public Vector2D Calculate()
        {
            float rand = (Convert.ToSingle(new Random().Next(-10, 10)) / 10f);
            Vector2D velocity = movingEntity.GetVelocity();

            circleCenter = new Vector2D(velocity.x, velocity.y);
            circleCenter.Normalize();
            circleCenter *= circleDistance;

            displacement = new Vector2D(0, -1);
            displacement *= circleRadius;

            displacement = SetAngle(displacement, displacementAngle);

            displacementAngle += rand * circleAngleChange - circleAngleChange * .5f;
            wanderForce = circleCenter + displacement;
            return wanderForce;
        }