QAngle: Difference between revisions
Weevil bob (talk | contribs) (→Naming Conventions: cameras) |
Weevil bob (talk | contribs) |
||
| Line 58: | Line 58: | ||
'''Cameras'''<br /> | '''Cameras'''<br /> | ||
When talking about cameras you might see the terms | When talking about cameras you might see the terms Tilt (up/down), Pan (left/right) and Roll (slant left/right) when talking about camera ([https://en.wikipedia.org/wiki/Gimbal Gimbal]) rotations. This is likely the reason why QAngle uses <span style="color:limegreen;">Y</span><span style="color:royalblue;">Z</span><span style="color:red;">X</span> coordinates. | ||
== Converting from Vector == | == Converting from Vector == | ||
Revision as of 16:58, 28 November 2025
QAngle is a C++ class in Source that represents a three-dimensional extrinsic Tait-Bryan rotations following the right-hand rule, offset from the cardinal Z axis. Each QAngle contains three vec t rotation values:
X
Roll +/- slant
Y
Pitch +down/-up
Z
Yaw +right/-left
id Tech 2, and by extension
GoldSrc,
Source, and
Source 2, use YZX = Pitch, Yaw, Roll, therefore
(-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(Qx, Qy, Qz) works, imagine a first-person perspective:
- Qx: Looking down or up corresponds to positive or negative [Y]
- Qy: Looking left or right corresponds to positive or negative [Z]
- Qz: Tilting your head so your right or left ear faces the ground corresponds to positive or negative [X]
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]
Positive angles are in "Clockwise rotation" around an axis, assuming the viewer is located at the origin looking out in the 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:
|
Cameras
When talking about cameras you might see the terms Tilt (up/down), Pan (left/right) and Roll (slant left/right) when talking about camera (Gimbal) rotations. This is likely the reason why QAngle uses YZX coordinates.
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);