Can't draw on minimap...

Can't draw on minimap...

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Can't draw on minimap...

Post by KDR_11k »

Code: Select all

function gadget:DrawInMiniMap(mmsx, mmsy)
	local hasPerk = SYNCED.perks[Spring.GetLocalTeamID()].have[5] --improved gravidar
	gl.LoadIdentity()
	if hasPerk then
		local stepX = mmsx / gravSizeX
		local stepY = mmsy / gravSizeZ
		for y = 0,gravSizeZ do
			l = gravdata[y]
			for x = 0,gravSizeX do
				--Spring.Echo(x.." "..y)
				local val = sqrt(l[x]) / maxV
				Color(val,val,val,.4)
				Rect(x*stepX, y*stepY, (x+1)*stepX, (y+1)*stepY)
			end
		end
		gl.Color(1,1,1,1)
	else
		local stepX = mmsx / lowresSizeX
		local stepY = mmsy / lowresSizeZ
		for y=0,lowresSizeZ do
			l=lowres[y]
			for x=0,lowresSizeX do
				local val = sqrt(l[x]) / maxV
				Color(val,val,val,.4)
				Rect(x*stepX, y*stepY, (x+1)*stepX, (y+1)*stepY)
			end
		end
		Color(1,1,1,1)
	end
end
Doesn't draw anything. Practically the same code is working fine for drawing in the main view but this won't work. I've even tried just throwing a huge gl.Rect in there and that didn't show either.
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Can't draw on minimap...

Post by user »

write in the start of the function:

Code: Select all

  gl.PushMatrix()
  gl.LoadIdentity()
  gl.Translate(0, 1, 0)
  gl.Scale(1 / mx, 1 / mz, 1)
  gl.Rotate(90, 1, 0, 0)
  gl.PopMatrix()
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Can't draw on minimap...

Post by KDR_11k »

Isn't that just for translating world coordinates to minimap coordinates?
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Can't draw on minimap...

Post by user »

no, it is used to draw things on the mini map using the functions used to draw on the world.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Can't draw on minimap...

Post by KDR_11k »

Well, I tried running my DrawWorld() code in DrawInMiniMap with that wrapper, doesn't do anything either.

EDIT: Okay, that had the scaling factor wrong but it just draws one color over the whole minimap

Also isn't there a way to just draw on the minimap instead of shoehorning a draw world function into a minimap drawer?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Can't draw on minimap...

Post by jK »

KDR_11k wrote:Isn't that just for translating world coordinates to minimap coordinates?
it does. also the glRotate is redundant, cus a gl.Scale(1 / mx, -1 / mz, 1) would do the same job.

Your code is missing basic informations to fix the problem, cus it is a scaling problem and how should we know what gravSizeX, etc. is?
And why do you use mmsx&mmsy if you load the identity matrix? that can't work (you have a -1 upto +1 range after gl.LoadIdenity).

PS: never change the ModelViewMatrix w/o Push's and Pop's.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Can't draw on minimap...

Post by KDR_11k »

The loadidentity was probably a leftover from some testing, didn't work without it either. GravSizeX is the size of the gravdata field in X direction, 64 in this case IIRC. Step is the conversion factor between array coords and minimap coords.

BTW, isn't the rotate about projecting the z coords onto the y axis? I don't think scale would work for that.

EDIT: Ahhh, now it works (using the transformation and DrawWorld). Turns out "mx" and "mz" are supposed to be the mapsize dimensions, not the size of the minimap. I wish user had said that instead of quoting code out of context.
Post Reply

Return to “Lua Scripts”