From GMod Wiki
cam.Start3D2D( Vector position, Angle normal, Number scale )
Where is this used?
|Positions the rendering camera three dimensionally to draw on a plane.|
|Part of Library:||cam|
|BBCode Link:||[b][url=http://wiki.garrysmod.com/?title=Cam.Start3D2D]Cam.Start3D2D [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]|
- Seems to only work when called in ENT.Draw, ENT.DrawTranslucent, EFFECT.Render, Gamemode.PostDrawOpaqueRenderables , Gamemode.HUDPaint or SWEP.ViewModelDrawn. You may also use this inside of RenderScreenspaceEffects, if it's wrapped in cam.Start3D and cam.End3D.
- This may be used to draw a computer screen on a prop.
- It should also be noted that the position and angle do not seem to update when this is hooked via HUDPaint.
- The HUDPaint will draw in relevance to the HUD orthographic projection, to update, hook it to a render function such as ENT:Draw() and make use of surface drawing to render properly and to avoid overlaps of certain places.
Forgetting the scale argument can cause a hilarious rendering failThis doesn't seem to happen anymore, but you can get the same effect (IgnoreZ) by forgetting cam.End3D2D()
- These functions may be helpful for converting between Draw3D2D screen coordinates and world coordinates:
--[[ Converts from Draw3D2D screen coordinates to world coordinates. x and y are the coordinates to transform, in pixels. vPos is the position you gave Start3D2D. The screen is drawn from this point in the world. scale is a number you also gave to Start3D2D. The Draw3D2D screen is scaled this much aRot is the angles you gave Start3D2D. The screen is drawn rotated according to these angles. ]]-- local function ScreenToWorld(x,y,vPos,scale,aRot) local vWorldPos=Vector(x*scale,(-y)*scale,0); vWorldPos:Rotate(aRot); vWorldPos=vWorldPos+vPos; return vWorldPos; end --[[ Converts from world coordinates to Draw3D2D screen coordinates. vWorldPos is a vector in the world nearby a Draw3D2D screen. vPos is the position you gave Start3D2D. The screen is drawn from this point in the world. scale is a number you also gave to Start3D2D. aRot is the angles you gave Start3D2D. The screen is drawn rotated according to these angles. ]]-- local function WorldToScreen(vWorldPos,vPos,vScale,aRot) local vWorldPos=vWorldPos-vPos; vWorldPos:Rotate(Angle(0,-aRot.y,0)); vWorldPos:Rotate(Angle(-aRot.p,0,0)); vWorldPos:Rotate(Angle(0,0,-aRot.r)); return vWorldPos.x/vScale,(-vWorldPos.y)/vScale; end