Revision Difference
Global.LocalToWorld#526831
<function name="LocalToWorld" parent="Global" type="libraryfunc">
<description>
Translates the specified position and angle from the specified local coordinate system into worldspace coordinates.
If you're working with an entity's local vectors, use <page>Entity:LocalToWorld</page> and/or <page>Entity:LocalToWorldAngles</page> instead.
See also: <page>Global.WorldToLocal</page>, the reverse of this function.
</description>
<realm>Shared</realm>
<args>
<arg name="localPos" type="Vector">The position vector in the source coordinate system, that should be translated to world coordinates</arg>
<arg name="localAng" type="Angle">The angle in the source coordinate system, that should be converted to a world angle. If you don't need to convert an angle, you can supply an arbitrary valid angle (e.g. <page>Global.Angle</page>()).</arg>
<arg name="originPos" type="Vector">The origin point of the source coordinate system, in world coordinates</arg>
<arg name="originAngle" type="Angle">The angles of the source coordinate system, as a world angle</arg>
</args>
<rets>
<ret name="" type="Vector">The world position of the supplied local position.</ret>
<ret name="" type="Angle">The world angles of the supplied local angle.</ret>
</rets>
</function>
⤶
⤶
<example>⤶
<description>Matrix math which showcases how this is calculated internally.</description>⤶
<code>⤶
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())⤶
</code>⤶
</example>