util.PixelVisible

From GMod Wiki

Jump to: navigation, search
Function
Syntax util.PixelVisible( Vector Position, Number Radius, pixelvis_handle_t Pixel Visible Handle )
Where is this used?
Description:
Returns the Float of visibility of the pixels in the radius of the Vector position.
Returns: Float
Part of Library: Util
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Util.PixelVisible]Util.PixelVisible [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionDraws a box when the center of the map is visible on your screen.
Used onNewerClient.png
Code
local PixVis = nil;
function SetupPixVis()
	PixVis = util.GetPixelVisibleHandle();
end
hook.Add("Initialize", "SetupPixVis", SetupPixVis);
 
function TestPixelVisibility()
	local visible = util.PixelVisible(Vector(0, 0, 0), 16, PixVis);
 
	if visible && visible != 0 then
		draw.RoundedBox( 10, 0, 0, 100, 100, Color(0, 0, 0, 200 * visible) );
	end
end
hook.Add("HUDPaint", "TestPixelVisibility", TestPixelVisibility);
OutputDraws a box when the center of the map is visible on your screen.


Additional Notes

You need to create a new pixel visibility handle for each unique query. Using the same pixel visibility handle for more than one pixel visibility query in the same engine tick will yield unusual results as demonstrated by the following client side Lua script.

local PixVis = util.GetPixelVisibleHandle()
 
local pts = {}
for i = 1,10 do table.insert( pts, Vector( 0, i * 64, 0 ) ) end
 
local function hudpaint_showvisibility()
    local v, p
 
    for i = 1,10 do
        v = util.PixelVisible( pts[i], 16, PixVis )
 
        p = pts[i]:ToScreen()
        if p.visible then
            draw.SimpleTextOutlined(string.format( "%.01f", v  ), "Default", p.x, p.y, color_white, 1, nil, 1, color_black) 
        end
    end
end
 
hook.Add( "HUDPaint", "showvisibility", hudpaint_showvisibility )

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox