QAngle: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (wth?)
(redone; the diagram was wrong)
Line 1: Line 1:
{| style="text-align:center"
'''QAngle''' is a C++ class that represents a three-dimensional Euler angle. Each QAngle contains three [[vec_t]] ordinates:  
! Description || Name || Value || Image || Code
 
|-
* X, for pitch (+down/-up)
|rowspan="3"| An angular world<br />orientation in degrees. || Pitch || Y
* Y, for yaw (+left/-right)
|rowspan="3"| [[Image:Roll_pitch_yaw.gif]]
* Z, for roll (+right/-left)
|rowspan="3"| <code>QAngle(y, z, x)</code>
 
|-
(45,10,0) means 45&deg; down, 10&deg; left and 0&deg; roll.
| Yaw || Z
 
|-
{{note|Z is clamped to +/-50 for player viewangles.}}
| Roll || X
 
|}
== Declaration ==
 
QAngle angMyAngle = QAngle(45,10,0);
 
* The classname QAngle is case-sensitive.
* 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.


== Converting to a vector ==
== Converting to a vector ==


Angles chosen in Hammer will arrive as [[vector]]s, but in a bad format. Fix them up with this code:
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
Vector vecDirection;
AngleVectors(angMyAngle, &vecDirection);</source>
 
== See also ==


<source lang=cpp>Vector vecAbsDir;
* [[Wikipedia:Yaw, pitch, and roll]]
QAngle angPushDir = QAngle(m_vecPushDir.x, m_vecPushDir.y, m_vecPushDir.z);
* [[getpos|getpos and setang]]
AngleVectors(angPushDir, &vecAbsDir);</source>
* [[Vector]]
* <code>[[AngleVectors()]]</code> and <code>[[VectorAngles()]]</code>


[[Category:Glossary]]
[[Category:Glossary]]
[[Category:Helpers]]
[[Category:Variables]]
[[Category:Programming]]

Revision as of 06:00, 7 June 2009

QAngle is a C++ class that represents a three-dimensional Euler angle. Each QAngle contains three vec_t ordinates:

  • X, for pitch (+down/-up)
  • Y, for yaw (+left/-right)
  • Z, for roll (+right/-left)

(45,10,0) means 45° down, 10° left and 0° roll.

Note.pngNote:Z is clamped to +/-50 for player viewangles.

Declaration

QAngle angMyAngle = QAngle(45,10,0);
  • The classname QAngle is case-sensitive.
  • 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.

Converting to a 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
Vector vecDirection;
AngleVectors(angMyAngle, &vecDirection);

See also