Page 1 of 1

Spring.Pos2BuildPos - BUG ?

Posted: 29 Aug 2011, 23:28
by Tanatos
Draw a box around the building model in the mouse coordinates.
Draw a model of a building aligned coordinate function Pos2BuildPos.
The result is visible in the screenshot. On the left shows the structure in line for construction - to 100% correct.
Alignment gives wrong coordinates? Why?
The code is as follows:

Code: Select all

local mX, mY, mBtnL, mBtnM, mBtnR = Spring.GetMouseState ()
local cPos = GetMouseWorldCoors (mX, mY)
local x, y, z, h = cPos [1], cPos [2], cPos [3], cmd.params [4]
gl.BeginEnd (GL.LINE_STRIP, DrawOutline,-cmd.id, x, y, z, h)

x, y, z = Spring.Pos2BuildPos (-cmd.id, x, y, z)
gl.DepthTest (true)
gl.PushMatrix ()
gl.Translate (x, y, z)
gl.Rotate (degrees, 0, 1.0, 0)
gl.UnitShape (-cmd.id, Spring.GetMyPlayerID ())

function DrawOutline (cmd, x, y, z, h)
local ud = UnitDefs [cmd]
local baseX = ud.xsize * 4 - ud.buildingDecalSizeX
local baseZ = ud.zsize * 4 - ud.buildingDecalSizeY
if (h == 1 or h == 3) then
baseX, baseZ = baseZ, baseX
end
gl.Vertex (x-baseX, y, z-baseZ)
gl.Vertex (x-baseX, y, z + baseZ)
gl.Vertex (x + baseX, y, z + baseZ)
gl.Vertex (x + baseX, y, z-baseZ)
gl.Vertex (x-baseX, y, z-baseZ)
end

Re: Spring.Pos2BuildPos - BUG ?

Posted: 29 Aug 2011, 23:41
by Tanatos
The error occurs only on the building of Fusion Reactor
Mod: Zero-K

Re: Spring.Pos2BuildPos - BUG ?

Posted: 29 Aug 2011, 23:58
by knorke
quick guess:
did you spawn the building with /cheat /give?
if yes, i think it will not snap to the 8-elmo grid like it does when being build normally.

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 00:03
by Tanatos
Left buildig place with Central Build.
Right i draw, no cheat

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 07:19
by Google_Frog
I'm not quite sure what the problem is but here's a widget that draws structure models at the correct position.

http://code.google.com/p/zero-k/source/ ... stSite.lua

The draw position was broken up until the most recent change to the widget.

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 08:18
by Niobium
Indeed it is a bug.

Pos2BuildPos doesn't take a facing argument and ends up using a hardcoded facing of 0 (south). So for non-square buildings facing west/east there can be a mismatch.

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 10:02
by hoijui
http://springrts.com/mantis/view.php?id=2629

edit: done, thanks Niobium
so you may test with current spring master if this really solves your problem, Tanatos.

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 11:37
by Tanatos
Google_Frog thanks for the example, but this widget gets the coordinates already building under construction. This means that the alignment of the grid is not happening.
Widget Central Build also receives the coordinates of the real line for construction.

Just wanted to know how to fix the code:)
Incredibly fast!

Thank you very much!
Test and write in the evening.

Check the changes I can re-download:
http://sourceforge.net/projects/springr ... e/download / http://sourceforge.net/projects/springr ... z/download
or just download the source code and compile it?

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 12:40
by hoijui
this contains the change:
http://springrts.com/dl/buildbot/defaul ... -ga17545b/
the .exe in there is the installer.

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 13:58
by Tanatos
Thanks again!!!
Checked, it works, only added orientation.

When can we expect that the fix will appear in the release version?
I would like to use the code in the real world, and the server needs to replace the version of the exe-file

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 14:20
by hoijui
it will be in next release. next release will be "soon", which might be in 2 weeks or 2 months.

Re: Spring.Pos2BuildPos - BUG ?

Posted: 30 Aug 2011, 16:02
by Tanatos
Written by an alternative function for alignments.
Paste code in LUA and instead use Spring.Pos2BuildPos

Code: Select all

function Pos2BuildPos(DefID, x, y, z, h)
	--	Grid step	
	local Step = 16

	--	1/2 size of Building
	local ud = UnitDefs[DefID]
	local baseX = ud.xsize * 4
	local baseZ = ud.zsize * 4

	if (h == 1 or h==3) then
		baseX,baseZ = baseZ,baseX
	end

	local rx = math.floor(( x - baseX + 8 ) / Step ) * Step + baseX
	local rz = math.floor(( z - baseZ + 8 ) / Step ) * Step + baseZ

	return rx, Spring.GetGroundHeight(rx, rz), rz
end