Anyway, playing around I figured out how to lock objects to the camera in screen spaces using
lock object on, meaning 128x128 quad represents 128,128 pixels.
Simple Function:
function makeScreenQuad( x, y, sizeX, sizeY )
x# = -(screen width()/2) + (x*2+sizeX)/2
y# = (screen height()/2) - (y*2+sizeY)/2
z# = screen height()/(2.0*tan(camera fov()/2.0))
o = find free object()
make object plain o, sizeX, sizeY, 1
position object o, x#, y#, z#
lock object on o
endfunction o
Example:
set text font "Tahoma"
set text size 13
sync on : sync rate 60 : sync
autocam off
// set up world
make matrix 1,128, 128, 128, 128
position camera 64, 1, 64
// manual set
hudElement1 = makeScreenQuad( 24, 24, 128, 128 )
hudElement2 = makeScreenQuad( screen width()-(24+128), 24, 128, 128 )
do
yrotate camera 0, camera angle y(0)+0.2
// update imput
_moc = _mc
_mc = mouseclick()
_mpx = mousex() : _mpy = mousey()
// check to see if the mouse is dragging, if not, initial drag
if _mc <> moc
if not drag
_mopx = _mpx : _mopy = _mpy : _moc = _mc
drag = 1
endif
endif
// if drag, create object on release
if drag
if _moc = _mc
// really we should do 2d drawing in the render phase but oh well
line _mopx, _mopy, _mpx, _mopy
line _mopx, _mopy, _mopx, _mpy
line _mpx, _mopy, _mpx, _mpy
line _mopx, _mpy, _mpx, _mpy
text _mopx+6,_mopy+4, "pos - "+str$((_mopx+_mpx)/2)+" / "+str$((_mopy+_mpy)/2)
text _mopx+6,_mopy+4+text size(), "size - "+str$(abs(_mpx-_mopx))+" / "+str$(abs(_mpy-_mopy))
else
makeScreenQuad( min(_mopx,_mpx), min(_mopy,_mpy), abs(_mpx-_mopx), abs(_mpy-_mopy) )
drag = 0
endif
endif
// debug
text 4,4,"Click Hold Drag to Create UI Objects"
sync
loop
// create and position quad in screen space (cam 0)
function makeScreenQuad( x, y, sizeX, sizeY )
x# = -(screen width()/2) + (x*2+sizeX)/2
y# = (screen height()/2) - (y*2+sizeY)/2
z# = screen height()/(2.0*tan(camera fov()/2.0))
o = find free object()
make object plain o, sizeX, sizeY, 1
position object o, x#, y#, z#
lock object on o
endfunction o
Now all you'd need to do is texture them, apply shaders and handle them exactly like you would 2d and boom, 3d interface. For Z sorting, I guess you could just offset the Z axis by a tiny tiny bit. If offset it too much it will become smaller or bigger cause it's distance to the camera would change. But if it's by .01 or something then you won't notice it I guess
"Get in the Van!" - Van B