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