Angle3
A 3D angle object ( pitch, yaw, roll in degrees ) in Source engine convention.
Arithmetic operators work component-wise:
ang3 + ang3, ang3 + number, number + ang3 ( same for - )ang3 * number, number * ang3, ang3 / number-ang3
Multiplying or dividing two angles is not supported, it has no geometric meaning.
Constructor
Angle3(pitch: number?, yaw: number?, roll: number?): Angle3
Fields
| Name | Type | Description |
|---|
pitch | number | Rotation around the Y axis in degrees, positive pitch looks down. |
yaw | number | Rotation around the Z axis in degrees, positive yaw turns left. |
roll | number | Rotation around the X axis in degrees, positive roll tilts right. |
zero | Angle3 | The shared zero angle ( 0, 0, 0 ), must not be modified. |
Operators
Static functions
copy | Creates a new independent copy of the angle. |
lerp | Linearly interpolates the angle ( component-wise, without normalization ). |
mul | Multiplies all values of the angle by the number. |
normalize | Normalizes the angle, all values will be in range [-180, 180). |
rotate | Rotates the angle around the specified world axis by the specified degrees. |
scale | Multiplies all values of the angle by the number. |
function Angle3.copy(self: Angle3): Angle3
Creates a new independent copy of the angle.
Parameters
| Name | Type | Description |
|---|
self | Angle3 | The angle. |
Returns
| Type | Name | Description |
|---|
Angle3 | copy | The new angle. |
function Angle3.lerp(self: Angle3, target: Angle3 | number, frac: number): Angle3
Linearly interpolates the angle ( component-wise, without normalization ).
Interpolating from 350 to 10 goes the long way through 180, normalize both angles or use Quaternion:slerp for the shortest rotation.
Parameters
| Name | Type | Description |
|---|
self | Angle3 | The angle. |
target | Angle3 | number | The target angle or a number of degrees ( used for every value ). |
frac | number | The interpolation factor, 0 keeps the angle, 1 sets it to the target. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, interpolated. |
function Angle3.mul(self: Angle3, scale: number): Angle3
Multiplies all values of the angle by the number.
Parameters
| Name | Type | Description |
|---|
self | Angle3 | The angle. |
scale | number | The scale factor. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, scaled. |
function Angle3.normalize(self: Angle3): Angle3
Normalizes the angle, all values will be in range [-180, 180).
Same as Angle:Normalize in Garry's Mod.
Parameters
| Name | Type | Description |
|---|
self | Angle3 | The angle. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, normalized. |
function Angle3.rotate(self: Angle3, axis: Vector3, degrees: number): Angle3
Rotates the angle around the specified world axis by the specified degrees.
Same as Angle:RotateAroundAxis in Garry's Mod, rotation follows the right-hand rule:
- around
ang:getUp() positive degrees turn left ( add yaw ). - around
ang:getRight() positive degrees look up ( subtract pitch ). - around
ang:getForward() positive degrees tilt right ( add roll ).
The result is not normalized.
Parameters
| Name | Type | Description |
|---|
self | Angle3 | The angle. |
axis | Vector3 | The world axis to rotate around, must be normalized. |
degrees | number | The degrees to rotate around the axis. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, rotated. |
function Angle3.scale(self: Angle3, scale: number): Angle3
Multiplies all values of the angle by the number.
Parameters
| Name | Type | Description |
|---|
self | Angle3 | The angle. |
scale | number | The scale factor. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, scaled. |
Methods
add | Adds another angle or a number ( to every value ) to the angle. |
div | Divides all values of the angle by the number. |
getBackward | Returns the backward direction of the angle ( negated forward ). |
getDown | Returns the down direction of the angle ( negated up ). |
getForward | Returns the forward direction of the angle, roll does not affect it. |
getLeft | Returns the left direction of the angle ( negated right ). |
getLerped | Returns a copy of the angle linearly interpolated to another angle or a number. |
getNormalized | Returns a normalized copy of the angle, all values will be in range [-180, 180). |
getRight | Returns the right direction of the angle. |
getRotated | Returns a copy of the angle rotated around the specified world axis by the specified degrees. |
getUp | Returns the up direction of the angle. |
getVectors | Returns the forward, right and up directions of the angle at once. |
isNear | Checks if the angle is equal to the given angle with the given tolerance. |
isZero | Checks if all values of the angle are exactly zero. |
negate | Negates all values of the angle. |
set | Copies the values of another angle into this angle. |
setUnpacked | Sets the pitch, yaw and roll of the angle. |
sub | Subtracts another angle or a number ( from every value ) from the angle. |
toQuaternion | Returns the rotation of the angle as a quaternion. |
toVMatrix | Returns the rotation of the angle as a matrix without translation. |
unpack | Returns the pitch, yaw and roll of the angle. |
zero | Sets all values of the angle to zero. |
function Angle3:add(value: Angle3 | number): Angle3
Adds another angle or a number ( to every value ) to the angle.
Parameters
| Name | Type | Description |
|---|
value | Angle3 | number | The other angle or a number of degrees. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, with the sum. |
function Angle3:div(divisor: number): Angle3
Divides all values of the angle by the number.
Division by zero is not checked and results in inf / nan values.
Parameters
| Name | Type | Description |
|---|
divisor | number | The divisor. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, divided. |
function Angle3:getBackward(): Vector3
Returns the backward direction of the angle ( negated forward ).
Returns
| Type | Name | Description |
|---|
Vector3 | backward_dir | The new normalized direction. |
function Angle3:getDown(): Vector3
Returns the down direction of the angle ( negated up ).
Returns
| Type | Name | Description |
|---|
Vector3 | down_dir | The new normalized direction. |
function Angle3:getForward(): Vector3
Returns the forward direction of the angle, roll does not affect it.
Same as Angle:Forward in Garry's Mod.
Returns
| Type | Name | Description |
|---|
Vector3 | forward_dir | The new normalized direction. |
function Angle3:getLeft(): Vector3
Returns the left direction of the angle ( negated right ).
Returns
| Type | Name | Description |
|---|
Vector3 | left_dir | The new normalized direction. |
function Angle3:getLerped(target: Angle3 | number, frac: number): Angle3
Returns a copy of the angle linearly interpolated to another angle or a number.
Parameters
| Name | Type | Description |
|---|
target | Angle3 | number | The target angle or a number of degrees ( used for every value ). |
frac | number | The interpolation factor, 0 keeps the angle, 1 sets it to the target. |
Returns
| Type | Name | Description |
|---|
Angle3 | lerped_ang3 | The new angle. |
function Angle3:getNormalized(): Angle3
Returns a normalized copy of the angle, all values will be in range [-180, 180).
Returns
| Type | Name | Description |
|---|
Angle3 | normalized_ang3 | The new angle. |
function Angle3:getRight(): Vector3
Returns the right direction of the angle.
Same as Angle:Right in Garry's Mod.
Returns
| Type | Name | Description |
|---|
Vector3 | right_dir | The new normalized direction. |
function Angle3:getRotated(axis: Vector3, degrees: number): Angle3
Returns a copy of the angle rotated around the specified world axis by the specified degrees.
See Angle3:rotate for the rotation direction.
Parameters
| Name | Type | Description |
|---|
axis | Vector3 | The world axis to rotate around, must be normalized. |
degrees | number | The degrees to rotate around the axis. |
Returns
| Type | Name | Description |
|---|
Angle3 | rotated_ang3 | The new angle. |
function Angle3:getUp(): Vector3
Returns the up direction of the angle.
Same as Angle:Up in Garry's Mod.
Returns
| Type | Name | Description |
|---|
Vector3 | up_dir | The new normalized direction. |
function Angle3:getVectors(): Vector3, Vector3, Vector3
Returns the forward, right and up directions of the angle at once.
Same as AngleVectors in Source engine, faster than calling getForward, getRight and getUp separately.
Returns
| Type | Name | Description |
|---|
Vector3 | forward_dir | The new normalized forward direction. |
Vector3 | right_dir | The new normalized right direction. |
Vector3 | up_dir | The new normalized up direction. |
function Angle3:isNear(angle: Angle3, tolerance: number): boolean
Checks if the angle is equal to the given angle with the given tolerance.
Values are compared as is, without normalization, so 359 and -1 are not near.
Parameters
| Name | Type | Description |
|---|
angle | Angle3 | The angle to check against. |
tolerance | number | The maximum allowed difference per value in degrees. |
Returns
| Type | Name | Description |
|---|
boolean | is_near | true if the angles are equal within the tolerance, otherwise false. |
function Angle3:isZero(): boolean
Checks if all values of the angle are exactly zero.
Returns
| Type | Name | Description |
|---|
boolean | is_zero | true if the angle is zero, false otherwise. |
function Angle3:negate(): Angle3
Negates all values of the angle.
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, negated. |
function Angle3:set(angle: Angle3): Angle3
Copies the values of another angle into this angle.
Parameters
| Name | Type | Description |
|---|
angle | Angle3 | The angle to copy from. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle. |
function Angle3:setUnpacked(pitch: number, yaw: number, roll: number): Angle3
Sets the pitch, yaw and roll of the angle.
Parameters
| Name | Type | Description |
|---|
pitch | number | The pitch in degrees. |
yaw | number | The yaw in degrees. |
roll | number | The roll in degrees. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle. |
function Angle3:sub(value: Angle3 | number): Angle3
Subtracts another angle or a number ( from every value ) from the angle.
Parameters
| Name | Type | Description |
|---|
value | Angle3 | number | The other angle or a number of degrees. |
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle, with the difference. |
function Angle3:toQuaternion(): Quaternion
Returns the rotation of the angle as a quaternion.
Same as AngleQuaternion in Source engine.
Returns
| Type | Name | Description |
|---|
Quaternion | quat | The new unit quaternion. |
function Angle3:toVMatrix(): VMatrix
Returns the rotation of the angle as a matrix without translation.
Same as AngleMatrix in Source engine.
Returns
| Type | Name | Description |
|---|
VMatrix | matrix | The new rotation matrix. |
function Angle3:unpack(): number, number, number
Returns the pitch, yaw and roll of the angle.
Returns
| Type | Name | Description |
|---|
number | pitch | The pitch in degrees. |
number | yaw | The yaw in degrees. |
number | roll | The roll in degrees. |
function Angle3:zero(): Angle3
Sets all values of the angle to zero.
Returns
| Type | Name | Description |
|---|
Angle3 | ang3 | The same angle. |