QAngle: Difference between revisions
GrampaSwood (talk | contribs) Tag: Undo |
(Replaced ambiguous "Orientation" chapter with a more in-depth explanation. First explains the concept, then the numbers, and finally mentions terminology pitfalls) |
||
Line 23: | Line 23: | ||
== Orientation == | == Orientation == | ||
To get a feeling for how a <code>QAngle([X], [Y], [Z])</code> works, imagine a first-person perspective: | |||
* Looking down or up corresponds to positive or negative [X] | |||
* Looking left or right corresponds to positive or negative [Y] | |||
* Tilting your head so your right or left ear faces the ground corresponds to positive or negative [Z] | |||
To relate this back to vectors and coordinates: The values of [X], [Y], and [Z] correspond to a clockwise rotation (in degrees) around the [[Coordinates|absolute axes]]{{confirm}} y, z, and x, respectively. | |||
"Clockwise rotation" in an axis assumes the viewer is located at the origin looking in the positive direction of said axis. | |||
=== Naming Conventions === | |||
Different fields use different naming conventions to describe these angles. To clear up any conflicting terms, short explanations are included below. Source Engine seems to draw its lingo from Aerospace Engineering. | |||
'''Aerospace Engineering''' | |||
{{Expand|When imagining a plane, pitch moves the nose up and down, yaw moves the nose left and right, and roll causes one wing to move up and the other wing to move down. | |||
[[Wikipedia: Aircraft principal axes|In Aerospace Engineering]], this system is also referred to as Euler angles if — unlike QAngles — the axes rotate along. See "Mathematics" for clarification.}} | |||
'''Mathematics''' | |||
{{Expand| Strictly speaking, QAngles would be defined as [[Wikipedia: Extrinsic rotations|extrinsic Tait-Bryan rotations]] following the [[Wikipedia: Right-hand rule|right-hand rule]]. The terms "Tait-Bryan angles" and "Euler angles" are sometimes used interchangeably however. Breaking down this name into digestible chunks: | |||
* The difference between [[Wikipedia: Extrinsic rotations|intrinsic and extrinsic rotations]], is that with the former, each rotation shifts the axes along with it | |||
* The difference between [[Wikipedia: Euler angles|proper Euler angles and Tait-Bryan angles]], is that the former rotates twice around one axis and once around another (alternatingly), while the latter rotates once around all three axes | |||
* The [[Wikipedia: right-hand rule|right-hand rule]] states that if the thumb of one's right hand is pointing along the positive direction of an axis, their other fingers will curl in the positive direction of rotation | |||
{{tip|Since many conflicting definitions are used in rotation, being explicit when it comes to naming can help avoid confusion}} }} | |||
== Converting from Vector == | == Converting from Vector == |
Revision as of 22:51, 11 March 2023
QAngle is a C++ class that represents a three-dimensional Euler angle, offset from the cardinal Z axis. Each QAngle contains three vec_t rotation values:
- X pitch +down/-up
- Y yaw +left/-right
- Z roll +right/-left
(-45,10,0)
means 45° up, 10° left and 0° roll.


Declaration
QAngle angMyAngle = QAngle(-45,10,0);
- You could also assign to the X, Y and Z member variables separately.
- The prefix
ang
(or sometimes justa
) identifies the variable as an angle.
Orientation
To get a feeling for how a QAngle([X], [Y], [Z])
works, imagine a first-person perspective:
- Looking down or up corresponds to positive or negative [X]
- Looking left or right corresponds to positive or negative [Y]
- Tilting your head so your right or left ear faces the ground corresponds to positive or negative [Z]
To relate this back to vectors and coordinates: The values of [X], [Y], and [Z] correspond to a clockwise rotation (in degrees) around the absolute axes[confirm] y, z, and x, respectively.
"Clockwise rotation" in an axis assumes the viewer is located at the origin looking in the positive direction of said axis.
Naming Conventions
Different fields use different naming conventions to describe these angles. To clear up any conflicting terms, short explanations are included below. Source Engine seems to draw its lingo from Aerospace Engineering.
Aerospace Engineering
When imagining a plane, pitch moves the nose up and down, yaw moves the nose left and right, and roll causes one wing to move up and the other wing to move down.
In Aerospace Engineering, this system is also referred to as Euler angles if — unlike QAngles — the axes rotate along. See "Mathematics" for clarification. |
Mathematics
Strictly speaking, QAngles would be defined as extrinsic Tait-Bryan rotations following the right-hand rule. The terms "Tait-Bryan angles" and "Euler angles" are sometimes used interchangeably however. Breaking down this name into digestible chunks:
![]() |
Converting from Vector
As there is no specific datadesc keyfield for angles, one chosen in Hammer will arrive as a vector. Its ordinates will represent degrees of rotation and not coordinates so it must be fixed up before use:
QAngle angMyAngle = QAngle(vecFromHammer.x, vecFromHammer.y, vecFromHammer.z);
// Conversion back to a vector, if required
AngleVectors(angMyAngle, &vecFromHammer);