Garry's Mod Wiki

Revision Difference

PhysObj:LocalToWorldVector#565527

<function name="LocalToWorldVector" parent="PhysObj" type="classfunc"> <description> Rotate a vector from the local frame of the physics object to world frame. ⤶ <note>This function only rotates the vector, without any translation operation.</note>⤶ Transforms a vector in the local space of the physics object merely by the rotation of the `PhysObj:GetPositionMatrix()`. ⤶ In contrast to <page>PhysObj:LocalToWorld</page>, this function doesn't translate the vector. </description> <realm>Shared</realm> <args> <arg name="LocalVec" type="Vector">A vector in the physics object's local frame</arg>⤶ <arg name="vecLocal" type="Vector">A vector in the physics object's local space.</arg>⤶ </args> <rets> <ret name="" type="Vector">The corresponding vector in world frame</ret>⤶ <ret name="" type="Vector">The result vector of the transformation by rotation.</ret>⤶ </rets> </function> <example> <description>Given the angle of the physics object is angle ( 0.045, 89.952, 89.99 ) ( This can be derived by PhysObj:GetAngles() ), convert the vector ( 1 ,2, 3 ) in this physics object's local frame into world frame.</description>⤶ <description>⤶ Suppose... The angle of some physics object is `( 0.045, 89.952, 89.993 )`. Transform a vector `( 1, 2, 3 )` by that physics object's position matrix's rotation.</description>⤶ <code> print( "Angle of the PhysObj: ", PhysObj:GetAngles() ) print( "Vector in world frame: ", PhysObj:LocalToWorld( Vector( 1, 2, 3 ) ) ) print( "Angle of that some PhysObj: ", PhysObj:GetAngles() ) print( "The result vector: ", PhysObj:LocalToWorldVector( Vector( 1, 2, 3 ) ) ) </code> <output> Angle of the PhysObj: 0.045 89.952 89.993;⤶ Vector in world frame: 3.000585 0.999039 1.999603;⤶ ```⤶ Angle of that some PhysObj: 0.045 89.952 89.993⤶ The result vector: 3.000585 0.999039 1.999603⤶ ```⤶ </output> </example>