コード例 #1
0
ファイル: AdvancedMath.cs プロジェクト: LordGurr/PhysicsSim
        public static Vector2 Normalize(Vector2 vector)
        {
            float mag = AdvancedMath.Magnitude(vector);
            //these intermediate variables force the intermediate result to be
            //of float precision. without this, the intermediate result can be of higher
            //precision, which changes behavior.
            float normalized_x = vector.X / mag;
            float normalized_y = vector.Y / mag;

            return(new Vector2(normalized_x, normalized_y));
        }
コード例 #2
0
ファイル: AdvancedMath.cs プロジェクト: LordGurr/PhysicsSim
        //public double ConvertToRadians(double angle) //Stulen från unity
        //{
        //    return (Math.PI / 180) * angle;
        //}

        public static Vector2 ClampMagnitude(Vector2 vector, float maxLength)//Stulen från unity
        {
            float sqrMagnitude = AdvancedMath.sqrMagnitude(vector);

            if (sqrMagnitude > maxLength * maxLength)
            {
                float mag = (float)Math.Sqrt(sqrMagnitude);
                //these intermediate variables force the intermediate result to be
                //of float precision. without this, the intermediate result can be of higher
                //precision, which changes behavior.
                float normalized_x = vector.X / mag;
                float normalized_y = vector.Y / mag;
                return(new Vector2(normalized_x * maxLength,
                                   normalized_y * maxLength));
            }
            return(vector);
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: LordGurr/PhysicsSim
 public float Distance(Vector2Int b)
 {
     return(AdvancedMath.Vector2Distance(new Vector2(X, Y), new Vector2(b.X, b.Y)));
 }