Difference between revisions of "QAngle"

From Valve Developer Community
Jump to: navigation, search
(relell)
m (See also: removed the TODO because the page exists now)
 
(39 intermediate revisions by 20 users not shown)
Line 1: Line 1:
relbasge
+
{{otherlang2
{| style="text-align:center"
+
|de=QAngle:de
! Description || Name || Value || Image || Code
+
}}
|-
+
{{toc-right}}
|rowspan="3"| An angular world<br />orientation in degrees. || Pitch || Y
+
 
|rowspan="3"| [[Image:Roll_pitch_yaw.gif]]
+
'''QAngle''' is a C++ class that represents a three-dimensional Euler angle, offset from the cardinal [[Coordinates|Z axis]]. Each QAngle contains three [[vec_t]] rotation values:  
|rowspan="3"| <code>QAngle(y, z, x)</code>
+
 
|-
+
* '''X''' pitch +down/-up
| Yaw || Z
+
* '''Y''' yaw +left/-right
|-
+
* '''Z''' roll +right/-left
| Roll || X
+
 
|}
+
<code>(-45,10,0)</code> means 45&deg; up, 10&deg; left and 0&deg; roll.
 +
 
 +
{{tip|The axes are sometimes called rX, rY and rZ to distinguish them from [[vector]] axes.}}
 +
 
 +
{{note|Z is clamped to +/-50 for player viewangles.}}
 +
 
 +
== Declaration ==
 +
 
 +
QAngle angMyAngle = QAngle(-45,10,0);
 +
 
 +
* You could also assign to the X, Y and Z member variables separately.
 +
* The prefix <code>ang</code> (or sometimes just <code>a</code>) identifies the variable as an angle.
 +
 
 +
== Orientation ==
 +
 
 +
Confusingly, none of Source's rotation axes align with their [[Coordinates|position axes]] counterparts.
 +
 
 +
Even ''more'' confusingly, Hammer lists rotation axes as Y, Z, X! This is completely wrong, but luckily they are just labels: the values are stored in a single string (e.g. "-45 10 0") and interpreted by the game as rX rY rZ.
 +
 
 +
Remember that the effective direction of an angle is determined by its frame of reference. Typically, it will either be aligned to the world or to an entity.
 +
 
 +
== Converting from Vector ==
 +
 
 +
As there is no specific [[Data Descriptions#DEFINE_FIELD|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:
 +
 
 +
<source lang=cpp>
 +
QAngle angMyAngle = QAngle(vecFromHammer.x, vecFromHammer.y, vecFromHammer.z);
 +
 
 +
// Conversion back to a vector, if required
 +
AngleVectors(angMyAngle, &vecFromHammer);</source>
 +
 
 +
== See also ==
 +
 
 +
* [[Wikipedia:Yaw, pitch, and roll]]
 +
* [[getpos]]
 +
* [[Vector]]
 +
* [[AngleVectors()|<code>AngleVectors()</code> / <code>VectorAngles()</code>]]
  
 
[[Category:Glossary]]
 
[[Category:Glossary]]
[[Category:Helpers]]
+
[[Category:Variables]]
[[Category:Level Design]]
 

Latest revision as of 01:10, 25 June 2018

Deutsch

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.

Tip.png Tip: The axes are sometimes called rX, rY and rZ to distinguish them from vector axes.
Note.png Note: Z is clamped to +/-50 for player viewangles.

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 just a) identifies the variable as an angle.

Orientation

Confusingly, none of Source's rotation axes align with their position axes counterparts.

Even more confusingly, Hammer lists rotation axes as Y, Z, X! This is completely wrong, but luckily they are just labels: the values are stored in a single string (e.g. "-45 10 0") and interpreted by the game as rX rY rZ.

Remember that the effective direction of an angle is determined by its frame of reference. Typically, it will either be aligned to the world or to an entity.

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);

See also