Jump to content

help getWorldPositionToImage


Recommended Posts

Posted (edited)

i´m create minimap using mask shader the wiki

to add blips i´m use dxTarget

i´m create dx image in dxTarget and set Target in shader, i´m necessary convert the blip world position to compatible image position

--
-- c_hud_mask.lua
--

----------------------------------------------------------------
-- onClientResourceStart
----------------------------------------------------------------
addEventHandler( "onClientResourceStart", resourceRoot,
	function()
		-- Create things
		screenx, screeny = 6000, 6000 -- the image dimension
        hudMaskShader = dxCreateShader("hud_mask.fx")
		radarTexture = dxCreateTexture("images/radar.jpg")
		maskTexture1 = dxCreateTexture("images/circle_mask.png")
		renderMap = dxCreateRenderTarget(screenx, screeny)

		-- Check everything is ok
		bAllValid = hudMaskShader and radarTexture and maskTexture1

		if not bAllValid then
			outputChatBox( "Could not create some things. Please use debugscript 3" )
		else
			dxSetShaderValue( hudMaskShader, "sPicTexture", radarTexture )
			dxSetShaderValue( hudMaskShader, "sMaskTexture", maskTexture1 )
		end
	end
)

-----------------------------------------------------------------------------------
-- onClientRender
-----------------------------------------------------------------------------------
addEventHandler( "onClientRender", root,
    function()
		if not bAllValid then return end
		--
		-- Transform world x,y into -0.5 to 0.5
		--
		local x,y = getElementPosition(localPlayer)
		x = ( x ) / 6000
		y = ( y ) / -6000
		dxSetShaderValue( hudMaskShader, "gUVPosition", x,y )
		
		--
		-- test blip
		--
		local bx, by = 1081, 270
		-- bx math ???
		-- by math ???
		--
		-- Zoom
		--
		local zoom = 8
		zoom = zoom + math.sin( getTickCount() / 500 ) * 3		-- Zoom animation for DEMO
		dxSetShaderValue( hudMaskShader, "gUVScale", 1/zoom, 1/zoom )

		--
		-- Rotate to camera direction - OPTIONAL
		--
		local _,_,camrot = getElementRotation( getCamera() )
		dxSetShaderValue( hudMaskShader, "gUVRotAngle", math.rad(-camrot) )

		--
		-- Draw
		--
		dxSetShaderValue( hudMaskShader2, "sPicTexture", renderMap )
		dxSetRenderTarget(renderMap)
			dxDrawImage( 0, 0, screenx, screeny, "images/radar.jpg", 0,0,0, tocolor(255,255,255,200) )
			dxDrawImage( bx, by, 16, 16, blipicon, 0,0,0, tocolor(255,255,255,255) )
		dxSetRenderTarget()

		-- set render target in shader
		dxSetShaderValue( hudMaskShader, "sPicTexture", renderMap )
		
		dxDrawImage( 100, 200, 400, 400, hudMaskShader, 0,0,0, tocolor(255,255,255,100) )
    end
)

 

Edited by raynner
Link to post

oh ok

is 
local mx, my = screenx/2, screeny/2
bx = bx + mx
by = my - by
bx = bx - (blipsize/2)
by = by - (blipsize/2)

if use other screen dimension to create imagem, you will need a number that divides the dimension of the world from 6000x6000 to the resolution you want for example

screenx, screeny = 768, 768 -- 6000 / 7.81 = 768
Divided = 768/2
bx, by = -27, 165 -- is world position
bx = math.floor (bx / 7.81) -- convert position world 6000x6000 to 768x768
by = math.floor (by / 7.81)
bx = bx + Divided
by = Divided - by
bx = bx - (32/2)
by = by - (32/2)

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...