Trying to recover function code:

QAngles = vecDir.ToEulerAngles ( &vecUp ); 

https://developer.valvesoftware.com/wiki/QAngle vecDir and vecUp vectors.

vecUp can be 0

 QAngles = vecDir.ToEulerAngles ( ); 

Can you tell me?

I found it on the Internet, but I don't know where to get w or r .

 void Quaternion::ToEulerAngles(Vector3D & v) const { float sqw = w * w; float sqx = x * x; float sqy = y * y; float sqz = z * z; float unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor float test = x * y + z * w; if (test > 0.499f * unit) // singularity at north pole { vy = 2.0f * atan2f(x, w); vz = FLOAT_PI / 2.0f; vx = 0.0f; return; } if (test < -0.499f * unit) // singularity at south pole { vy = -2.0f * atan2f(x, w); vz = -FLOAT_PI / 2.0f; vx = 0; return; } vy = atan2f(2.0f * y * w - 2.0f * x * z, sqx - sqy - sqz + sqw); vz = asinf(2.0f * test / unit); vx = atan2f(2.0f * x * w - 2.0f * y * z, -sqx + sqy - sqz + sqw); return; } Vector3 Quaternion::toEulerAngles() const { float sqw = r * r; float sqx = x * x; float sqy = y * y; float sqz = z * z; Vector3 euler( atan2( 2.0f * (x * y + z * r), sqx - sqy - sqz + sqw), asin( -2.0f * (x * z - y * r)), atan2( 2.0f * (y * z + x * r), -sqx - sqy + sqz + sqw)); return euler; } 

    1 answer 1

    It is not very clear from the context that this function should do at all, if only to proceed from your formulation. A line pulled out of context has no meaning at all without a description of what these vectors represent and how the result should be.

    QAngle is not a vector at all, it is a rotation, its three elements are nothing more than rotation angles around the axes of the CCS (related coordinate system).

    • X pitch (pitch) + up / -down

    • Y yaw (yaw) + left / -right

    • Z roll (roll) + right / -left

    What you found is for quaternions, and not the best option. A quaternion is a representation of rotation in the form of a 4-dimensional complex number, there is a different format, w is a component of a quaternion.

    Much depends on the order in which you define the coordinate axes (the direction of the CS is right-handed or left-handed), and in what order the rotation is defined. The order of turns in Euler angles is clearly defined. Therefore, your algorithm may vary, and apparently therefore they have implemented some sort of switching.

    For different objects it is preferable to rotate in a different order. For example, when controlling a person, a machine on the surface - first, rotation around the vertical (yaw) occurs, then roll and pitch (the order can vary), while controlling an airplane or other object in three dimensions - roll, pitch, yaw (corresponds to the order of Euler angles).

    I will give comments from the project I was working on (written by me)

     // Потядок вращений для углов Эйлера: // // вращает ССК вокруг изначальной x на 'roll' (крен) // вращает ССК вокруг изначальной y на 'pitch' (тангаж) // вращает ССК вокруг изначальной z на 'yaw' (рыскание). // . // /|\ yaw axis // | __. // ._ ___| /| pitch axis // _||\ \\ |-. / // \|| \_______\_|__\_/_______ // | _ _ oo o_o_o_o o /_\__ ________\ roll axis // // /_______/ /__________/ / // /_,-' // / // /__,-' // 

    This illustrates the order of the axes. If one axis is reversed, the system becomes "mirror", which corresponds to the permutation of the columns of transformation matrices, etc.