I was playing about with using plains for a hud, and came up with this.
Rem Project: hud
Rem Created: 09/11/2004 23:43:07
Rem ***** Main Source File *****
`This is the default camera field of view
#constant cameraFOV 61.9621391296
sync on
autocam off
backdrop on
color backdrop 0
`create text image for hud
create bitmap 1,450,92
set current bitmap 1
cls rgb(200,100,0)
ink rgb(255,255,255),0
line 0,0,448,0
line 0,0,0,90
line 0,90,448,90
line 448,0,448,90
ink rgb(0,0,150),rgb(200,100,0)
text 0,5," MakeHudObject - By Jason Clogg"
text 0,20," Code will position a plain at the correct position"
text 0,35," To display at exact size. E.G. a 50x50 plain will"
text 0,50," take up 50x50 pixels on screen"
text 0,65," Works for any resolution."
get image 1,0,0,449,91,1
set current bitmap 0
delete bitmap 1
position camera 0,0,0
MakeHudObject(1,1,450,92,0,0,1,1) `Top Left
MakeHudObject(2,1,450,92,573,675,1,1) `Bottom Right
do
sync
loop
function MakeHudObject(object,image,xsize,ysize,xpos,ypos,ghost,transparency)
`object=Object Number
`image=Image to use as texture
`xsize=X Size of texture image
`ysize=Y Size of texture image
`xpos=X Position on object in screen pixels
`ypos=Y Position on object in screen pixels
`ghost=Ghost object. 1=ghost on
`transparency=Use Alpha for transparency 1=transparency
`The objects are placed by top left corner rather than center as this make positioning easy.
dist#=(screen height()/2)/tan(cameraFOV/2)
make object plain object,xsize,ysize
texture object object,image
if ghost=1 then ghost object on object
if transparency=1 then set object transparency object,2
set object filter object,0 `Do Not MipMap
set object light object,0 `Do not be affected by light
xpos=(xpos-screen width()/2)+xsize/2 `Adjust position relative to screen pixels
ypos=((ypos*-1)+screen height()/2)-ysize/2
position object object,xpos,ypos,dist#
lock object on object
endfunction
The important bit is
dist#=(screen height()/2)/tan(cameraFOV/2), as this is the distance away from the camera to position the plain.
For example if you have a resolution of 1024x768, a plain of 1024x768 will fit exactly to screen without and blurring of the texture (providing you do not use mipmapping on the texture or object).
If this has already been done I apologise, but it was something I wanted to find out for myself and I thought I would pass it on.
Cheers,
Cloggy