Angle Helpers
Categories:
The Orientation namespace (GS_Core::Orientation) provides angle-to-sector mapping for directional gameplay — animation direction selection, facing classification, and compass-style sector queries. It splits a full circle into N equal angular sectors and determines which sector a given angle falls into, with hysteresis to prevent rapid sector-switching at boundaries.
Used by: Paper-facing systems (gs_performer), directional input reactors (gs_unit), targeting systems (gs_interaction)
For usage guides and setup examples, see The Basics: GS_Core.
Contents
SectionConfig Enum
A reflected, editor-friendly enum selecting common sector counts and alignment modes. Two alignment modes exist per count:
- cardinal / sideAligned — sector boundaries fall on the cardinal directions; sectors straddle diagonals
- quarters / forwardAligned — sector boundaries fall on diagonals; sectors straddle cardinals
| Family | Values |
|---|---|
| x4 | x4_cardinal, x4_quarters |
| x6 | x6_sideAligned, x6_forwardAligned |
| x8 | x8_cardinal, x8_quarters |
| x10 | x10_sideAligned, x10_forwardAligned |
| x12 | x12_sideAligned, x12_forwardAligned |
| x14 | x14_sideAligned, x14_forwardAligned |
| x16 | x16_sideAligned, x16_forwardAligned |
| x18 | x18_sideAligned, x18_forwardAligned |
| x20 | x20_sideAligned, x20_forwardAligned |
| x22 | x22_sideAligned, x22_forwardAligned |
| x24 | x24_sideAligned, x24_forwardAligned |
Register with GS_Core::Orientation::ReflectOrientationEnums(context) to expose these in the Inspector.
RotationDirection Enum
Controls the winding convention used when computing sector angles.
| Value | Numeric | Description |
|---|---|---|
CCW | 1 | Counter-clockwise winding |
CW | -1 | Clockwise winding |
Pick Struct
Returned by all PickByAngle overloads. Contains full sector geometry for the selected sector.
| Field | Type | Description |
|---|---|---|
index | int | Which sector was selected [0, N) |
count | int | Total number of sectors |
angle | float | The input angle as provided |
width | float | Angular width of each sector (2π / N) |
center | float | Center angle of the selected sector |
start | float | Start angle of the selected sector |
end | float | End angle of the selected sector |
Use GS_Core::Orientation::Changed(pick, prevIndex) to detect when the sector index changes between frames.
API Reference
Sector Mapping
| Function | Description |
|---|---|
PickByAngle(angle, count, halfAligned, prevIndex, hysteresisDeg, startAngle, dir) | Primary overload — full parameter control |
PickByAngle(angle, SectionConfig, prevIndex, hysteresisDeg, startAngle, dir) | Convenience overload using SectionConfig enum |
PickByAngle(angle, count, offsetRad, prevIndex, hysteresisDeg, startAngle, dir) | Low-level overload with explicit alignment offset |
ConfigToParams(cfg) | Maps a SectionConfig value to its (count, halfAligned) pair |
Changed(pick, prevIndex) | Returns true if the sector index changed from prevIndex |
Angle Math
| Function | Description |
|---|---|
WrapToTwoPi(x) | Wraps any angle to [0, 2π) |
WrapToPi(x) | Wraps any angle to (-π, π] |
AlignmentOffsetRad(N, halfAligned) | Returns the alignment shift in radians for a given count and mode |
Yaw and Quaternion
| Function | Description |
|---|---|
YawFromDir(dir, rotDir) | Flat yaw from a direction vector (Z-up world) |
YawFromDir(dir, upAxis, forwardHint, rotDir) | General yaw with custom up and forward axes |
FlatSignedYaw_ToCam(camFwd, rootFwd, up, dir) | Signed yaw from camera-forward to entity-forward, projected flat |
QuatFromYaw(yawRad, upAxis) | Builds a rotation quaternion from a yaw angle and up axis |
Reflection
| Function | Description |
|---|---|
ReflectOrientationEnums(context) | Registers SectionConfig and RotationDirection with SerializeContext |
Usage Example
#include <GS_Core/Utility/Math/SectionByAngle.h>
// Member field — track previous sector to enable hysteresis
int m_prevSectorIndex = -1;
// In your tick / update function:
AZ::Vector3 moveDir = GetMovementDirection();
// Get the yaw from the movement direction (Z-up world)
float yaw = GS_Core::Orientation::YawFromDir(moveDir, GS_Core::Orientation::RotationDirection::CCW);
// Map to an 8-way sector with 5-degree hysteresis
GS_Core::Orientation::Pick pick = GS_Core::Orientation::PickByAngle(
yaw,
GS_Core::Orientation::SectionConfig::x8_cardinal,
m_prevSectorIndex, // previous index for hysteresis
5.0f // hysteresis in degrees
);
if (GS_Core::Orientation::Changed(pick, m_prevSectorIndex))
{
m_prevSectorIndex = pick.index;
// React to direction change: play animation, update facing, etc.
}
See Also
For related resources:
Get GS_Core
GS_Core — Explore this gem on the product page and add it to your project.