Garry's Mod Wiki


  number render.ComputePixelDiameterOfSphere( Vector point, number radius )


Calculates diameter of a 3D sphere on a 2D screen.

This is a rendering function that requires a 3d rendering context.

This means that it will only work in 3d Rendering Hooks.


1 Vector point
The position of the sphere in 3D space.
2 number radius
The radius of the sphere in 3D space.


1 number
The diameter of the sphere in 2D screen space.


hook.Add( "HUDPaint", "HUDPaint_PixelDiameterOfSphereExample", function() local point = Vector( 0, 0, 0 ) cam.Start3D() local diameter = render.ComputePixelDiameterOfSphere( point, 10 ) cam.End3D() local pos2D = point:ToScreen() surface.DrawCircle( pos2D.x, pos2D.y, diameter / 2, Color( 255, 120, 0 ) ) end )