Here is a snippet to display a rotating 3d Menu system. The menu items are textured plains but you could load objects and make a 3d object selector.
Maybe it could be used to browse a selection of cars in a racing game,units in an rts, or game options.
Let me know if you find any bugs.
Rem Project: Rotating Menu
Rem Created: 05/11/2004 21:56:49
Rem ***** Main Source File *****
set display mode 1024,768,32 : sync on : sync rate 60 : autocam off : color backdrop 0
set cursor 0,0;print "Rotating 3D Menu By Jason Clogg (DBPro 5.7)"
print "Click on any menu item to bring to front."
print "Click on front object to select item."
Print "Cursor keys move through items one at a time."
get image 1000,0,0,500,100,1
make object plain 1000,500,100
texture object 1000,1000
position object 1000,-252,350,640
set object light 1000,0
`lock object on 1000
rem Global variables required by the menu functions
global maxitems
global angle#
global objectbase
global texturebase
`global baseangle#
rem Number of items in menu
maxitems=15
rem first object number to use when building the menu
objectbase=1
rem first texture number to use when building the menu
texturebase=1
rem You can texture the menu items here. aspect ratio should be 4:3
`load image "start.png",1,1
`load image "graphics.png",2,1
`load image "sound.png",3,1
`load image "high.png",4,1
`load image "controls.png",5,1
rem Generate some textures for menu
set text opaque:set text size 16
for i=1 to maxitems
cls rgb(255,0,0):ink rgb(255,255,255),rgb(255,0,0)
set cursor 15-text width(str$(i))/2,12.5-text height(str$(i))/2:print str$(i)
get image i,0,0,30,25,1
next i
cls 0:ink rgb(255,255,255),rgb(0,0,0):set text transparent
rem main loop. Run menu and return item
do
item=display_rotating_menu()
while spacekey()=0
set cursor 0,710
print "Menu Item Selected=",item
print "Press SPACEBAR to continue"
sync
endwhile
loop
function display_rotating_menu()
set ambient light 50
hide light 0
angle#=360/maxitems
baseangle#=0
rem create menu objects. Ive used textured plains but you could load objects
rem and create and object browser.
for i=0 to maxitems-1
objnum=i+objectbase
make object plain objnum,3,2.25
set object light objnum,1
set object transparency objnum,2
ghost object on objnum
fade object objnum,100
position object objnum,sin(angle#*i)*-10,0,cos(angle#*i)*-10
texture object objnum,i+texturebase
set object texture objnum,0,0
next i
fade object objectbase,180
rem set initial selected item
selitem=0
previtem=maxitems
rem set camera position and direction
position camera 0,3,-20
point camera 0,-1,0
do
if mouseclick()=1
clicked=pick object(mousex(),mousey(),objectbase,objectbase+maxitems-1)
rem if you click currently selected item, delete objects and return selected item number
if clicked-objectbase=selitem
for i=objectbase to objectbase+maxitems-1
delete object i
next i
retval=clicked-objectbase+1
exitfunction retval
rem otherwise move clicked item to front
else
if clicked>0
previtem=selitem
selitem=clicked-objectbase
show_menu_item(previtem,selitem)
endif
endif
endif
mwheel=mousemovez()
if rightkey()=1 or mwheel>0
if rk=1
rk=0
previtem=selitem
inc selitem
if selitem>maxitems-1 then selitem=0
show_menu_item(previtem,selitem)
endif
else
rk=1
endif
if leftkey()=1 or mwheel<0
if lk=1
lk=0
previtem=selitem
dec selitem
if selitem<0 then selitem=maxitems-1
show_menu_item(previtem,selitem)
endif
else
lk=1
endif
rem make sure objects point at the camera
for i=0 to maxitems-1
objnum=i+objectbase
set object to camera orientation objnum
turn object right objnum,180
next i
sync
loop
endfunction 0
function show_menu_item(previtem,selitem)
rem ca# is the current angle, a# is the angle of the selected item
ca#=wrapvalue(360-(previtem*angle#))
a#=360-(selitem*angle#)
rem Variables used to fade in an out items
pfd#=100
pfs#=180
sfd#=180
sfs#=100
if ca#<180 then a#=wrapvalue(a#)
rem move selected item to the front
repeat
ca#=curveangle(a#,ca#,20)
pfs#=curvevalue(pfd#,pfs#,20)
sfs#=curvevalue(sfd#,sfs#,20)
fade object previtem+objectbase,int(pfs#)
fade object selitem+objectbase,int(sfs#)
for i=0 to maxitems-1
objnum=i+objectbase
position object objnum,sin(ca#+angle#*i)*-10,0,cos(ca#+angle#*i)*-10
set object to camera orientation objnum
turn object right objnum,180
next i
sync
until abs(ca#-a#)<1
endfunction
Cheers,
Cloggy