IrrlichtNETCP.Quaternion.toEuler C# (CSharp) Method

toEuler() public method

Returns an Euler Angles vector. Angles in radiants
public toEuler ( IrrlichtNETCP.Vector3D &euler ) : IrrlichtNETCP.Vector3D
euler IrrlichtNETCP.Vector3D vector to put the result into
return IrrlichtNETCP.Vector3D
        public Vector3D toEuler(out Vector3D euler)
        {
            double sqw = m_w * m_w;
            double sqx = m_x * m_x;
            double sqy = m_y * m_y;
            double sqz = m_z * m_z;

            // heading = rotation about z-axis
            euler.Z = (float)(Math.Atan2(2.0 * (m_x * m_y + m_z * m_w), (sqx - sqy - sqz + sqw)));

            // bank = rotation about x-axis
            euler.X = (float)(Math.Atan2(2.0 * (m_y * m_z + m_x * m_w), (-sqx - sqy + sqz + sqw)));

            // attitude = rotation about y-axis
            euler.Y = (float)(Math.Asin(-2.0 * (m_x * m_z - m_y * m_w)));
            return euler;
        }

Usage Example

        public void UpdateDirection()
        {
            DateTime now = Reference.Viewer.WorldTime;
            TimeSpan span = new DateTime(2009, 1, 1, now.Hour, now.Minute, now.Second) - DateTime.Parse("2009-01-01 07:00:00");
            int sec = span.Hours * 3600 + span.Minutes * 60 + span.Seconds;
            int end = 10 * 3600 + 0 * 60 + 0;
            float amount = (float)sec / end;
            amount = Util.Clamp<float>(amount, 0, 1);
            angle = OpenViewer.Util.Lerp(sunriseAngle, sunsetAngle, amount);

            qx.fromAngleAxis((float)(Math.PI / 1.25f), new Vector3D(1, 0, 0));
            qy.fromAngleAxis(angle, new Vector3D(0, 1, 0));
            qy = qx * qy;
            Vector3D rot;
            qy.toEuler(out rot);
            rotation = new Vector3D(rot.X, rot.Y, rot.Z) * OpenMetaverse.Utils.RAD_TO_DEG;
        }