I set up a simple system to place my 3D objects in the gameworld:
set window on
set display mode 1024,768,32
load object "images\file1.x",1
load image "images\file1.jpg",1
texture object 1,1
make camera 1
scale object 1,10,10,10
position object 1,0,0,20
position camera 1,0,0,0
point camera 1,0,0,1
make object plane 2,160,40
load image "images\file2.png",2,1
set object transparency 2,4
texture object 2,2
position object 2,0,-40,100
make object plane 3,1024,768
load image "images\file3.jpg",3
texture object 3,3
position object 3,0,0,200
Global wkey
global lwkey
global WTRIG
Global skey
global lskey
global STRIG
Global ekey
global lekey
global ETRIG
Global dkey
global ldkey
global DTRIG
Global rkey
global lrkey
global RTRIG
Global fkey
global lfkey
global FTRIG
Global spkey
global lspkey
global SPTRIG
global enkey
global lenkey
global ENTRIG
type POSITION
X as float
Y as float
Z as float
T as integer
endtype
dim POS(3) as POSITION
POS(1).X=object position x(1)
POS(1).Y=object position y(1)
POS(1).Z=object position z(1)
POS(2).X=object position x(2)
POS(2).Y=object position y(2)
POS(2).Z=object position z(2)
POS(3).X=object position x(3)
POS(3).Y=object position y(3)
POS(3).Z=object position z(3)
dim OBNUM(0)
do
gosub TEXTDEBUG
gosub POSITIONDEBUG
gosub DISPLAYPIECES
sync
loop
DISPLAYPIECES:
position object 1,POS(1).X,POS(1).Y,POS(1).Z
position object 2,POS(2).X,POS(2).Y,POS(2).Z
position object 3,POS(3).X,POS(3).Y,POS(3).Z
return
TEXTDEBUG:
text 0,0,"Object Number: "+str$(OBNUM(0))
text 0,10,"Object X: "+str$(POS(OBNUM(0)).X)
text 0,20,"Object Y: "+str$(POS(OBNUM(0)).Y)
text 0,30,"Object Z: "+str$(POS(OBNUM(0)).Z)
return
POSITIONDEBUG:
OnSpace()
OnW()
OnS()
OnE()
OnD()
OnR()
OnF()
OnEnter()
if SPTRIG=1
if file exist("data\pos.arr")=1
delete file "data\pos.arr"
open to write 1,"data\pos.arr"
save array "data\pos.arr",POS(0)
close file 1
else
open to write 1,"data\pos.arr"
save array "data\pos.arr",POS(0)
close file 1
endif
endif
if WTRIG=1
if POS(OBNUM(0)).T<timer()
POS(OBNUM(0)).X=POS(OBNUM(0)).X+1
POS(OBNUM(0)).T=timer()+100
endif
endif
if STRIG=1
if POS(OBNUM(0)).T<timer()
POS(OBNUM(0)).X=POS(OBNUM(0)).X-1
POS(OBNUM(0)).T=timer()+100
endif
endif
if ETRIG=1
if POS(OBNUM(0)).T<timer()
POS(OBNUM(0)).Y=POS(OBNUM(0)).Y+1
POS(OBNUM(0)).T=timer()+100
endif
endif
if DTRIG=1
if POS(OBNUM(0)).T<timer()
POS(OBNUM(0)).Y=POS(OBNUM(0)).Y-1
POS(OBNUM(0)).T=timer()+100
endif
endif
if RTRIG=1
if POS(OBNUM(0)).T<timer()
POS(OBNUM(0)).Z=POS(OBNUM(0)).Z+1
POS(OBNUM(0)).T=timer()+100
endif
endif
if FTRIG=1
if POS(OBNUM(0)).T<timer()
POS(OBNUM(0)).Z=POS(OBNUM(0)).Z-1
POS(OBNUM(0)).T=timer()+100
endif
endif
if ENTRIG=1
OBNUM(0)=OBNUM(0)+1
if OBNUM(0)=4 then OBNUM(0)=1
endif
return
Function OnSpace()
lspkey=spkey
spkey=SpaceKey()
` not held Down
if spkey=0 and lspkey=0 then SPTRIG=0
` held Down
if spkey=1 and lspkey=0 then SPTRIG=1
` just Been Pressed
if spkey=1 and lspkey=1 then SPTRIG=1
` just been Lifted
if spkey=0 and lspkey=1 then SPTRIG=0
Endfunction
Function OnW()
lwkey=wkey
wkey=keystate(17)
` not held Down
if wkey=0 and lwkey=0 then WTRIG=0
` held Down
if wkey=1 and lwkey=0 then WTRIG=1
` just Been Pressed
if wkey=1 and lwkey=1 then WTRIG=1
` just been Lifted
if wkey=0 and lwkey=1 then WTRIG=0
Endfunction
Function OnS()
lskey=skey
skey=keystate(31)
` not held Down
if skey=0 and lskey=0 then STRIG=0
` held Down
if skey=1 and lskey=0 then STRIG=1
` just Been Pressed
if skey=1 and lskey=1 then STRIG=1
` just been Lifted
if skey=0 and lskey=1 then STRIG=0
Endfunction
Function OnE()
lekey=ekey
ekey=keystate(18)
` not held Down
if ekey=0 and lekey=0 then ETRIG=0
` held Down
if ekey=1 and lekey=0 then ETRIG=1
` just Been Pressed
if ekey=1 and lekey=1 then ETRIG=1
` just been Lifted
if ekey=0 and lekey=1 then ETRIG=0
Endfunction
Function OnD()
ldkey=dkey
dkey=keystate(32)
` not held Down
if dkey=0 and ldkey=0 then DTRIG=0
` held Down
if dkey=1 and ldkey=0 then DTRIG=1
` just Been Pressed
if dkey=1 and ldkey=1 then DTRIG=1
` just been Lifted
if dkey=0 and ldkey=1 then DTRIG=0
Endfunction
Function OnR()
lrkey=rkey
rkey=keystate(19)
` not held Down
if rkey=0 and lrkey=0 then RTRIG=0
` held Down
if rkey=1 and lrkey=0 then RTRIG=1
` just Been Pressed
if rkey=1 and lrkey=1 then RTRIG=1
` just been Lifted
if rkey=0 and lrkey=1 then RTRIG=0
Endfunction
Function OnF()
lfkey=fkey
fkey=keystate(33)
` not held Down
if fkey=0 and lfkey=0 then FTRIG=0
` held Down
if fkey=1 and lfkey=0 then FTRIG=1
` just Been Pressed
if fkey=1 and lfkey=1 then FTRIG=1
` just been Lifted
if fkey=0 and lfkey=1 then FTRIG=0
Endfunction
Function OnEnter()
lenkey=enkey
enkey=returnkey()
` not held Down
if enkey=0 and lenkey=0 then ENTRIG=0
` held Down
if enkey=1 and lenkey=0 then ENTRIG=1
` just Been Pressed
if enkey=1 and lenkey=1 then ENTRIG=0
` just been Lifted
if enkey=0 and lenkey=1 then ENTRIG=0
Endfunction
The bit in question is in the POSITIONDEBUG gosub under if SPTRIG=1. I wanted to save the current positions of the objects after moving them about. But when I try to save, I get runtime error 54 - "Array type invalid at [the line the array is to be saved]". I've saved arrays like this before, but they weren't defined as a custom type, and it worked fine.
Also, another quick question: how do you make a 3d object render without shading? The textures on my planes are dull, when I want them to be just as bright as the source image.
And how do you render transparent textures on a plane? My png file has transparent areas that worked fine when it was a sprite, but now that I'm transitioning to 3d and used SET OBJECT TRANSPARENCY, it has these weird outlines where the transparent areas are.
Thanks for the help.
EDIT: It turns out that I needed to SET OBJECT TRANSPARENCY 2,x to x=4. Don't know why it works, but it does.