Garry's Mod Wiki

Revision Difference

Global.WorldToLocal#526832

<function name="WorldToLocal" parent="Global" type="libraryfunc"> <description>Translates the specified position and angle into the specified coordinate system.</description> <realm>Shared</realm> <args> <arg name="position" type="Vector">The position that should be translated from the current to the new system.</arg> <arg name="angle" type="Angle">The angles that should be translated from the current to the new system.</arg> <arg name="newSystemOrigin" type="Vector">The origin of the system to translate to.</arg> <arg name="newSystemAngles" type="Angle">The angles of the system to translate to.</arg> </args> <rets> <ret name="" type="Vector">Local position</ret> <ret name="" type="Angle">Local angles</ret> </rets> </function> ⤶ <example>⤶ <description>Matrix math which showcases how this is calculated internally.</description>⤶ <code>⤶ local worldTransform = Matrix()⤶ worldTransform:SetTranslation(position)⤶ worldTransform:SetAngles(angle)⤶ ⤶ local objectTransform = Matrix()⤶ objectTransform:SetTranslation(newSystemOrigin)⤶ objectTransform:SetAngles(newSystemAngles)⤶ ⤶ -- Transform the world coordinates using the object transform as an inverted transformation matrix⤶ local worldToLocal = objectTransform:GetInverse() * worldTransform⤶ ⤶ print(worldToLocal:GetTranslation(), worldToLocal:GetAngles())⤶ </code>⤶ </example>