QAngle: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
m (Nesciuse moved page QAngle/en to QAngle without leaving a redirect: Move en subpage to basepage)
 
(13 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{lang|QAngle}}
{{LanguageBar|title = QAngle}}
 
{{toc-right}}
{{toc-right}}


'''QAngle''' это класс C++, который представляет трехмерный угол Эйлера, смещенный от кардинальной [[Coordinates|Z axis]]. Каждый QAngle содержит три значения поворота [[vec_t]]:
'''QAngle''' is a C++ class in [[Source]] that represents a three-dimensional [[Wikipedia: Extrinsic rotations|extrinsic Tait-Bryan rotations]] following the [[Wikipedia: Right-hand rule|right-hand rule]], offset from the cardinal [[Coordinates|Z axis]]. Each QAngle contains three [[vec t]] rotation values:  
== ==
=== X ===
'''X''' pitch +down/-up
=== Y ===
'''Y''' yaw +left/-right
=== Z ===
'''Z''' roll +right/-left
 
<code>(-45,10,0)</code> means 45° up, 10° left and 0° roll.
 
{{tip|The axes are sometimes called rX, rY and rZ to distinguish them from [[vector]] axes.}}


* '''X''' движение +вниз/-вверх
{{note|Z is clamped to +/-50 for player viewangles.}}
* '''Y''' движение +влево/-вправо
* '''Z''' поворот  +вправо/-влево


<code>(-45,10,0)</code> означает 45&deg; вверх, 10&deg; влево and 0&deg; поворота.
== Declaration ==


{{Tip|Иногда называют rX, rY и rZ чтобы отделять их от углов [[vector]] .}}
QAngle angMyAngle = QAngle(-45,10,0);


{{Note|Z фиксируются +/-50 для игрока viewangles.}}
* 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 ==


QAngle angMyAngle = QAngle(-45,10,0);
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'''


* Вы также можете назначить переменные-члены X, Y и Z отдельно.
{{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.
* Префикс <code>ang</code> (иногда <code>a</code>) определяет переменную как угол.
[[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'''


Как ни странно, ни одна из осей вращения источника не совпадает с их [[Coordinates|position axes]] сверстниками.
{{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:


Еще более "запутанно", что Хаммер перечисляет оси вращения как Y, Z, X! Это совершенно неправильно, но, к счастью, это всего лишь метки: значения хранятся в одной строке (например, "-45 10 0") и интерпретируются игрой как
* The difference between [[Wikipedia: Extrinsic rotations|intrinsic and extrinsic rotations]], is that with the former, each rotation shifts the axes along with it
rX rY rZ.
* 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 ==


Поскольку нет никаких конкретных [[Data Descriptions#DEFINE_FIELD|datadesc keyfield]] для углов, один, выбранный в Hammer, прибудет как [[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>
<source lang=cpp>
Line 40: Line 66:
AngleVectors(angMyAngle, &vecFromHammer);</source>
AngleVectors(angMyAngle, &vecFromHammer);</source>


== Также посмотрите ==
== Presence ==
 
* SP 2013 ([https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/sp/src/public/mathlib/vector.h#L1661 blob] [https://github.com/ValveSoftware/source-sdk-2013/blob/master/sp/src/public/mathlib/vector.h#L1661 master])
* MP 2013 ([https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/mp/src/public/mathlib/vector.h#L1661 blob] [https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/mathlib/vector.h#L1661 master])
 
== See also ==


* [[Wikipedia:Yaw, pitch, and roll]]
* [[Wikipedia:Yaw, pitch, and roll]]
* [[getpos]]
* [[getpos]]
* [[Vector]]
* [[Vector]] and [[Coordinates]]
* [[AngleVectors()|<code>AngleVectors()</code> / <code>VectorAngles()</code>]]
* [[AngleVectors()|<code>AngleVectors()</code> / <code>VectorAngles()</code>]]


[[Category:Source class]]
[[Category:Glossary]]
[[Category:Glossary]]
[[Category:Variables]]
[[Category:Variables]]

Latest revision as of 09:40, 12 July 2024

English (en)Deutsch (de)Русский (ru)中文 (zh)Translate (Translate)

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

X pitch +down/-up

Y

Y yaw +left/-right

Z

Z roll +right/-left

(-45,10,0) means 45° up, 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);
  • 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

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:
  • The difference between intrinsic and extrinsic rotations, is that with the former, each rotation shifts the axes along with it
  • The difference between 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 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.pngTip:Since many conflicting definitions are used in rotation, being explicit when it comes to naming can help avoid confusion

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

Presence

See also