Basically I'm doing this:
// setup display
set text font "Tahoma"
set text size 13
sync on : sync rate 60 : sync
autocam off
// create orthogonal camera
hudCamID = find free camera()
// offsets
orthoSizeX# = screen width() * .5
orthoSizeY# = screen height() * .5
orthoSizeZ# = orthoSizeY#
hudCamID = find free camera()
make camera hudCamID
set camera to image hudCamID, 99, screen width(), screen height()
color backdrop hudCamID, rgb(0,0,0)
// overide camera porjection matrix
projMat = new matrix4()
build ortho lhmatrix4 projMat, screen width(), screen height(), 1.0, 3000.0
apply projection matrix4 projMat, hudCamID
delete matrix4 projMat
// position it somewhere off screen
position camera hudCamID, 99999999, 0, 99999999
set current camera 0
// for keeping track of UI objects
dim uiElement()
// set up world
make matrix 1,128, 128, 128, 128
position camera 64, 1, 64
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
// work out offsets from ortho cam
posx# = camera position x(hudCamID) - orthoSizeX# + (_mopx+_mpx)/2
posy# = camera position y(hudCamID) + orthoSizeY# - (_mopy+_mpy)/2
posz# = camera position z(hudCamID) + orthoSizeZ#
// create objects to size and position
o = find free object()
array insert at bottom uiElement() : uiElement() = o
make object plain o, abs(_mpx-_mopx), abs(_mpy-_mopy), 0
position object o, posx#, posy#, posz#
set object light o, 0
drag = 0
endif
endif
// if any UI elements exist, rotate them for affect
if array count(uiElement()) > -1
for n = 0 to array count(uiElement())
o = uiElement(n)
rotate object o, 0, object angle y(o)+0.2, object angle z(o)+0.2
next
endif
// draw HUD camera over screen *switch this in future for a better method. ImageKit for example
sprite 1,0,0,99
set sprite 1,0,2
// debug
text 4,4,"Click Drag to Create UI Objects"
sync
loop
But as you can see there's the problem with how the orthogonal camera is combined with the main cam. So I figured if I turn them both into images and combined via a shader I could sort this. But that's where I'm stuck, no matter what I've tried the output is slightly transplant.
"Get in the Van!" - Van B