Jump to content

[Help] How to convert coords to pixels, correctly?


Kazafka

Recommended Posts

Is there any universal way, to convert GTA SA coordinates to pixels?

I tried with this:

local x, y = getElementPosition(localPlayer)
x = (256 * x) / 6000 --(Player's coords times myMinimapWidth) devided by GTASAMaxCoords
y = (256 * y) / 6000 --Same as upper's

But it's not giving me positive results. Anyone knows the way?

Edited by VaporZ
Link to comment
10 minutes ago, stPatrick said:

Looks good.

I think you spoil it elsewhere.

Look at this, perhaps ur right:

pliki = {
	mapa = "files/colormap.png",
	gracz = "files/playerblip.png"
}
	
hud = {
	szer = 320,
	przez = 200
}

addEventHandler("onClientResourceStart", resourceRoot, function()
	setPlayerHudComponentVisible("radar", false)
end)

addEventHandler("onClientResourceStop", resourceRoot, function()
	setPlayerHudComponentVisible("radar", true)
end)

addEventHandler("onClientRender", root, function()
	local w, h = guiGetScreenSize()
	
	local x, y, z = getElementPosition(localPlayer)
	
	local mult = 320 / 6000
	
	local sX = x * mult
	local sY = y * mult
	
	local r = getScreenRotationFromWorldPosition(x, y, z)
	
	dxDrawImageSection(9, 24, hud.szer, hud.szer, sX, sY, hud.szer, hud.szer, pliki.mapa, r--[[ - 72]], 0, 0, tocolor(255, 255, 255, hud.przez))
end)

Results are negative, for my expectations.

Link to comment
1 minute ago, -ffs-PLASMA said:

At line 24, you already divide image size by 6000 and then in 26/27 you multiply it with player position but you need to multiply image size with player position first before dividing it by 6000.

Ok, but look at this at logic side:

local x, y, z = getElementPosition(localPlayer)

local mult = 320 / 6000

local sx = x * mult --Example: 16 (x) * 0.05 (320 / 6000) = 0.8
local sy = y * mult

--Isn't that same as:

local sx = (x * 320) / 6000 --Example: 16 (x) * 0.05 (320 / 6000) = 0.8
local sy = (y * 320) / 6000

If you still not see the similarity, look:

(16 * 320) / 6000 is pretty the same as 16 * (320 / 6000)

Link to comment
2 hours ago, stPatrick said:

Looks good.

I think you spoil it elsewhere.

Well, I have another question, skipping previous, why this don't rendering target?

pliki = {
	mapa = "files/colormap.png"
}
	
hud = {
	szer = 320,
	przez = 200
}

addEventHandler("onClientResourceStart", resourceRoot, function()
	setPlayerHudComponentVisible("radar", false)
	
	image = dxCreateRenderTarget(hud.szer, hud.szer, true)
end)

addEventHandler("onClientResourceStop", resourceRoot, function()
	setPlayerHudComponentVisible("radar", true)
	
	destroyElement(image)
end)

addEventHandler("onClientRender", root, function()
	local x, y, z = getElementPosition(localPlayer)
	local r = getScreenRotationFromWorldPosition(x, y, z)
	
	dxSetRenderTarget(image)
	-dxSetBlendMode("blend")
	dxDrawImageSection(9, 24, 3000, 3000, x, y, 3000, 3000, pliki.mapa)
end)

 

Link to comment
  • Scripting Moderators
20 minutes ago, VaporZ said:

Well, I have another question, skipping previous, why this don't rendering target?


pliki = {
	mapa = "files/colormap.png"
}
	
hud = {
	szer = 320,
	przez = 200
}

addEventHandler("onClientResourceStart", resourceRoot, function()
	setPlayerHudComponentVisible("radar", false)
	
	image = dxCreateRenderTarget(hud.szer, hud.szer, true)
end)

addEventHandler("onClientResourceStop", resourceRoot, function()
	setPlayerHudComponentVisible("radar", true)
	
	destroyElement(image)
end)

addEventHandler("onClientRender", root, function()
	local x, y, z = getElementPosition(localPlayer)
	local r = getScreenRotationFromWorldPosition(x, y, z)
	
	dxSetRenderTarget(image)
	-dxSetBlendMode("blend")
	dxDrawImageSection(9, 24, 3000, 3000, x, y, 3000, 3000, pliki.mapa)
end)

 

Not finished comment i guess?

-dxSetBlendMode("blend")

Perhaps do you use /debugscript 3 because it doesn't seems to?

Link to comment

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