Microsoft.Xna.Framework.Vector2.Normalize C# (CSharp) Method

Normalize() public static method

Creates a unit vector from the specified vector. The result is a vector one unit in length pointing in the same direction as the original vector.
public static Normalize ( Vector2 value ) : Vector2
value Vector2 Source Vector2.
return Vector2
        public static Vector2 Normalize(Vector2 value)
        {
            float num = value.X * value.X + value.Y * value.Y;
            float num2 = 1f / (float)Math.Sqrt((double)num);
            Vector2 result;
            result.X = value.X * num2;
            result.Y = value.Y * num2;
            return result;
        }
        /// <summary>Creates a unit vector from the specified vector, writing the result to a user-specified variable. The result is a vector one unit in length pointing in the same direction as the original vector.</summary>

Same methods

Vector2::Normalize ( ) : void
Vector2::Normalize ( Vector2 &value, Vector2 &result ) : void

Usage Example

コード例 #1
1
 public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
 {
     Vector2 direction = new Vector2(speedX, speedY);
     direction.Normalize();
     position += direction * item.width;
     return true;
 }
All Usage Examples Of Microsoft.Xna.Framework.Vector2::Normalize