Exemple #1
0
 /// <summary> Normalize a set of (euler) angles to fall within a -180... 180 range. </summary>
 /// <param name="angles"></param>
 /// <returns></returns>
 public static Vector3 NormalizeAngles(Vector3 angles)
 {
     return(new Vector3
            (
                SG_Util.NormalizeAngle(angles.x),
                SG_Util.NormalizeAngle(angles.y),
                SG_Util.NormalizeAngle(angles.z)
            ));
 }
Exemple #2
0
        //-------------------------------------------------------------------------------------------------------------------------
        // Velocities / Transforms

        #region Transforms

        /// <summary> Calculate the angular velocity of a GameObject, using its current rotation and that of the previous frame. </summary>
        /// <param name="currentRot"></param>
        /// <param name="previousRot"></param>
        /// <remarks>Placed here because it may be used by other scripts as well.</remarks>
        /// <returns></returns>
        public static Vector3 CalculateAngularVelocity(Quaternion currentRot, Quaternion previousRot, float deltaTime)
        {
            Quaternion dQ  = currentRot * Quaternion.Inverse(previousRot);
            Vector3    dE  = dQ.eulerAngles;
            Vector3    res = new Vector3
                             (
                SG_Util.NormalizeAngle(dE.x),
                SG_Util.NormalizeAngle(dE.y),
                SG_Util.NormalizeAngle(dE.z)
                             );

            return((res * Mathf.Deg2Rad) / deltaTime); //convert from deg to rad / sec
        }