Garry's Mod Wiki

Revision Difference

cam.Start3D2D#517304

<function name="Start3D2D" parent="cam" type="libraryfunc"> <description> Sets up a new 2D rendering context. Must be finished by <page>cam.End3D2D</page>. This function pushes a new matrix onto the stack. (<page>cam.PushModelMatrix</page>) <rendercontext hook="false" type="2D"/> <rendercontext hook="false" type="3D"/> </description> <realm>Client</realm> <args> <arg name="pos" type="Vector">Origin of the 3D2D context, ie. the top left corner, (0, 0).</arg> <arg name="angles" type="Angle">Angles of the 3D2D context.&amp;amp;lt;br&amp;amp;gt;&#xA;&#x2B;x in the 2d context corresponds to &#x2B;x of the angle (its forward direction).&amp;amp;lt;br&amp;amp;gt;&#xA;&#x2B;y in the 2d context corresponds to -y of the angle (its right direction).&#xA;&#xA;If (dx, dy) are your desired (&#x2B;x, &#x2B;y) unit vectors, the angle you want is dx:AngleEx(dx:Cross(-dy)).</arg> <arg name="scale" type="number">The scale of the render context.&#xA;If scale is 1 then 1 pixel in 2D context will equal to 1 unit in 3D context.</arg> </args> </function> <example> <code> hook.Add("PostDrawOpaqueRenderables", "example", function() local trace = LocalPlayer():GetEyeTrace() local angle = trace.HitNormal:Angle() render.DrawLine( trace.HitPos, trace.HitPos + 8 * angle:Forward(), Color( 255, 0, 0 ), true ) render.DrawLine( trace.HitPos, trace.HitPos + 8 * -angle:Right(), Color( 0, 255, 0 ), true ) render.DrawLine( trace.HitPos, trace.HitPos + 8 * angle:Up(), Color( 0, 0, 255 ), true ) cam.Start3D2D( trace.HitPos, angle, 1 ) surface.SetDrawColor( 255, 165, 0, 255 ) surface.DrawRect( 0, 0, 8, 8 ) render.DrawLine( Vector( 0, 0, 0 ), Vector( 8, 8, 8 ), Color( 100, 149, 237, 255 ), true ) cam.End3D2D() end ) </code> <output></output>⤶ <output><image src="cam.Start3D2D_example_1.png"/></output>⤶ </example>