Exemplo n.º 1
0
        public static FixVec3 ClampMagnitude(FixVec3 vector, Fix maxLength)
        {
            if (vector.GetSqrMagnitude() > maxLength * maxLength)
            {
                return(vector.Normalize() * maxLength);
            }

            return(vector);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Build a quaternion from the given axis and angle
        /// </summary>
        /// <param name="axis">The axis to rotate about</param>
        /// <param name="angle">The rotation angle in radians</param>
        /// <returns></returns>
        public static FixQuaternion FromAxisAngle(FixVec3 axis, Fix angle)
        {
            if (axis.GetSqrMagnitude() == Fix.Zero)
            {
                return(Identity);
            }

            FixQuaternion result = Identity;

            angle *= Fix.One / 2;
            axis.Normalize();
            result.Xyz = axis * FixMath.Sin(angle);
            result.W   = FixMath.Cos(angle);

            return(Normalize(result));
        }