IrrlichtNETCP.Quaternion.Normalize C# (CSharp) Method

Normalize() public method

public Normalize ( ) : Quaternion
return Quaternion
        public Quaternion Normalize()
        {
            float n = m_x * m_x + m_y * m_y + m_z * m_z + m_w * m_w;

            if (n == 1)
                return this;

            n = 1.0f / (float)Math.Sqrt(n);
            m_x *= n;
            m_y *= n;
            m_z *= n;
            m_w *= n;

            return this;
        }

Usage Example

Example #1
0
        //! sets new Quaternion based on euler angles
        public static Quaternion FromEulerAngles(float x, float y, float z)
        {
            Quaternion t_tmp = new Quaternion();
            //TODO Duplicated code (Method Set(x,y,z))
            double angle;

            angle = x * 0.5;
            double sr = (float)Math.Sin(angle);
            double cr = (float)Math.Cos(angle);

            angle = y * 0.5;
            double sp = (float)Math.Sin(angle);
            double cp = (float)Math.Cos(angle);

            angle = z * 0.5;
            double sy = (float)Math.Sin(angle);
            double cy = (float)Math.Cos(angle);

            double cpcy = cp * cy;
            double spcy = sp * cy;
            double cpsy = cp * sy;
            double spsy = sp * sy;

            t_tmp.X = (float)(sr * cpcy - cr * spsy);
            t_tmp.Y = (float)(cr * spcy + sr * cpsy);
            t_tmp.Z = (float)(cr * cpsy - sr * spcy);
            t_tmp.W = (float)(cr * cpcy + sr * spsy);

            t_tmp.Normalize();
            return t_tmp;
        }