dreamworkAPI
Ctrl K
GitHub
classDocs / Angle3

Angle3

classsharedmenusource
Object → 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

NameTypeDescription
pitchnumberRotation around the Y axis in degrees, positive pitch looks down.
yawnumberRotation around the Z axis in degrees, positive yaw turns left.
rollnumberRotation around the X axis in degrees, positive roll tilts right.
zeroAngle3The shared zero angle ( 0, 0, 0 ), must not be modified.

Operators

OperatorOperandResult
add Angle3 | number Angle3
sub Angle3 | number Angle3
mul number Angle3
div number Angle3
unmAngle3

Static functions

copyCreates a new independent copy of the angle.
lerpLinearly interpolates the angle ( component-wise, without normalization ).
mulMultiplies all values of the angle by the number.
normalizeNormalizes the angle, all values will be in range [-180, 180).
rotateRotates the angle around the specified world axis by the specified degrees.
scaleMultiplies all values of the angle by the number.

#Angle3.copy

sharedmenunodiscardsource
function Angle3.copy(self: Angle3): Angle3

Creates a new independent copy of the angle.

Parameters
NameTypeDescription
selfAngle3The angle.
Returns
TypeNameDescription
Angle3copyThe new angle.

#Angle3.lerp

sharedmenusource
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
NameTypeDescription
selfAngle3The angle.
targetAngle3 | numberThe target angle or a number of degrees ( used for every value ).
fracnumberThe interpolation factor, 0 keeps the angle, 1 sets it to the target.
Returns
TypeNameDescription
Angle3ang3The same angle, interpolated.

#Angle3.mul

sharedmenusource
function Angle3.mul(self: Angle3, scale: number): Angle3

Multiplies all values of the angle by the number.

Parameters
NameTypeDescription
selfAngle3The angle.
scalenumberThe scale factor.
Returns
TypeNameDescription
Angle3ang3The same angle, scaled.

#Angle3.normalize

sharedmenusource
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
NameTypeDescription
selfAngle3The angle.
Returns
TypeNameDescription
Angle3ang3The same angle, normalized.

#Angle3.rotate

sharedmenusource
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
NameTypeDescription
selfAngle3The angle.
axisVector3The world axis to rotate around, must be normalized.
degreesnumberThe degrees to rotate around the axis.
Returns
TypeNameDescription
Angle3ang3The same angle, rotated.

#Angle3.scale

sharedmenusource
function Angle3.scale(self: Angle3, scale: number): Angle3

Multiplies all values of the angle by the number.

Parameters
NameTypeDescription
selfAngle3The angle.
scalenumberThe scale factor.
Returns
TypeNameDescription
Angle3ang3The same angle, scaled.

Methods

addAdds another angle or a number ( to every value ) to the angle.
divDivides all values of the angle by the number.
getBackwardReturns the backward direction of the angle ( negated forward ).
getDownReturns the down direction of the angle ( negated up ).
getForwardReturns the forward direction of the angle, roll does not affect it.
getLeftReturns the left direction of the angle ( negated right ).
getLerpedReturns a copy of the angle linearly interpolated to another angle or a number.
getNormalizedReturns a normalized copy of the angle, all values will be in range [-180, 180).
getRightReturns the right direction of the angle.
getRotatedReturns a copy of the angle rotated around the specified world axis by the specified degrees.
getUpReturns the up direction of the angle.
getVectorsReturns the forward, right and up directions of the angle at once.
isNearChecks if the angle is equal to the given angle with the given tolerance.
isZeroChecks if all values of the angle are exactly zero.
negateNegates all values of the angle.
setCopies the values of another angle into this angle.
setUnpackedSets the pitch, yaw and roll of the angle.
subSubtracts another angle or a number ( from every value ) from the angle.
toQuaternionReturns the rotation of the angle as a quaternion.
toVMatrixReturns the rotation of the angle as a matrix without translation.
unpackReturns the pitch, yaw and roll of the angle.
zeroSets all values of the angle to zero.

#Angle3:add

sharedmenusource
function Angle3:add(value: Angle3 | number): Angle3

Adds another angle or a number ( to every value ) to the angle.

Parameters
NameTypeDescription
valueAngle3 | numberThe other angle or a number of degrees.
Returns
TypeNameDescription
Angle3ang3The same angle, with the sum.

#Angle3:div

sharedmenusource
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
NameTypeDescription
divisornumberThe divisor.
Returns
TypeNameDescription
Angle3ang3The same angle, divided.

#Angle3:getBackward

sharedmenunodiscardsource
function Angle3:getBackward(): Vector3

Returns the backward direction of the angle ( negated forward ).

Returns
TypeNameDescription
Vector3backward_dirThe new normalized direction.

#Angle3:getDown

sharedmenunodiscardsource
function Angle3:getDown(): Vector3

Returns the down direction of the angle ( negated up ).

Returns
TypeNameDescription
Vector3down_dirThe new normalized direction.

#Angle3:getForward

sharedmenunodiscardsource
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
TypeNameDescription
Vector3forward_dirThe new normalized direction.

#Angle3:getLeft

sharedmenunodiscardsource
function Angle3:getLeft(): Vector3

Returns the left direction of the angle ( negated right ).

Returns
TypeNameDescription
Vector3left_dirThe new normalized direction.

#Angle3:getLerped

sharedmenunodiscardsource
function Angle3:getLerped(target: Angle3 | number, frac: number): Angle3

Returns a copy of the angle linearly interpolated to another angle or a number.

Parameters
NameTypeDescription
targetAngle3 | numberThe target angle or a number of degrees ( used for every value ).
fracnumberThe interpolation factor, 0 keeps the angle, 1 sets it to the target.
Returns
TypeNameDescription
Angle3lerped_ang3The new angle.

#Angle3:getNormalized

sharedmenunodiscardsource
function Angle3:getNormalized(): Angle3

Returns a normalized copy of the angle, all values will be in range [-180, 180).

Returns
TypeNameDescription
Angle3normalized_ang3The new angle.

#Angle3:getRight

sharedmenunodiscardsource
function Angle3:getRight(): Vector3

Returns the right direction of the angle.

Same as Angle:Right in Garry's Mod.

Returns
TypeNameDescription
Vector3right_dirThe new normalized direction.

#Angle3:getRotated

sharedmenunodiscardsource
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
NameTypeDescription
axisVector3The world axis to rotate around, must be normalized.
degreesnumberThe degrees to rotate around the axis.
Returns
TypeNameDescription
Angle3rotated_ang3The new angle.

#Angle3:getUp

sharedmenunodiscardsource
function Angle3:getUp(): Vector3

Returns the up direction of the angle.

Same as Angle:Up in Garry's Mod.

Returns
TypeNameDescription
Vector3up_dirThe new normalized direction.

#Angle3:getVectors

sharedmenunodiscardsource
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
TypeNameDescription
Vector3forward_dirThe new normalized forward direction.
Vector3right_dirThe new normalized right direction.
Vector3up_dirThe new normalized up direction.

#Angle3:isNear

sharedmenunodiscardsource
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
NameTypeDescription
angleAngle3The angle to check against.
tolerancenumberThe maximum allowed difference per value in degrees.
Returns
TypeNameDescription
booleanis_neartrue if the angles are equal within the tolerance, otherwise false.

#Angle3:isZero

sharedmenunodiscardsource
function Angle3:isZero(): boolean

Checks if all values of the angle are exactly zero.

Returns
TypeNameDescription
booleanis_zerotrue if the angle is zero, false otherwise.

#Angle3:negate

sharedmenusource
function Angle3:negate(): Angle3

Negates all values of the angle.

Returns
TypeNameDescription
Angle3ang3The same angle, negated.

#Angle3:set

sharedmenusource
function Angle3:set(angle: Angle3): Angle3

Copies the values of another angle into this angle.

Parameters
NameTypeDescription
angleAngle3The angle to copy from.
Returns
TypeNameDescription
Angle3ang3The same angle.

#Angle3:setUnpacked

sharedmenusource
function Angle3:setUnpacked(pitch: number, yaw: number, roll: number): Angle3

Sets the pitch, yaw and roll of the angle.

Parameters
NameTypeDescription
pitchnumberThe pitch in degrees.
yawnumberThe yaw in degrees.
rollnumberThe roll in degrees.
Returns
TypeNameDescription
Angle3ang3The same angle.

#Angle3:sub

sharedmenusource
function Angle3:sub(value: Angle3 | number): Angle3

Subtracts another angle or a number ( from every value ) from the angle.

Parameters
NameTypeDescription
valueAngle3 | numberThe other angle or a number of degrees.
Returns
TypeNameDescription
Angle3ang3The same angle, with the difference.

#Angle3:toQuaternion

sharedmenunodiscardsource
function Angle3:toQuaternion(): Quaternion

Returns the rotation of the angle as a quaternion.

Same as AngleQuaternion in Source engine.

Returns
TypeNameDescription
QuaternionquatThe new unit quaternion.

#Angle3:toVMatrix

sharedmenunodiscardsource
function Angle3:toVMatrix(): VMatrix

Returns the rotation of the angle as a matrix without translation.

Same as AngleMatrix in Source engine.

Returns
TypeNameDescription
VMatrixmatrixThe new rotation matrix.

#Angle3:unpack

sharedmenunodiscardsource
function Angle3:unpack(): number, number, number

Returns the pitch, yaw and roll of the angle.

Returns
TypeNameDescription
numberpitchThe pitch in degrees.
numberyawThe yaw in degrees.
numberrollThe roll in degrees.

#Angle3:zero

sharedmenusource
function Angle3:zero(): Angle3

Sets all values of the angle to zero.

Returns
TypeNameDescription
Angle3ang3The same angle.
Generated from the dreamwork meta branch.