Hi all. I've been experimenting with DB Pro for a few days, and am trying to make a game (of sorts). Now, I've run into some problems regarding the use of Graphic User Interfaces.
Here are the things I'm trying to achieve:
1). My test-GUI covers most of the screen, and has a tiny 'viewport'. I'd like to display a 3D enviroment in this space.
2). Ideally, the GUI would be allowed to scale according to the resolution the player chooses and would take as less FPS as possible to draw.
So far so good. I've been searching the forum and the tutorials for help and have been messing around with several techniques (pasting images and displaying 3D plains). A post from fellow forum-member Cloggy has resulted in the following code:
Rem Project: Gui using a 3D plane
Rem Created: Feb 05 2011
` ===============================
` Declare global variables
` ===============================
#CONSTANT cameraFOV 61.9621391296
Global BaseX as integer
Global BaseY as integer
Global ZDist as integer
Global MaxWidth as integer = 1024
Global MaxHeight as integer = 768
` ===============================
` Set the screen
` ===============================
set display mode MaxWidth, MaxHeight, 32
set window on
set window layout 0,1,0
sync on : sync rate 60
color backdrop rgb(0,0,0)
backdrop on
autocam off
` ===============================
` give values to globals/load gui
` ===============================
gosub SetGlobals
gosub DefineGui
` ===============================
` Main program loop
` ===============================
make object box 2,100,100,10
position object 2,0,0,-300
do
zrotate object 2, object angle z(2)+2
xrotate object 2, object angle x(2)+1
yrotate object 2, object angle y(2)+1
gosub DisplayGui
x#=x#+mousemovey() : y#=y#+mousemovex() : rotate camera 0,x#,y#,0 ` move camera with mouse - just for testing purposes
sync
loop
` ===============================
` Subroutine SetGlobals
` ===============================
SetGlobals:
ZDist=(screen height()/2)/TAN(cameraFOV/2) ` distance from camera to scale plain to screensize (i.e. 10x10 pixel plain takes up 10x10 pixels on screen)
BaseX=0-screen width()/2 ` variable needed to convert an object's X position to screen position
BaseY=screen height()/2 ` same for Y value
return
` ===============================
` Subroutine DefineGui
` ===============================
DefineGui:
load image "GUI_02.png", 100
make object plain 1,MaxWidth,MaxHeight
texture object 1,100
set object transparency 1, 1
set object light 1,0
return
` ===============================
` Subroutine DisplayGui
` ===============================
DisplayGui:
PlaceGui(1,0,0,MaxWidth,MaxHeight,0) ` other Gui-objects can be added ofcourse
return
` ===============================
` Function PlaceGui
` ===============================
Function PlaceGui(obj,x,y,width,height,ghost)
CamPosX=camera position x()
CamPosY=camera position y()
CamPosZ=camera position z()
position object obj,CamPosX,CamPosY,CamPosZ ` place plain at camera position
set object to camera orientation obj ` turn object to point in the same direction as the camera
turn object left obj,180 ` turn object to face camera
move object left obj,BaseX+x+(width/2) ` move object to pixel perfect distance on x-axis
move object up obj,BaseY-y-(height/2) ` same for y-axis
move object obj,(zDist*-1) ` same for z-axis
disable object zdepth obj ` make plain appear over everything else
set object filter obj,1 ` turn mipmaps on object off
if ghost=1 ` Ghost plain if requested (only works if object is set to be effected by lighting).
set object light obj,1
ghost object on obj
else
set object light obj,0 ` if ghosting is not required, make sure the plain isn't affected by brightness, lights etc.
ghost object off obj
endif
EndFunction
The result of wich looks a bit like this:
.
This sort of works. Sort of, because... while I have a scalable GUI, it's not *really* restricting the 3D-world to the viewport... The world is rendered and the 3D-plain is put on top of it. I've been fiddling around with another camera, but I'm not really sure if that's the right direction. So, I'd like to ask these two questions:
1). Is the 3D-plain route the best way of programming a GUI like this?
2). Is it possible to render the 3D world within a specific set of coordinates?
Thank you for any help!