cam.Start3D2D

From GMod Wiki

Jump to: navigation, search
Function
Syntax cam.Start3D2D( Vector position, Angle normal, Number scale )
Where is this used?
Description:
Positions the rendering camera three dimensionally to draw on a plane.
Returns: nil
Part of Library: cam
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Cam.Start3D2D]Cam.Start3D2D [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionPrint text on the screen in 3d.
Used onNewerClient.png
Code
 
        cam.Start3D2D( Vector(0, 0, 0), Angle(0, 0, 0), 1 )
                draw.DrawText("Your Mother", "ScoreboardText", 0, 0, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER )
        cam.End3D2D()
 
OutputDraws "Your Mother" at the Vector 0, 0, 0.


DescriptionPrint 3D2D text above every player's world model.
Used onNewerClient.png
Code
surface.CreateFont ( "coolvetica", 40, 400, true, false, "CV20", true )
 
function DrawName( ply )
 
	if !ply:Alive() then return end
 
	local offset = Vector( 0, 0, 85 )
	local ang = LocalPlayer():EyeAngles()
	local pos = ply:GetPos() + offset + ang:Up()
 
	ang:RotateAroundAxis( ang:Forward(), 90 )
	ang:RotateAroundAxis( ang:Right(), 90 )
 
	cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.25 )
		draw.DrawText( ply:GetName(), "CV20", 2, 2, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
	cam.End3D2D()
 
end
hook.Add( "PostPlayerDraw", "DrawName", DrawName )
OutputDraws the player's name above their world model.


Additional Notes

 
--[[
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
 

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox