Garry's Mod Wiki

LocalToWorld

  Vector, Angle LocalToWorld( Vector localPos, Angle localAng, Vector originPos, Angle originAngle )

Description

Translates a vector and angle from a local coordinate system into a global coordinate system.

For the reverse of this function see WorldToLocal.

For working with an entity's local space vectors/angles you might want to use Entity:LocalToWorld/Entity:LocalToWorldAngles instead.

Arguments

1 Vector localPos
A vector from a local coordinate system.
2 Angle localAng
An angle from a local coordinate system.

Pass a zero angle if you don't need to translate an angle.

3 Vector originPos
The origin of a global coordinate system, in worldspace coordinates.
4 Angle originAngle
The angles of a global coordinate system, as a worldspace angle.

Returns

1 Vector
The correspondent worldspace vector of localPos.
2 Angle
The correspondent worldspace angle of localAng.

Example

A matrix math that shows how this is calculated internally.

local localTransform = Matrix() localTransform:SetTranslation( localPos ) localTransform:SetAngles( localAng ) local worldTransform = Matrix() worldTransform:SetTranslation( originPos ) worldTransform:SetAngles( originAngle ) -- Transform the local coordinates using the world transform as a transformation matrix local localToWorld = worldTransform * localTransform print( localToWorld:GetTranslation(), localToWorld:GetAngles() )