Post by barliesque on Jan 12, 2005 8:00:13 GMT
I found a problem with centering an image. HUDdrawimage() positions the mesh so that it will be centered. However, if you then scale or turn that image, the centering is immediately lost due to the way those functions work. The same goes for the HUDpositionImage() function in another thread on this forum. ...So I've ammended HUDdrawimage() so that the mesh is constructed to retain its centering.
Function HUDdrawimage.hudimage(tex,x#,y#, zord = -99, cent_x = False, cent_y = False, frame=0)
; If tex = 0 Then Return
Local hi.hudimage = New hudimage
hi\tex = tex
hi\mesh = CreateMesh(currHUD\ent);(hi\piv)
hi\surf = CreateSurface(hi\mesh)
surf = hi\surf
hi\x = (x-400.0)*0.002
hi\y = (600.0 - y - 300.0)*0.002
If cent_x
x_left# = 0.001 * (-TextureWidth(tex))
x_right# = 0.001 * TextureWidth(tex)
Else
x_left# = 0.0
x_right# = 0.002 * TextureWidth(tex)
EndIf
If cent_y
y_top# = 0.001 * TextureHeight(tex)
y_bot# = 0.001 * (-TextureHeight(tex))
Else
y_top# = 0.0
y_bot# = 0.002 * (-TextureHeight(tex))
EndIf
v0 = AddVertex ( surf, x_left, y_top, 0, 0,0 )
v1 = AddVertex ( surf, x_right, y_top, 0, 1,0 )
v2 = AddVertex ( surf, x_left, y_bot, 0, 0,1 )
v3 = AddVertex ( surf, x_right, y_bot, 0, 1,1 )
; VertexColor surf,v0, currfont\r,currfont\g,currfont\b, currfont\alfa
; VertexColor surf,v1, currfont\r,currfont\g,currfont\b, currfont\alfa
; VertexColor surf,v2, currfont\r,currfont\g,currfont\b, currfont\alfa
; VertexColor surf,v3, currfont\r,currfont\g,currfont\b, currfont\alfa
AddTriangle ( surf,v0,v1,v2)
AddTriangle ( surf,v1,v3,v2)
EntityTexture hi\mesh,tex,frame
hi\frame = frame
PositionMesh hi\mesh, hi\x,hi\y,0
ScaleEntity hi\mesh,250,250,1 ;2.5,2.5,1
EntityFX hi\mesh,1
EntityOrder hi\mesh,zord
hi\zorder = zord
Return hi
End Function