QAngle: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
'''QAngle''' is a C++ class that represents a three-dimensional Euler angle. Each QAngle contains three [[vec_t]] ordinates:  
{{toc-right}}
 
'''QAngle''' is a C++ class that represents a three-dimensional Euler angle, offset from the [[Coordinates|Z axis]]. Each QAngle contains three [[vec_t]] rotation values:  


* '''X''' pitch +down/-up
* '''X''' pitch +down/-up
Line 6: Line 8:


<code>(45,10,0)</code> means 45&deg; down, 10&deg; left and 0&deg; roll.
<code>(45,10,0)</code> means 45&deg; down, 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.}}
{{note|Z is clamped to +/-50 for player viewangles.}}
Line 17: Line 21:
* The prefix <code>ang</code> (or sometimes just <code>a</code>) identifies the variable as an angle.
* The prefix <code>ang</code> (or sometimes just <code>a</code>) identifies the variable as an angle.


== Converting to a vector ==
== Orientation ==
 
Confusingly, Source's rY and rZ angle axes respectively point down the ''Z'' and ''Y'' vector axes - the opposite of what might be expected. X stays the same, at least!
 
{{todo|Are angles typically abs or local?}}
 
== 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:
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:

Revision as of 06:45, 7 June 2009

QAngle is a C++ class that represents a three-dimensional Euler angle, offset from the 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° down, 10° left and 0° roll.

Tip.pngTip:The axes are sometimes called rX, rY and rZ to distinguish them from vector axes.
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.

Orientation

Confusingly, Source's rY and rZ angle axes respectively point down the Z and Y vector axes - the opposite of what might be expected. X stays the same, at least!

Todo: Are angles typically abs or local?

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