Revision Difference
PhysObj:LocalToWorldVector#565643
<function name="LocalToWorldVector" parent="PhysObj" type="classfunc">
<description>
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.⤶
Rotationally transforms a vector in the physics object's local space by the <page>PhysObj:GetPositionMatrix</page>.
⤶
<note>In contrast to <page>PhysObj:LocalToWorld</page>, this function doesn't translate the vector.</note>⤶
</description>
<realm>Shared</realm>
<args>
<arg name="vecLocal" type="Vector">A vector in the physics object's local space.</arg>
</args>
<rets>
<ret name="" type="Vector">The result vector of the transformation by rotation.</ret>
<ret name="" type="Vector">The resulting vector from the rotational transformation.</ret>
</rets>
</function>
<example>
<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>
Displays the forward, right, and up directions of the physics object the player is looking at using <page>debugoverlay</page>.</description>
<code>
print( "Angle of that some PhysObj: ", PhysObj:GetAngles() )
print( "The result vector: ", PhysObj:LocalToWorldVector( Vector( 1, 2, 3 ) ) )
local vector_forward = Vector( 1, 0, 0 )
local vector_right = Vector( 0, -1, 0 )
local vector_up = Vector( 0, 0, 1 )⤶
⤶
local color_forward = Color( 255, 0, 0 )⤶
local color_right = Color( 255, 0, 255 ) -- Note: green is used for left, so then the reverse for the opposite⤶
local color_up = Color( 0, 0, 255 )⤶
⤶
concommand.Add( 'test_localtoworldvector', function( pPlayer )⤶
⤶
local traceAim = pPlayer:GetEyeTrace()⤶
local pEntity = traceAim.Entity⤶
⤶
if ( not pEntity:IsValid() ) then⤶
return⤶
end⤶
⤶
local pPhysObj = pEntity:GetPhysicsObject()⤶
⤶
if ( not pPhysObj:IsValid() ) then⤶
return⤶
end⤶
⤶
local vecForward = pPhysObj:LocalToWorldVector( vector_forward )⤶
local vecRight = pPhysObj:LocalToWorldVector( vector_right )⤶
local vecUp = pPhysObj:LocalToWorldVector( vector_up )⤶
⤶
local vecPos = pPhysObj:GetPos()⤶
debugoverlay.Line( vecPos, vecPos + vecForward * 48, 5, color_forward, true )⤶
debugoverlay.Line( vecPos, vecPos + vecRight * 48, 5, color_right, true )⤶
debugoverlay.Line( vecPos, vecPos + vecUp * 48, 5, color_up, true )⤶
⤶
end )⤶
</code>
<output>
```⤶
Angle of that some PhysObj: 0.045 89.952 89.993⤶
The result vector: 3.000585 0.999039 1.999603⤶
```⤶
<upload src="8cd79/8de286f90755a43.jpg" size="605485" name="test_localtoworldvector.jpg" />⤶
</output>
⤶
</example></example>
Garry's Mod
Rust
Steamworks
Wiki Help