Sign in to follow this  

dxDrawImage, render targets

Recommended Posts

Hello. I have decided to write some kind of GPS/radar script by myself.

As always, there is some problems which i don't know can i solve. I have also other script which i'm using, but i prefer to rewrite it, because when local player is moving, the radar isn't moving smooth. :P

- How can i get correct offsets for radar, depends from player position, and background map with resolution 3000x3000.

- Why this code isn't that much effective as this one? And somehow when minimalizing a game, it uses less or more CPU.

-- takes up to 8, 10% of CPU

local gpsRender = dxCreateRenderTarget(290, 175)
local mapWidth, mapHeight = 3000, 3000

if gpsRender and playerTable.settings.user[2] then -- used within onClientRender <- render events by IIYAMA, i've tested, and default events gives nearly same results.
		dxSetRenderTarget(gpsRender, true)
		local x, y, z = getElementPosition(getLocalPlayer())
		local rotX, rotY, rotZ = getElementRotation(getCamera())
		dxDrawImage(-10, -10, mapWidth, mapHeight, "map.png", rotZ, x/mapWidth, -y/mapHeight, tocolor(255, 255, 255, 255))
		dxDrawImage(20, 100, 365, 235, gpsRender, 0, 0, 0, tocolor(255, 255, 255, 255))

-- before that code it's just a dxDrawText and nothing more.
-- takes up to 1-4% of CPU, and 20% when starting.
local worldW, worldH = 3072, 3072
local rt = dxCreateRenderTarget(290, 175)

local mW, mH = dxGetMaterialSize(rt) -- used within onClientRender.
dxSetRenderTarget(rt, true)
local x, y = getElementPosition(localPlayer)
local X, Y = mW/2 -(x/(6000/worldW)), mH/2 +(y/(6000/worldH))
local camX,camY,camZ = getElementRotation(getCamera())
dxDrawImage(X - worldW/2, mH/5 + (Y - worldH/2), worldW, worldH, "img/radar_map.jpg", camZ, (x/(6000/worldW)), -(y/(6000/worldH)), tocolor(255, 255, 255, 255))

-- later is some other code, and also ipairs loop.


Share this post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.